mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
Add Radios, CircularProgressIndicator and LinearProgressIndicator to the demo app (#1442)
* Added Radios, CircularProgressIndicator and LinearProgressIndicator * Modified README * Fixed readme comment * Changed layout of indicators * Ran Flutter format command * Put two indicators to one row * Fixed comment * Ran flutter format Co-authored-by: Qun Cheng <quncheng@google.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
This sample Flutter app showcases Material 3 features in the Flutter Material library. These features include updated components, typography, color system and elevation support. The app supports light and dark themes, different color palettes, as well as the ability to switch between Material 2 and Material 3. For more information about Material 3, the guidance is now live at https://m3.material.io/.
|
This sample Flutter app showcases Material 3 features in the Flutter Material library. These features include updated components, typography, color system and elevation support. The app supports light and dark themes, different color palettes, as well as the ability to switch between Material 2 and Material 3. For more information about Material 3, the guidance is now live at https://m3.material.io/.
|
||||||
|
|
||||||
This app also includes new M3 components that haven't landed in the Flutter stable channel, such as IconButtons, Chips, TextFields, Switches and Checkboxes. The app will be migrated to the non-experimental directory in the samples repo once all the components land in the stable branch. For more information about the components in the stable channel, please check the "material_3_demo" in the non-experimental directory.
|
This app also includes new M3 components that haven't landed in the Flutter stable channel, such as IconButtons, Chips, TextFields, Switches, Checkboxes, Radio buttons and ProgressIndicators. The app will be migrated to the non-experimental directory in the samples repo once all the components land in the stable branch. For more information about the components in the stable channel, please check the "material_3_demo" in the non-experimental directory.
|
||||||
|
|
||||||
# Preview
|
# Preview
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ This app also includes new M3 components that haven't landed in the Flutter stab
|
|||||||
<img src="https://user-images.githubusercontent.com/36861262/166511137-85dea8df-0017-4649-b913-14d4b7a17c2f.png" width="25" /> This button will bring up a pop-up menu that allows the user to change the base color used for the light and dark themes. This uses a new color seed feature to generate entire color schemes from a single color.
|
<img src="https://user-images.githubusercontent.com/36861262/166511137-85dea8df-0017-4649-b913-14d4b7a17c2f.png" width="25" /> This button will bring up a pop-up menu that allows the user to change the base color used for the light and dark themes. This uses a new color seed feature to generate entire color schemes from a single color.
|
||||||
|
|
||||||
## Component Screen
|
## Component Screen
|
||||||
The default screen displays all the updated components in Material 3: AppBar, common Buttons, Floating Action Button(FAB), Chips, Card, Checkbox, Dialog, NavigationBar, NavigationRail, TextFields and Switch.
|
The default screen displays all the updated components in Material 3: AppBar, common Buttons, Floating Action Button(FAB), Chips, Card, Checkbox, Dialog, NavigationBar, NavigationRail, ProgressIndicators, Radio buttons, TextFields and Switch.
|
||||||
|
|
||||||
### Adaptive Layout
|
### Adaptive Layout
|
||||||
Based on the fact that NavigationRail is not recommended on a small screen, the app changes its layout based on the screen width. If it's played on iOS or Android devices which have a narrow screen, a Navigation Bar will show at the bottom and will be used to navigate. But if it's played as a desktop or a web app, a Navigation Rail will show on the left side and at the same time, a Navigation Bar will show as an example but will not have any functionality.
|
Based on the fact that NavigationRail is not recommended on a small screen, the app changes its layout based on the screen width. If it's played on iOS or Android devices which have a narrow screen, a Navigation Bar will show at the bottom and will be used to navigate. But if it's played as a desktop or a web app, a Navigation Rail will show on the left side and at the same time, a Navigation Bar will show as an example but will not have any functionality.
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ class ComponentScreen extends StatelessWidget {
|
|||||||
colDivider,
|
colDivider,
|
||||||
const Checkboxes(),
|
const Checkboxes(),
|
||||||
colDivider,
|
colDivider,
|
||||||
|
const Radios(),
|
||||||
|
colDivider,
|
||||||
|
const ProgressIndicators(),
|
||||||
|
colDivider,
|
||||||
showNavBottomBar
|
showNavBottomBar
|
||||||
? const NavigationBars(
|
? const NavigationBars(
|
||||||
selectedIndex: 0,
|
selectedIndex: 0,
|
||||||
@@ -629,6 +633,98 @@ class _CheckboxRowState extends State<CheckboxRow> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum Value { first, second }
|
||||||
|
|
||||||
|
class Radios extends StatefulWidget {
|
||||||
|
const Radios({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<Radios> createState() => _RadiosState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RadiosState extends State<Radios> {
|
||||||
|
Value? _value = Value.first;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
|
children: <Widget>[
|
||||||
|
Radio<Value>(
|
||||||
|
value: Value.first,
|
||||||
|
groupValue: _value,
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
_value = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
Radio<Value>(
|
||||||
|
value: Value.second,
|
||||||
|
groupValue: _value,
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
_value = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ProgressIndicators extends StatefulWidget {
|
||||||
|
const ProgressIndicators({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ProgressIndicators> createState() => _ProgressIndicatorsState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ProgressIndicatorsState extends State<ProgressIndicators> {
|
||||||
|
bool playProgressIndicator = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final double? progressValue = playProgressIndicator ? null : 0.7;
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
children: <Widget>[
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
IconButton(
|
||||||
|
isSelected: playProgressIndicator,
|
||||||
|
selectedIcon: const Icon(Icons.pause),
|
||||||
|
icon: const Icon(Icons.play_arrow),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
playProgressIndicator = !playProgressIndicator;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Row(
|
||||||
|
children: <Widget>[
|
||||||
|
CircularProgressIndicator(
|
||||||
|
value: progressValue,
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
width: 10,
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: LinearProgressIndicator(
|
||||||
|
value: progressValue,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const List<NavigationDestination> appBarDestinations = [
|
const List<NavigationDestination> appBarDestinations = [
|
||||||
NavigationDestination(
|
NavigationDestination(
|
||||||
tooltip: 'Updated component list',
|
tooltip: 'Updated component list',
|
||||||
|
|||||||
@@ -63,6 +63,16 @@ void main() {
|
|||||||
// Checkboxes
|
// Checkboxes
|
||||||
Finder checkboxExample = find.byType(Checkbox);
|
Finder checkboxExample = find.byType(Checkbox);
|
||||||
expect(checkboxExample, findsNWidgets(8));
|
expect(checkboxExample, findsNWidgets(8));
|
||||||
|
|
||||||
|
// Radios
|
||||||
|
Finder radioExample = find.byType(Radio<Value>);
|
||||||
|
expect(radioExample, findsNWidgets(2));
|
||||||
|
|
||||||
|
// ProgressIndicator
|
||||||
|
Finder circularProgressIndicator = find.byType(CircularProgressIndicator);
|
||||||
|
expect(circularProgressIndicator, findsOneWidget);
|
||||||
|
Finder linearProgressIndicator = find.byType(LinearProgressIndicator);
|
||||||
|
expect(linearProgressIndicator, findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets(
|
testWidgets(
|
||||||
|
|||||||
Reference in New Issue
Block a user