Auto-format Framework (#160545)

This auto-formats all *.dart files in the repository outside of the
`engine` subdirectory and enforces that these files stay formatted with
a presubmit check.

**Reviewers:** Please carefully review all the commits except for the
one titled "formatted". The "formatted" commit was auto-generated by
running `dev/tools/format.sh -a -f`. The other commits were hand-crafted
to prepare the repo for the formatting change. I recommend reviewing the
commits one-by-one via the "Commits" tab and avoiding Github's "Files
changed" tab as it will likely slow down your browser because of the
size of this PR.

---------

Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
Michael Goderbauer
2024-12-19 12:06:21 -08:00
committed by GitHub
parent 8e0993eda8
commit 5491c8c146
4411 changed files with 455108 additions and 415991 deletions

View File

@@ -19,20 +19,17 @@ class _PlaceholderDigit extends StatelessWidget {
@override
Widget build(BuildContext context) {
final TextStyle textStyle = Theme.of(context).textTheme.displayLarge!.copyWith(
fontWeight: FontWeight.w500,
);
final TextStyle textStyle = Theme.of(
context,
).textTheme.displayLarge!.copyWith(fontWeight: FontWeight.w500);
final Iterable<Widget> placeholderDigits = <int>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map<Widget>(
(int n) {
return Text('$n', style: textStyle);
},
);
final Iterable<Widget> placeholderDigits = <int>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map<Widget>((
int n,
) {
return Text('$n', style: textStyle);
});
return Opacity(
opacity: 0,
child: Stack(children: placeholderDigits.toList()),
);
return Opacity(opacity: 0, child: Stack(children: placeholderDigits.toList()));
}
}
@@ -41,7 +38,7 @@ class _PlaceholderDigit extends StatelessWidget {
// When the value changes the old value slides upwards and out of sight
// at the same as the new value slides into view.
class AnimatedDigit extends StatefulWidget {
const AnimatedDigit({ super.key, required this.value });
const AnimatedDigit({super.key, required this.value});
final int value;
@@ -55,16 +52,14 @@ class _AnimatedDigitState extends State<AnimatedDigit> with SingleTickerProvider
late final AnimationController controller;
late int incomingValue;
late int outgoingValue;
List<int> pendingValues = <int>[]; // widget.value updates that occurred while the animation is underway
List<int> pendingValues =
<int>[]; // widget.value updates that occurred while the animation is underway
Duration duration = defaultDuration;
@override
void initState() {
super.initState();
controller = AnimationController(
duration: duration,
vsync: this,
);
controller = AnimationController(duration: duration, vsync: this);
controller.addStatusListener(handleAnimationCompleted);
incomingValue = widget.value;
outgoingValue = widget.value;
@@ -133,32 +128,22 @@ class _AnimatedDigitState extends State<AnimatedDigit> with SingleTickerProvider
children: <Widget>[
const _PlaceholderDigit(),
SlideTransition(
position: controller
.drive(
Tween<Offset>(
begin: Offset.zero,
end: const Offset(0, -1), // Out of view above the top.
),
position: controller.drive(
Tween<Offset>(
begin: Offset.zero,
end: const Offset(0, -1), // Out of view above the top.
),
child: Text(
key: ValueKey<int>(outgoingValue),
'$outgoingValue',
style: textStyle,
),
child: Text(key: ValueKey<int>(outgoingValue), '$outgoingValue', style: textStyle),
),
SlideTransition(
position: controller
.drive(
Tween<Offset>(
begin: const Offset(0, 1), // Out of view below the bottom.
end: Offset.zero,
),
position: controller.drive(
Tween<Offset>(
begin: const Offset(0, 1), // Out of view below the bottom.
end: Offset.zero,
),
child: Text(
key: ValueKey<int>(incomingValue),
'$incomingValue',
style: textStyle,
),
child: Text(key: ValueKey<int>(incomingValue), '$incomingValue', style: textStyle),
),
],
),
@@ -167,19 +152,16 @@ class _AnimatedDigitState extends State<AnimatedDigit> with SingleTickerProvider
}
class AnimatedDigitApp extends StatelessWidget {
const AnimatedDigitApp({ super.key });
const AnimatedDigitApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'AnimatedDigit',
home: AnimatedDigitHome(),
);
return const MaterialApp(title: 'AnimatedDigit', home: AnimatedDigitHome());
}
}
class AnimatedDigitHome extends StatefulWidget {
const AnimatedDigitHome({ super.key });
const AnimatedDigitHome({super.key});
@override
State<AnimatedDigitHome> createState() => _AnimatedDigitHomeState();
@@ -191,12 +173,12 @@ class _AnimatedDigitHomeState extends State<AnimatedDigitHome> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: AnimatedDigit(value: value % 10),
),
body: Center(child: AnimatedDigit(value: value % 10)),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() { value += 1; });
setState(() {
value += 1;
});
},
tooltip: 'Increment Digit',
child: const Icon(Icons.add),

View File

@@ -13,9 +13,7 @@ class Curve2DExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Curve2DExample(),
);
return const MaterialApp(home: Curve2DExample());
}
}
@@ -84,10 +82,7 @@ class _FollowCurve2DState extends State<FollowCurve2D> with TickerProviderStateM
Widget build(BuildContext context) {
// Scale the path values to match the -1.0 to 1.0 domain of the Alignment widget.
final Offset position = widget.path.transform(animation.value) * 2.0 - const Offset(1.0, 1.0);
return Align(
alignment: Alignment(position.dx, position.dy),
child: widget.child,
);
return Align(alignment: Alignment(position.dx, position.dy), child: widget.child);
}
}

View File

@@ -26,9 +26,7 @@ class CupertinoIndicatorExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('CupertinoActivityIndicator Sample'),
),
navigationBar: CupertinoNavigationBar(middle: Text('CupertinoActivityIndicator Sample')),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
@@ -61,10 +59,7 @@ class CupertinoIndicatorExample extends StatelessWidget {
// animation.
CupertinoActivityIndicator(radius: 20.0, animating: false),
SizedBox(height: 10),
Text(
'radius: 20.0\nanimating: false',
textAlign: TextAlign.center,
),
Text('radius: 20.0\nanimating: false', textAlign: TextAlign.center),
],
),
],

View File

@@ -28,30 +28,19 @@ class CupertinoTabBarExample extends StatelessWidget {
return CupertinoTabScaffold(
tabBar: CupertinoTabBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.star_fill),
label: 'Favorites',
),
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.clock_solid),
label: 'Recents',
),
BottomNavigationBarItem(icon: Icon(CupertinoIcons.star_fill), label: 'Favorites'),
BottomNavigationBarItem(icon: Icon(CupertinoIcons.clock_solid), label: 'Recents'),
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.person_alt_circle_fill),
label: 'Contacts',
),
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.circle_grid_3x3_fill),
label: 'Keypad',
),
BottomNavigationBarItem(icon: Icon(CupertinoIcons.circle_grid_3x3_fill), label: 'Keypad'),
],
),
tabBuilder: (BuildContext context, int index) {
return CupertinoTabView(
builder: (BuildContext context) {
return Center(
child: Text('Content of tab $index'),
);
return Center(child: Text('Content of tab $index'));
},
);
},

View File

@@ -26,32 +26,18 @@ class CupertinoButtonExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoButton Sample'),
),
navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoButton Sample')),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const CupertinoButton(
onPressed: null,
child: Text('Disabled'),
),
const CupertinoButton(onPressed: null, child: Text('Disabled')),
const SizedBox(height: 30),
const CupertinoButton.filled(
onPressed: null,
child: Text('Disabled'),
),
const CupertinoButton.filled(onPressed: null, child: Text('Disabled')),
const SizedBox(height: 30),
CupertinoButton(
onPressed: () {},
child: const Text('Enabled'),
),
CupertinoButton(onPressed: () {}, child: const Text('Enabled')),
const SizedBox(height: 30),
CupertinoButton.filled(
onPressed: () {},
child: const Text('Enabled'),
),
CupertinoButton.filled(onPressed: () {}, child: const Text('Enabled')),
],
),
),

View File

@@ -16,12 +16,8 @@ class CupertinoCheckboxApp extends StatelessWidget {
return const CupertinoApp(
theme: CupertinoThemeData(brightness: Brightness.light),
home: CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('CupertinoCheckbox Example'),
),
child: SafeArea(
child: CupertinoCheckboxExample(),
),
navigationBar: CupertinoNavigationBar(middle: Text('CupertinoCheckbox Example')),
child: SafeArea(child: CupertinoCheckboxExample()),
),
);
}

View File

@@ -26,9 +26,7 @@ class ContextMenuExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoContextMenu Sample'),
),
navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoContextMenu Sample')),
child: Center(
child: SizedBox(
width: 100,

View File

@@ -41,10 +41,7 @@ class ContextMenuExample extends StatelessWidget {
return _tween.animate(
CurvedAnimation(
parent: animation,
curve: Interval(
0.0,
CupertinoContextMenu.animationOpensAt,
),
curve: Interval(0.0, CupertinoContextMenu.animationOpensAt),
),
);
}
@@ -52,9 +49,7 @@ class ContextMenuExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoContextMenu Sample'),
),
navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoContextMenu Sample')),
child: Center(
child: SizedBox(
width: 100,
@@ -93,11 +88,15 @@ class ContextMenuExample extends StatelessWidget {
),
],
builder: (BuildContext context, Animation<double> animation) {
final Animation<Decoration> boxDecorationAnimation = _boxDecorationAnimation(animation);
final Animation<Decoration> boxDecorationAnimation = _boxDecorationAnimation(
animation,
);
return Container(
decoration:
animation.value < CupertinoContextMenu.animationOpensAt ? boxDecorationAnimation.value : null,
animation.value < CupertinoContextMenu.animationOpensAt
? boxDecorationAnimation.value
: null,
child: Container(
decoration: BoxDecoration(
color: CupertinoColors.systemYellow,

View File

@@ -37,36 +37,27 @@ class _DatePickerExampleState extends State<DatePickerExample> {
void _showDialog(Widget child) {
showCupertinoModalPopup<void>(
context: context,
builder: (BuildContext context) => Container(
height: 216,
padding: const EdgeInsets.only(top: 6.0),
// The Bottom margin is provided to align the popup above the system
// navigation bar.
margin: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
// Provide a background color for the popup.
color: CupertinoColors.systemBackground.resolveFrom(context),
// Use a SafeArea widget to avoid system overlaps.
child: SafeArea(
top: false,
child: child,
),
),
builder:
(BuildContext context) => Container(
height: 216,
padding: const EdgeInsets.only(top: 6.0),
// The Bottom margin is provided to align the popup above the system
// navigation bar.
margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
// Provide a background color for the popup.
color: CupertinoColors.systemBackground.resolveFrom(context),
// Use a SafeArea widget to avoid system overlaps.
child: SafeArea(top: false, child: child),
),
);
}
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoDatePicker Sample'),
),
navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoDatePicker Sample')),
child: DefaultTextStyle(
style: TextStyle(
color: CupertinoColors.label.resolveFrom(context),
fontSize: 22.0,
),
style: TextStyle(color: CupertinoColors.label.resolveFrom(context), fontSize: 22.0),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
@@ -76,27 +67,26 @@ class _DatePickerExampleState extends State<DatePickerExample> {
const Text('Date'),
CupertinoButton(
// Display a CupertinoDatePicker in date picker mode.
onPressed: () => _showDialog(
CupertinoDatePicker(
initialDateTime: date,
mode: CupertinoDatePickerMode.date,
use24hFormat: true,
// This shows day of week alongside day of month
showDayOfWeek: true,
// This is called when the user changes the date.
onDateTimeChanged: (DateTime newDate) {
setState(() => date = newDate);
},
),
),
onPressed:
() => _showDialog(
CupertinoDatePicker(
initialDateTime: date,
mode: CupertinoDatePickerMode.date,
use24hFormat: true,
// This shows day of week alongside day of month
showDayOfWeek: true,
// This is called when the user changes the date.
onDateTimeChanged: (DateTime newDate) {
setState(() => date = newDate);
},
),
),
// In this example, the date is formatted manually. You can
// use the intl package to format the value based on the
// user's locale settings.
child: Text(
'${date.month}-${date.day}-${date.year}',
style: const TextStyle(
fontSize: 22.0,
),
style: const TextStyle(fontSize: 22.0),
),
),
],
@@ -106,25 +96,24 @@ class _DatePickerExampleState extends State<DatePickerExample> {
const Text('Time'),
CupertinoButton(
// Display a CupertinoDatePicker in time picker mode.
onPressed: () => _showDialog(
CupertinoDatePicker(
initialDateTime: time,
mode: CupertinoDatePickerMode.time,
use24hFormat: true,
// This is called when the user changes the time.
onDateTimeChanged: (DateTime newTime) {
setState(() => time = newTime);
},
),
),
onPressed:
() => _showDialog(
CupertinoDatePicker(
initialDateTime: time,
mode: CupertinoDatePickerMode.time,
use24hFormat: true,
// This is called when the user changes the time.
onDateTimeChanged: (DateTime newTime) {
setState(() => time = newTime);
},
),
),
// In this example, the time value is formatted manually.
// You can use the intl package to format the value based on
// the user's locale settings.
child: Text(
'${time.hour}:${time.minute}',
style: const TextStyle(
fontSize: 22.0,
),
style: const TextStyle(fontSize: 22.0),
),
),
],
@@ -134,24 +123,23 @@ class _DatePickerExampleState extends State<DatePickerExample> {
const Text('DateTime'),
CupertinoButton(
// Display a CupertinoDatePicker in dateTime picker mode.
onPressed: () => _showDialog(
CupertinoDatePicker(
initialDateTime: dateTime,
use24hFormat: true,
// This is called when the user changes the dateTime.
onDateTimeChanged: (DateTime newDateTime) {
setState(() => dateTime = newDateTime);
},
),
),
onPressed:
() => _showDialog(
CupertinoDatePicker(
initialDateTime: dateTime,
use24hFormat: true,
// This is called when the user changes the dateTime.
onDateTimeChanged: (DateTime newDateTime) {
setState(() => dateTime = newDateTime);
},
),
),
// In this example, the time value is formatted manually. You
// can use the intl package to format the value based on the
// user's locale settings.
child: Text(
'${dateTime.month}-${dateTime.day}-${dateTime.year} ${dateTime.hour}:${dateTime.minute}',
style: const TextStyle(
fontSize: 22.0,
),
style: const TextStyle(fontSize: 22.0),
),
),
],
@@ -175,22 +163,13 @@ class _DatePickerItem extends StatelessWidget {
return DecoratedBox(
decoration: const BoxDecoration(
border: Border(
top: BorderSide(
color: CupertinoColors.inactiveGray,
width: 0.0,
),
bottom: BorderSide(
color: CupertinoColors.inactiveGray,
width: 0.0,
),
top: BorderSide(color: CupertinoColors.inactiveGray, width: 0.0),
bottom: BorderSide(color: CupertinoColors.inactiveGray, width: 0.0),
),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: children,
),
child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: children),
),
);
}

View File

@@ -35,36 +35,27 @@ class _TimerPickerExampleState extends State<TimerPickerExample> {
void _showDialog(Widget child) {
showCupertinoModalPopup<void>(
context: context,
builder: (BuildContext context) => Container(
height: 216,
padding: const EdgeInsets.only(top: 6.0),
// The bottom margin is provided to align the popup above the system
// navigation bar.
margin: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
// Provide a background color for the popup.
color: CupertinoColors.systemBackground.resolveFrom(context),
// Use a SafeArea widget to avoid system overlaps.
child: SafeArea(
top: false,
child: child,
),
),
builder:
(BuildContext context) => Container(
height: 216,
padding: const EdgeInsets.only(top: 6.0),
// The bottom margin is provided to align the popup above the system
// navigation bar.
margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
// Provide a background color for the popup.
color: CupertinoColors.systemBackground.resolveFrom(context),
// Use a SafeArea widget to avoid system overlaps.
child: SafeArea(top: false, child: child),
),
);
}
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoTimerPicker Sample'),
),
navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoTimerPicker Sample')),
child: DefaultTextStyle(
style: TextStyle(
color: CupertinoColors.label.resolveFrom(context),
fontSize: 22.0,
),
style: TextStyle(color: CupertinoColors.label.resolveFrom(context), fontSize: 22.0),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
@@ -74,26 +65,22 @@ class _TimerPickerExampleState extends State<TimerPickerExample> {
const Text('Timer'),
CupertinoButton(
// Display a CupertinoTimerPicker with hour/minute mode.
onPressed: () => _showDialog(
CupertinoTimerPicker(
mode: CupertinoTimerPickerMode.hm,
initialTimerDuration: duration,
// This is called when the user changes the timer's
// duration.
onTimerDurationChanged: (Duration newDuration) {
setState(() => duration = newDuration);
},
),
),
onPressed:
() => _showDialog(
CupertinoTimerPicker(
mode: CupertinoTimerPickerMode.hm,
initialTimerDuration: duration,
// This is called when the user changes the timer's
// duration.
onTimerDurationChanged: (Duration newDuration) {
setState(() => duration = newDuration);
},
),
),
// In this example, the timer's value is formatted manually.
// You can use the intl package to format the value based on
// the user's locale settings.
child: Text(
'$duration',
style: const TextStyle(
fontSize: 22.0,
),
),
child: Text('$duration', style: const TextStyle(fontSize: 22.0)),
),
],
),
@@ -116,22 +103,13 @@ class _TimerPickerItem extends StatelessWidget {
return DecoratedBox(
decoration: const BoxDecoration(
border: Border(
top: BorderSide(
color: CupertinoColors.inactiveGray,
width: 0.0,
),
bottom: BorderSide(
color: CupertinoColors.inactiveGray,
width: 0.0,
),
top: BorderSide(color: CupertinoColors.inactiveGray, width: 0.0),
bottom: BorderSide(color: CupertinoColors.inactiveGray, width: 0.0),
),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: children,
),
child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: children),
),
);
}

View File

@@ -27,46 +27,45 @@ class ActionSheetExample extends StatelessWidget {
void _showActionSheet(BuildContext context) {
showCupertinoModalPopup<void>(
context: context,
builder: (BuildContext context) => CupertinoActionSheet(
title: const Text('Title'),
message: const Text('Message'),
actions: <CupertinoActionSheetAction>[
CupertinoActionSheetAction(
/// This parameter indicates the action would be a default
/// default behavior, turns the action's text to bold text.
isDefaultAction: true,
onPressed: () {
Navigator.pop(context);
},
child: const Text('Default Action'),
builder:
(BuildContext context) => CupertinoActionSheet(
title: const Text('Title'),
message: const Text('Message'),
actions: <CupertinoActionSheetAction>[
CupertinoActionSheetAction(
/// This parameter indicates the action would be a default
/// default behavior, turns the action's text to bold text.
isDefaultAction: true,
onPressed: () {
Navigator.pop(context);
},
child: const Text('Default Action'),
),
CupertinoActionSheetAction(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Action'),
),
CupertinoActionSheetAction(
/// This parameter indicates the action would perform
/// a destructive action such as delete or exit and turns
/// the action's text color to red.
isDestructiveAction: true,
onPressed: () {
Navigator.pop(context);
},
child: const Text('Destructive Action'),
),
],
),
CupertinoActionSheetAction(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Action'),
),
CupertinoActionSheetAction(
/// This parameter indicates the action would perform
/// a destructive action such as delete or exit and turns
/// the action's text color to red.
isDestructiveAction: true,
onPressed: () {
Navigator.pop(context);
},
child: const Text('Destructive Action'),
),
],
),
);
}
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoActionSheet Sample'),
),
navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoActionSheet Sample')),
child: Center(
child: CupertinoButton(
onPressed: () => _showActionSheet(context),

View File

@@ -26,40 +26,39 @@ class AlertDialogExample extends StatelessWidget {
void _showAlertDialog(BuildContext context) {
showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) => CupertinoAlertDialog(
title: const Text('Alert'),
content: const Text('Proceed with destructive action?'),
actions: <CupertinoDialogAction>[
CupertinoDialogAction(
/// This parameter indicates this action is the default,
/// and turns the action's text to bold text.
isDefaultAction: true,
onPressed: () {
Navigator.pop(context);
},
child: const Text('No'),
builder:
(BuildContext context) => CupertinoAlertDialog(
title: const Text('Alert'),
content: const Text('Proceed with destructive action?'),
actions: <CupertinoDialogAction>[
CupertinoDialogAction(
/// This parameter indicates this action is the default,
/// and turns the action's text to bold text.
isDefaultAction: true,
onPressed: () {
Navigator.pop(context);
},
child: const Text('No'),
),
CupertinoDialogAction(
/// This parameter indicates the action would perform
/// a destructive action such as deletion, and turns
/// the action's text color to red.
isDestructiveAction: true,
onPressed: () {
Navigator.pop(context);
},
child: const Text('Yes'),
),
],
),
CupertinoDialogAction(
/// This parameter indicates the action would perform
/// a destructive action such as deletion, and turns
/// the action's text color to red.
isDestructiveAction: true,
onPressed: () {
Navigator.pop(context);
},
child: const Text('Yes'),
),
],
),
);
}
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoAlertDialog Sample'),
),
navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoAlertDialog Sample')),
child: Center(
child: CupertinoButton(
onPressed: () => _showAlertDialog(context),

View File

@@ -13,9 +13,7 @@ class PopupSurfaceApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const CupertinoApp(
home: PopupSurfaceExample(),
);
return const CupertinoApp(home: PopupSurfaceExample());
}
}
@@ -72,12 +70,13 @@ class _PopupSurfaceExampleState extends State<PopupSurfaceExample> {
Expanded(
child: Container(
alignment: Alignment.center,
decoration: _shouldPaintSurface
? null
: BoxDecoration(
color: CupertinoTheme.of(context).scaffoldBackgroundColor,
borderRadius: BorderRadius.circular(8.0),
),
decoration:
_shouldPaintSurface
? null
: BoxDecoration(
color: CupertinoTheme.of(context).scaffoldBackgroundColor,
borderRadius: BorderRadius.circular(8.0),
),
child: const Text('This is a popup surface.'),
),
),
@@ -85,14 +84,12 @@ class _PopupSurfaceExampleState extends State<PopupSurfaceExample> {
SizedBox(
width: double.infinity,
child: CupertinoButton(
color: _shouldPaintSurface
? null
: CupertinoTheme.of(context).scaffoldBackgroundColor,
color:
_shouldPaintSurface
? null
: CupertinoTheme.of(context).scaffoldBackgroundColor,
onPressed: () => Navigator.pop(context),
child: const Text(
'Close',
style: TextStyle(color: CupertinoColors.systemBlue),
),
child: const Text('Close', style: TextStyle(color: CupertinoColors.systemBlue)),
),
),
],

View File

@@ -33,9 +33,7 @@ class _CupertinoFormRowExampleState extends State<CupertinoFormRowExample> {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoFormSection Sample'),
),
navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoFormSection Sample')),
// Add safe area widget to place the CupertinoFormSection below the navigation bar.
child: SafeArea(
child: CupertinoFormSection(
@@ -65,7 +63,11 @@ class _CupertinoFormRowExampleState extends State<CupertinoFormRowExample> {
error: Text('Home network unavailable'),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[Text('Not connected'), SizedBox(width: 5), Icon(CupertinoIcons.forward)],
children: <Widget>[
Text('Not connected'),
SizedBox(width: 5),
Icon(CupertinoIcons.forward),
],
),
),
const CupertinoFormRow(
@@ -78,19 +80,12 @@ class _CupertinoFormRowExampleState extends State<CupertinoFormRowExample> {
padding: EdgeInsets.symmetric(vertical: 4.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('Headphone'),
Text('Connected'),
],
children: <Widget>[Text('Headphone'), Text('Connected')],
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Text('On'),
SizedBox(width: 5),
Icon(CupertinoIcons.forward),
],
children: <Widget>[Text('On'), SizedBox(width: 5), Icon(CupertinoIcons.forward)],
),
),
const CupertinoFormRow(
@@ -109,12 +104,7 @@ class _CupertinoFormRowExampleState extends State<CupertinoFormRowExample> {
}
class PrefixWidget extends StatelessWidget {
const PrefixWidget({
super.key,
required this.icon,
required this.title,
required this.color,
});
const PrefixWidget({super.key, required this.icon, required this.title, required this.color});
final IconData icon;
final String title;
@@ -126,14 +116,11 @@ class PrefixWidget extends StatelessWidget {
children: <Widget>[
Container(
padding: const EdgeInsets.all(4.0),
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(4.0),
),
decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(4.0)),
child: Icon(icon, color: CupertinoColors.white),
),
const SizedBox(width: 15),
Text(title)
Text(title),
],
);
}

View File

@@ -13,9 +13,7 @@ class CupertinoListSectionBaseApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const CupertinoApp(
home: ListSectionBaseExample(),
);
return const CupertinoApp(home: ListSectionBaseExample());
}
}
@@ -36,13 +34,14 @@ class ListSectionBaseExample extends StatelessWidget {
color: CupertinoColors.activeGreen,
),
trailing: const CupertinoListTileChevron(),
onTap: () => Navigator.of(context).push(
CupertinoPageRoute<void>(
builder: (BuildContext context) {
return const _SecondPage(text: 'Open pull request');
},
),
),
onTap:
() => Navigator.of(context).push(
CupertinoPageRoute<void>(
builder: (BuildContext context) {
return const _SecondPage(text: 'Open pull request');
},
),
),
),
CupertinoListTile(
title: const Text('Push to master'),
@@ -62,13 +61,14 @@ class ListSectionBaseExample extends StatelessWidget {
),
additionalInfo: const Text('12 days ago'),
trailing: const CupertinoListTileChevron(),
onTap: () => Navigator.of(context).push(
CupertinoPageRoute<void>(
builder: (BuildContext context) {
return const _SecondPage(text: 'Last commit');
},
),
),
onTap:
() => Navigator.of(context).push(
CupertinoPageRoute<void>(
builder: (BuildContext context) {
return const _SecondPage(text: 'Last commit');
},
),
),
),
],
),
@@ -83,10 +83,6 @@ class _SecondPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
child: Center(
child: Text(text),
),
);
return CupertinoPageScaffold(child: Center(child: Text(text)));
}
}

View File

@@ -13,9 +13,7 @@ class CupertinoListSectionInsetApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const CupertinoApp(
home: ListSectionInsetExample(),
);
return const CupertinoApp(home: ListSectionInsetExample());
}
}
@@ -36,13 +34,14 @@ class ListSectionInsetExample extends StatelessWidget {
color: CupertinoColors.activeGreen,
),
trailing: const CupertinoListTileChevron(),
onTap: () => Navigator.of(context).push(
CupertinoPageRoute<void>(
builder: (BuildContext context) {
return const _SecondPage(text: 'Open pull request');
},
),
),
onTap:
() => Navigator.of(context).push(
CupertinoPageRoute<void>(
builder: (BuildContext context) {
return const _SecondPage(text: 'Open pull request');
},
),
),
),
CupertinoListTile.notched(
title: const Text('Push to master'),
@@ -62,13 +61,14 @@ class ListSectionInsetExample extends StatelessWidget {
),
additionalInfo: const Text('12 days ago'),
trailing: const CupertinoListTileChevron(),
onTap: () => Navigator.of(context).push(
CupertinoPageRoute<void>(
builder: (BuildContext context) {
return const _SecondPage(text: 'Last commit');
},
),
),
onTap:
() => Navigator.of(context).push(
CupertinoPageRoute<void>(
builder: (BuildContext context) {
return const _SecondPage(text: 'Last commit');
},
),
),
),
],
),
@@ -83,10 +83,6 @@ class _SecondPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
child: Center(
child: Text(text),
),
);
return CupertinoPageScaffold(child: Center(child: Text(text)));
}
}

View File

@@ -14,9 +14,7 @@ class CupertinoListTileApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const CupertinoApp(
home: CupertinoListTileExample(),
);
return const CupertinoApp(home: CupertinoListTileExample());
}
}
@@ -26,16 +24,11 @@ class CupertinoListTileExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoListTile Sample'),
),
navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoListTile Sample')),
child: ListView(
children: const <Widget>[
CupertinoListTile(title: Text('One-line CupertinoListTile')),
CupertinoListTile(
leading: FlutterLogo(),
title: Text('One-line with leading widget'),
),
CupertinoListTile(leading: FlutterLogo(), title: Text('One-line with leading widget')),
CupertinoListTile(
title: Text('One-line with trailing widget'),
trailing: Icon(Icons.more_vert),

View File

@@ -49,7 +49,6 @@ class _NavBarExampleState extends State<NavBarExample> {
}
}
class _NavigationBarSearchField extends StatelessWidget implements PreferredSizeWidget {
const _NavigationBarSearchField();
@@ -60,10 +59,7 @@ class _NavigationBarSearchField extends StatelessWidget implements PreferredSize
Widget build(BuildContext context) {
return const Padding(
padding: EdgeInsets.symmetric(horizontal: padding, vertical: padding),
child: SizedBox(
height: searchFieldHeight,
child: CupertinoSearchTextField()
),
child: SizedBox(height: searchFieldHeight, child: CupertinoSearchTextField()),
);
}

View File

@@ -33,19 +33,14 @@ class _NavBarExampleState extends State<NavBarExample> {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar.large(
largeTitle: Text('Large Sample'),
),
navigationBar: const CupertinoNavigationBar.large(largeTitle: Text('Large Sample')),
child: SafeArea(
child: Center(
child: Column(
children: <Widget>[
const Spacer(),
const Text('You have pushed the button this many times:'),
Text(
'$_count',
style: CupertinoTheme.of(context).textTheme.navLargeTitleTextStyle,
),
Text('$_count', style: CupertinoTheme.of(context).textTheme.navLargeTitleTextStyle),
const Spacer(),
Padding(
padding: const EdgeInsets.all(15.0),

View File

@@ -80,7 +80,8 @@ class NextPage extends StatelessWidget {
backgroundColor: CupertinoColors.systemYellow,
border: Border(
bottom: BorderSide(
color: brightness == Brightness.light ? CupertinoColors.black : CupertinoColors.white,
color:
brightness == Brightness.light ? CupertinoColors.black : CupertinoColors.white,
),
),
// The middle widget is visible in both collapsed and expanded states.

View File

@@ -59,9 +59,7 @@ class SliverNavBarExample extends StatelessWidget {
context,
CupertinoPageRoute<Widget>(
builder: (BuildContext context) {
return const NextPage(
bottomMode: NavigationBarBottomMode.always,
);
return const NextPage(bottomMode: NavigationBarBottomMode.always);
},
),
);
@@ -93,9 +91,8 @@ class NextPage extends StatelessWidget {
backgroundColor: CupertinoColors.systemYellow,
border: Border(
bottom: BorderSide(
color: brightness == Brightness.light
? CupertinoColors.black
: CupertinoColors.white,
color:
brightness == Brightness.light ? CupertinoColors.black : CupertinoColors.white,
),
),
middle: const Text('Contacts Group'),
@@ -107,8 +104,7 @@ class NextPage extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text('Drag me up', textAlign: TextAlign.center),
Text('Tap on the leading button to navigate back',
textAlign: TextAlign.center),
Text('Tap on the leading button to navigate back', textAlign: TextAlign.center),
],
),
),

View File

@@ -35,16 +35,12 @@ class _PageScaffoldExampleState extends State<PageScaffoldExample> {
return CupertinoPageScaffold(
// Uncomment to change the background color
// backgroundColor: CupertinoColors.systemPink,
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoPageScaffold Sample'),
),
navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoPageScaffold Sample')),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Center(
child: Text('You have pressed the button $_count times.'),
),
Center(child: Text('You have pressed the button $_count times.')),
const SizedBox(height: 20.0),
Center(
child: CupertinoButton.filled(

View File

@@ -44,35 +44,26 @@ class _CupertinoPickerExampleState extends State<CupertinoPickerExample> {
void _showDialog(Widget child) {
showCupertinoModalPopup<void>(
context: context,
builder: (BuildContext context) => Container(
height: 216,
padding: const EdgeInsets.only(top: 6.0),
// The Bottom margin is provided to align the popup above the system navigation bar.
margin: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
// Provide a background color for the popup.
color: CupertinoColors.systemBackground.resolveFrom(context),
// Use a SafeArea widget to avoid system overlaps.
child: SafeArea(
top: false,
child: child,
),
),
builder:
(BuildContext context) => Container(
height: 216,
padding: const EdgeInsets.only(top: 6.0),
// The Bottom margin is provided to align the popup above the system navigation bar.
margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
// Provide a background color for the popup.
color: CupertinoColors.systemBackground.resolveFrom(context),
// Use a SafeArea widget to avoid system overlaps.
child: SafeArea(top: false, child: child),
),
);
}
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoPicker Sample'),
),
navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoPicker Sample')),
child: DefaultTextStyle(
style: TextStyle(
color: CupertinoColors.label.resolveFrom(context),
fontSize: 22.0,
),
style: TextStyle(color: CupertinoColors.label.resolveFrom(context), fontSize: 22.0),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
@@ -81,34 +72,28 @@ class _CupertinoPickerExampleState extends State<CupertinoPickerExample> {
CupertinoButton(
padding: EdgeInsets.zero,
// Display a CupertinoPicker with list of fruits.
onPressed: () => _showDialog(
CupertinoPicker(
magnification: 1.22,
squeeze: 1.2,
useMagnifier: true,
itemExtent: _kItemExtent,
// This sets the initial item.
scrollController: FixedExtentScrollController(
initialItem: _selectedFruit,
onPressed:
() => _showDialog(
CupertinoPicker(
magnification: 1.22,
squeeze: 1.2,
useMagnifier: true,
itemExtent: _kItemExtent,
// This sets the initial item.
scrollController: FixedExtentScrollController(initialItem: _selectedFruit),
// This is called when selected item is changed.
onSelectedItemChanged: (int selectedItem) {
setState(() {
_selectedFruit = selectedItem;
});
},
children: List<Widget>.generate(_fruitNames.length, (int index) {
return Center(child: Text(_fruitNames[index]));
}),
),
),
// This is called when selected item is changed.
onSelectedItemChanged: (int selectedItem) {
setState(() {
_selectedFruit = selectedItem;
});
},
children: List<Widget>.generate(_fruitNames.length, (int index) {
return Center(child: Text(_fruitNames[index]));
}),
),
),
// This displays the selected fruit name.
child: Text(
_fruitNames[_selectedFruit],
style: const TextStyle(
fontSize: 22.0,
),
),
child: Text(_fruitNames[_selectedFruit], style: const TextStyle(fontSize: 22.0)),
),
],
),

View File

@@ -16,12 +16,8 @@ class CupertinoRadioApp extends StatelessWidget {
return const CupertinoApp(
theme: CupertinoThemeData(brightness: Brightness.light),
home: CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('CupertinoRadio Example'),
),
child: SafeArea(
child: CupertinoRadioExample(),
),
navigationBar: CupertinoNavigationBar(middle: Text('CupertinoRadio Example')),
child: SafeArea(child: CupertinoRadioExample()),
),
);
}

View File

@@ -15,12 +15,8 @@ class CupertinoRadioApp extends StatelessWidget {
Widget build(BuildContext context) {
return const CupertinoApp(
home: CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('CupertinoRadio Toggleable Example'),
),
child: SafeArea(
child: CupertinoRadioExample(),
),
navigationBar: CupertinoNavigationBar(middle: Text('CupertinoRadio Toggleable Example')),
child: SafeArea(child: CupertinoRadioExample()),
),
);
}

View File

@@ -46,23 +46,14 @@ class _RefreshControlExampleState extends State<RefreshControlExample> {
middle: Text('CupertinoSliverRefreshControl Sample'),
),
child: CustomScrollView(
physics: const BouncingScrollPhysics(
parent: AlwaysScrollableScrollPhysics(),
),
physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
slivers: <Widget>[
const CupertinoSliverNavigationBar(
largeTitle: Text('Scroll down'),
),
const CupertinoSliverNavigationBar(largeTitle: Text('Scroll down')),
CupertinoSliverRefreshControl(
onRefresh: () async {
await Future<void>.delayed(
const Duration(milliseconds: 1000),
);
await Future<void>.delayed(const Duration(milliseconds: 1000));
setState(() {
items.insert(
0,
Container(color: colors[items.length % 3], height: 100.0),
);
items.insert(0, Container(color: colors[items.length % 3], height: 100.0));
});
},
),

View File

@@ -27,9 +27,7 @@ class CupertinoDialogExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('Home'),
),
navigationBar: const CupertinoNavigationBar(middle: Text('Home')),
child: Center(
child: CupertinoButton(
onPressed: () {

View File

@@ -27,9 +27,7 @@ class ModalPopupExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('Home'),
),
navigationBar: const CupertinoNavigationBar(middle: Text('Home')),
child: Center(
child: CupertinoButton(
onPressed: () {

View File

@@ -26,9 +26,7 @@ class ScrollbarExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoScrollbar Sample'),
),
navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoScrollbar Sample')),
child: CupertinoScrollbar(
thickness: 6.0,
thicknessWhileDragging: 10.0,
@@ -38,10 +36,7 @@ class ScrollbarExample extends StatelessWidget {
itemCount: 120,
itemBuilder: (BuildContext context, int index) {
return Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text('Item $index'),
),
child: Padding(padding: const EdgeInsets.all(8.0), child: Text('Item $index')),
);
},
),

View File

@@ -33,9 +33,7 @@ class _ScrollbarExampleState extends State<ScrollbarExample> {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoScrollbar Sample'),
),
navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoScrollbar Sample')),
child: CupertinoScrollbar(
thickness: 6.0,
thicknessWhileDragging: 10.0,
@@ -48,10 +46,7 @@ class _ScrollbarExampleState extends State<ScrollbarExample> {
itemCount: 120,
itemBuilder: (BuildContext context, int index) {
return Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text('Item $index'),
),
child: Padding(padding: const EdgeInsets.all(8.0), child: Text('Item $index')),
);
},
),

View File

@@ -45,16 +45,11 @@ class _SearchTextFieldExampleState extends State<SearchTextFieldExample> {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoSearchTextField Sample'),
),
navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoSearchTextField Sample')),
child: Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: CupertinoSearchTextField(
controller: textController,
placeholder: 'Search',
),
child: CupertinoSearchTextField(controller: textController, placeholder: 'Search'),
),
),
);

View File

@@ -33,9 +33,7 @@ class _SearchTextFieldExampleState extends State<SearchTextFieldExample> {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoSearchTextField Sample'),
),
navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoSearchTextField Sample')),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
@@ -59,10 +57,7 @@ class _SearchTextFieldExampleState extends State<SearchTextFieldExample> {
}
class SearchTextField extends StatelessWidget {
const SearchTextField({
super.key,
required this.fieldValue,
});
const SearchTextField({super.key, required this.fieldValue});
final ValueChanged<String> fieldValue;

View File

@@ -119,11 +119,7 @@ class _SegmentedControlExampleState extends State<SegmentedControlExample> {
_toggleOne = false;
_disabledChildren = <Sky>{};
} else {
_disabledChildren = <Sky>{
Sky.midnight,
Sky.viridian,
Sky.cerulean,
};
_disabledChildren = <Sky>{Sky.midnight, Sky.viridian, Sky.cerulean};
}
});
},

View File

@@ -60,24 +60,15 @@ class _SegmentedControlExampleState extends State<SegmentedControlExample> {
children: const <Sky, Widget>{
Sky.midnight: Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Text(
'Midnight',
style: TextStyle(color: CupertinoColors.white),
),
child: Text('Midnight', style: TextStyle(color: CupertinoColors.white)),
),
Sky.viridian: Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Text(
'Viridian',
style: TextStyle(color: CupertinoColors.white),
),
child: Text('Viridian', style: TextStyle(color: CupertinoColors.white)),
),
Sky.cerulean: Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Text(
'Cerulean',
style: TextStyle(color: CupertinoColors.white),
),
child: Text('Cerulean', style: TextStyle(color: CupertinoColors.white)),
),
},
),

View File

@@ -34,9 +34,7 @@ class _CupertinoSliderExampleState extends State<CupertinoSliderExample> {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoSlider Sample'),
),
navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoSlider Sample')),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
@@ -74,9 +72,7 @@ class _CupertinoSliderExampleState extends State<CupertinoSliderExample> {
),
Text(
_sliderStatus ?? '',
style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(
fontSize: 12,
),
style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(fontSize: 12),
),
],
),

View File

@@ -33,9 +33,7 @@ class _CupertinoSwitchExampleState extends State<CupertinoSwitchExample> {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoSwitch Sample'),
),
navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoSwitch Sample')),
child: Center(
child: CupertinoSwitch(
// This bool value toggles the switch.

View File

@@ -42,14 +42,8 @@ class _TabControllerExampleState extends State<TabControllerExample> {
controller: controller,
tabBar: CupertinoTabBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.square_grid_2x2_fill),
label: 'Browse',
),
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.star_circle_fill),
label: 'Starred',
),
BottomNavigationBarItem(icon: Icon(CupertinoIcons.square_grid_2x2_fill), label: 'Browse'),
BottomNavigationBarItem(icon: Icon(CupertinoIcons.star_circle_fill), label: 'Starred'),
],
),
tabBuilder: (BuildContext context, int index) {

View File

@@ -33,23 +33,15 @@ class _TabScaffoldExampleState extends State<TabScaffoldExample> {
return CupertinoTabScaffold(
tabBar: CupertinoTabBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.search_circle_fill),
label: 'Explore',
),
BottomNavigationBarItem(icon: Icon(CupertinoIcons.home), label: 'Home'),
BottomNavigationBarItem(icon: Icon(CupertinoIcons.search_circle_fill), label: 'Explore'),
],
),
tabBuilder: (BuildContext context, int index) {
return CupertinoTabView(
builder: (BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('Page 1 of tab $index'),
),
navigationBar: CupertinoNavigationBar(middle: Text('Page 1 of tab $index')),
child: Center(
child: CupertinoButton(
child: const Text('Next page'),

View File

@@ -45,14 +45,8 @@ class _CupertinoTextFieldExampleState extends State<CupertinoTextFieldExample> {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoTextField Sample'),
),
child: Center(
child: CupertinoTextField(
controller: _textController,
),
),
navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoTextField Sample')),
child: Center(child: CupertinoTextField(controller: _textController)),
);
}
}

View File

@@ -26,9 +26,7 @@ class FromSectionExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoFormSection Sample'),
),
navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoFormSection Sample')),
// Add safe area widget to place the CupertinoFormSection below the navigation bar.
child: SafeArea(
child: Form(

View File

@@ -15,9 +15,7 @@ class PointerSignalResolverExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: PointerSignalResolverExample(),
);
return const MaterialApp(home: PointerSignalResolverExample());
}
}
@@ -62,7 +60,9 @@ class _ColorChangerState extends State<ColorChanger> {
child: Listener(
onPointerSignal: (PointerSignalEvent event) {
if (widget.useResolver) {
GestureBinding.instance.pointerSignalResolver.register(event, (PointerSignalEvent event) {
GestureBinding.instance.pointerSignalResolver.register(event, (
PointerSignalEvent event,
) {
rotateColor();
});
} else {
@@ -71,10 +71,7 @@ class _ColorChangerState extends State<ColorChanger> {
},
child: Stack(
fit: StackFit.expand,
children: <Widget>[
const AbsorbPointer(),
if (widget.child != null) widget.child!,
],
children: <Widget>[const AbsorbPointer(), if (widget.child != null) widget.child!],
),
),
);

View File

@@ -17,13 +17,7 @@ class TapAndDragToZoomApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: Center(
child: TapAndDragToZoomWidget(
child: MyBoxWidget(),
),
),
),
home: Scaffold(body: Center(child: TapAndDragToZoomWidget(child: MyBoxWidget()))),
);
}
}
@@ -33,11 +27,7 @@ class MyBoxWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
color: Colors.blueAccent,
height: 100.0,
width: 100.0,
);
return Container(color: Colors.blueAccent, height: 100.0, width: 100.0);
}
}
@@ -101,38 +91,36 @@ class _TapAndDragToZoomWidgetState extends State<TapAndDragToZoomWidget> {
Widget build(BuildContext context) {
return RawGestureDetector(
gestures: <Type, GestureRecognizerFactory>{
TapAndPanGestureRecognizer: GestureRecognizerFactoryWithHandlers<TapAndPanGestureRecognizer>(
() => TapAndPanGestureRecognizer(),
(TapAndPanGestureRecognizer instance) {
instance
..onTapDown = (TapDragDownDetails details) {
_previousDragPosition = details.globalPosition;
}
..onDragStart = (TapDragStartDetails details) {
if (details.consecutiveTapCount == 2) {
_zoomLogic(details.globalPosition);
}
}
..onDragUpdate = (TapDragUpdateDetails details) {
if (details.consecutiveTapCount == 2) {
_zoomLogic(details.globalPosition);
}
}
..onDragEnd = (TapDragEndDetails details) {
if (details.consecutiveTapCount == 2) {
setState(() {
_currentScale = 1.0;
});
_previousDragPosition = null;
}
};
}
),
TapAndPanGestureRecognizer:
GestureRecognizerFactoryWithHandlers<TapAndPanGestureRecognizer>(
() => TapAndPanGestureRecognizer(),
(TapAndPanGestureRecognizer instance) {
instance
..onTapDown = (TapDragDownDetails details) {
_previousDragPosition = details.globalPosition;
}
..onDragStart = (TapDragStartDetails details) {
if (details.consecutiveTapCount == 2) {
_zoomLogic(details.globalPosition);
}
}
..onDragUpdate = (TapDragUpdateDetails details) {
if (details.consecutiveTapCount == 2) {
_zoomLogic(details.globalPosition);
}
}
..onDragEnd = (TapDragEndDetails details) {
if (details.consecutiveTapCount == 2) {
setState(() {
_currentScale = 1.0;
});
_previousDragPosition = null;
}
};
},
),
},
child: Transform.scale(
scale: _currentScale,
child: widget.child,
),
child: Transform.scale(scale: _currentScale, child: widget.child),
);
}
}

View File

@@ -13,9 +13,7 @@ class AboutListTileExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: AboutListTileExample(),
);
return const MaterialApp(home: AboutListTileExample());
}
}
@@ -32,11 +30,16 @@ class AboutListTileExample extends StatelessWidget {
text: TextSpan(
children: <TextSpan>[
TextSpan(
style: textStyle,
text: "Flutter is Google's UI toolkit for building beautiful, "
'natively compiled applications for mobile, web, and desktop '
'from a single codebase. Learn more about Flutter at '),
TextSpan(style: textStyle.copyWith(color: theme.colorScheme.primary), text: 'https://flutter.dev'),
style: textStyle,
text:
"Flutter is Google's UI toolkit for building beautiful, "
'natively compiled applications for mobile, web, and desktop '
'from a single codebase. Learn more about Flutter at ',
),
TextSpan(
style: textStyle.copyWith(color: theme.colorScheme.primary),
text: 'https://flutter.dev',
),
TextSpan(style: textStyle, text: '.'),
],
),
@@ -44,9 +47,7 @@ class AboutListTileExample extends StatelessWidget {
];
return Scaffold(
appBar: AppBar(
title: const Text('Show About Example'),
),
appBar: AppBar(title: const Text('Show About Example')),
drawer: Drawer(
child: SingleChildScrollView(
child: SafeArea(

View File

@@ -16,10 +16,7 @@ class _CustomEndDrawerIcon extends StatelessWidget {
@override
Widget build(BuildContext context) {
final MaterialLocalizations localization = MaterialLocalizations.of(context);
return Icon(
Icons.more_horiz,
semanticLabel: localization.openAppDrawerTooltip,
);
return Icon(Icons.more_horiz, semanticLabel: localization.openAppDrawerTooltip);
}
}
@@ -29,10 +26,7 @@ class _CustomDrawerIcon extends StatelessWidget {
@override
Widget build(BuildContext context) {
final MaterialLocalizations localization = MaterialLocalizations.of(context);
return Icon(
Icons.segment,
semanticLabel: localization.openAppDrawerTooltip,
);
return Icon(Icons.segment, semanticLabel: localization.openAppDrawerTooltip);
}
}
@@ -70,19 +64,13 @@ class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
appBar: AppBar(title: Text(title)),
drawer: Drawer(
child: Column(
children: <Widget>[
TextButton(child: const Text('Drawer Item'), onPressed: () {}),
],
children: <Widget>[TextButton(child: const Text('Drawer Item'), onPressed: () {})],
),
),
body: const Center(
child: NextPageButton(),
),
body: const Center(child: NextPageButton()),
);
}
}
@@ -95,9 +83,11 @@ class NextPageButton extends StatelessWidget {
return ElevatedButton.icon(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute<MySecondPage>(builder: (BuildContext context) {
return const MySecondPage();
}),
MaterialPageRoute<MySecondPage>(
builder: (BuildContext context) {
return const MySecondPage();
},
),
);
},
icon: const Icon(Icons.arrow_forward),
@@ -111,11 +101,6 @@ class MySecondPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Second page'),
),
endDrawer: const Drawer(),
);
return Scaffold(appBar: AppBar(title: const Text('Second page')), endDrawer: const Drawer());
}
}

View File

@@ -33,9 +33,7 @@ class _ActionChipExampleState extends State<ActionChipExample> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('ActionChip Sample'),
),
appBar: AppBar(title: const Text('ActionChip Sample')),
body: Center(
child: ActionChip(
avatar: Icon(favorite ? Icons.favorite : Icons.favorite_border),

View File

@@ -16,13 +16,8 @@ class AnimatedIconApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
colorSchemeSeed: const Color(0xff6750a4),
useMaterial3: true,
),
home: const Scaffold(
body: AnimatedIconExample(),
),
theme: ThemeData(colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true),
home: const Scaffold(body: AnimatedIconExample()),
);
}
}
@@ -34,19 +29,18 @@ class AnimatedIconExample extends StatefulWidget {
State<AnimatedIconExample> createState() => _AnimatedIconExampleState();
}
class _AnimatedIconExampleState extends State<AnimatedIconExample> with SingleTickerProviderStateMixin {
class _AnimatedIconExampleState extends State<AnimatedIconExample>
with SingleTickerProviderStateMixin {
late AnimationController controller;
late Animation<double> animation;
@override
void initState() {
super.initState();
controller = AnimationController(
vsync: this,
duration: const Duration(seconds: 2),
)
..forward()
..repeat(reverse: true);
controller =
AnimationController(vsync: this, duration: const Duration(seconds: 2))
..forward()
..repeat(reverse: true);
animation = Tween<double>(begin: 0.0, end: 1.0).animate(controller);
}

View File

@@ -33,13 +33,8 @@ class AnimatedIconApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
colorSchemeSeed: const Color(0xff6750a4),
useMaterial3: true,
),
home: const Scaffold(
body: AnimatedIconExample(),
),
theme: ThemeData(colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true),
home: const Scaffold(body: AnimatedIconExample()),
);
}
}
@@ -51,19 +46,18 @@ class AnimatedIconExample extends StatefulWidget {
State<AnimatedIconExample> createState() => _AnimatedIconExampleState();
}
class _AnimatedIconExampleState extends State<AnimatedIconExample> with SingleTickerProviderStateMixin {
class _AnimatedIconExampleState extends State<AnimatedIconExample>
with SingleTickerProviderStateMixin {
late AnimationController controller;
late Animation<double> animation;
@override
void initState() {
super.initState();
controller = AnimationController(
vsync: this,
duration: const Duration(seconds: 2),
)
..forward()
..repeat(reverse: true);
controller =
AnimationController(vsync: this, duration: const Duration(seconds: 2))
..forward()
..repeat(reverse: true);
animation = Tween<double>(begin: 0.0, end: 1.0).animate(controller);
}
@@ -77,28 +71,27 @@ class _AnimatedIconExampleState extends State<AnimatedIconExample> with SingleTi
Widget build(BuildContext context) {
return Scaffold(
body: GridView(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
),
children: iconsList.entries.map((MapEntry<String, AnimatedIconData> entry) {
return Card(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
AnimatedIcon(
icon: entry.value,
progress: animation,
size: 72.0,
semanticLabel: entry.key,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4),
children:
iconsList.entries.map((MapEntry<String, AnimatedIconData> entry) {
return Card(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
AnimatedIcon(
icon: entry.value,
progress: animation,
size: 72.0,
semanticLabel: entry.key,
),
const SizedBox(height: 8.0),
Text(entry.key),
],
),
const SizedBox(height: 8.0),
Text(entry.key),
],
),
),
);
}).toList(),
),
);
}).toList(),
),
);
}

View File

@@ -11,6 +11,7 @@ void main() {
}
enum AnimationStyles { defaultStyle, custom, none }
const List<(AnimationStyles, String)> animationStyleSegments = <(AnimationStyles, String)>[
(AnimationStyles.defaultStyle, 'Default'),
(AnimationStyles.custom, 'Custom'),
@@ -35,10 +36,7 @@ class _MaterialAppExampleState extends State<MaterialAppExample> {
themeAnimationStyle: _animationStyle,
themeMode: isDarkTheme ? ThemeMode.dark : ThemeMode.light,
theme: ThemeData(colorSchemeSeed: Colors.green),
darkTheme: ThemeData(
colorSchemeSeed: Colors.green,
brightness: Brightness.dark,
),
darkTheme: ThemeData(colorSchemeSeed: Colors.green, brightness: Brightness.dark),
home: Scaffold(
body: Center(
child: Column(
@@ -62,11 +60,12 @@ class _MaterialAppExampleState extends State<MaterialAppExample> {
}
});
},
segments: animationStyleSegments
.map<ButtonSegment<AnimationStyles>>(((AnimationStyles, String) shirt) {
return ButtonSegment<AnimationStyles>(value: shirt.$1, label: Text(shirt.$2));
})
.toList(),
segments:
animationStyleSegments.map<ButtonSegment<AnimationStyles>>((
(AnimationStyles, String) shirt,
) {
return ButtonSegment<AnimationStyles>(value: shirt.$1, label: Text(shirt.$2));
}).toList(),
),
const SizedBox(height: 10),
OutlinedButton.icon(

View File

@@ -13,9 +13,7 @@ class AppBarApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: AppBarExample(),
);
return const MaterialApp(home: AppBarExample());
}
}
@@ -32,38 +30,33 @@ class AppBarExample extends StatelessWidget {
icon: const Icon(Icons.add_alert),
tooltip: 'Show Snackbar',
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('This is a snackbar')));
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('This is a snackbar')));
},
),
IconButton(
icon: const Icon(Icons.navigate_next),
tooltip: 'Go to the next page',
onPressed: () {
Navigator.push(context, MaterialPageRoute<void>(
builder: (BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Next page'),
),
body: const Center(
child: Text(
'This is the next page',
style: TextStyle(fontSize: 24),
Navigator.push(
context,
MaterialPageRoute<void>(
builder: (BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Next page')),
body: const Center(
child: Text('This is the next page', style: TextStyle(fontSize: 24)),
),
),
);
},
));
);
},
),
);
},
),
],
),
body: const Center(
child: Text(
'This is the home page',
style: TextStyle(fontSize: 24),
),
),
body: const Center(child: Text('This is the home page', style: TextStyle(fontSize: 24))),
);
}
}

View File

@@ -16,10 +16,7 @@ class AppBarApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
colorSchemeSeed: const Color(0xff6750a4),
useMaterial3: true,
),
theme: ThemeData(colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true),
home: const AppBarExample(),
);
}
@@ -92,9 +89,7 @@ class _AppBarExampleState extends State<AppBarExample> {
shadowColor = !shadowColor;
});
},
icon: Icon(
shadowColor ? Icons.visibility_off : Icons.visibility,
),
icon: Icon(shadowColor ? Icons.visibility_off : Icons.visibility),
label: const Text('shadow color'),
),
const SizedBox(width: 5),
@@ -111,9 +106,7 @@ class _AppBarExampleState extends State<AppBarExample> {
});
}
},
child: Text(
'scrolledUnderElevation: ${scrolledUnderElevation ?? 'default'}',
),
child: Text('scrolledUnderElevation: ${scrolledUnderElevation ?? 'default'}'),
),
],
),

View File

@@ -13,9 +13,7 @@ class AppBarApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: AppBarExample(),
);
return const MaterialApp(home: AppBarExample());
}
}
@@ -30,16 +28,8 @@ class AppBarExample extends StatelessWidget {
return Scaffold(
appBar: AppBar(
actions: <Widget>[
TextButton(
style: style,
onPressed: () {},
child: const Text('Action 1'),
),
TextButton(
style: style,
onPressed: () {},
child: const Text('Action 2'),
),
TextButton(style: style, onPressed: () {}, child: const Text('Action 1')),
TextButton(style: style, onPressed: () {}, child: const Text('Action 2')),
],
),
);

View File

@@ -6,11 +6,7 @@ import 'package:flutter/material.dart';
/// Flutter code sample for [AppBar].
List<String> titles = <String>[
'Cloud',
'Beach',
'Sunny',
];
List<String> titles = <String>['Cloud', 'Beach', 'Sunny'];
void main() => runApp(const AppBarApp());
@@ -60,18 +56,9 @@ class AppBarExample extends StatelessWidget {
shadowColor: Theme.of(context).shadowColor,
bottom: TabBar(
tabs: <Widget>[
Tab(
icon: const Icon(Icons.cloud_outlined),
text: titles[0],
),
Tab(
icon: const Icon(Icons.beach_access_sharp),
text: titles[1],
),
Tab(
icon: const Icon(Icons.brightness_5_sharp),
text: titles[2],
),
Tab(icon: const Icon(Icons.cloud_outlined), text: titles[0]),
Tab(icon: const Icon(Icons.beach_access_sharp), text: titles[1]),
Tab(icon: const Icon(Icons.brightness_5_sharp), text: titles[2]),
],
),
),

View File

@@ -13,9 +13,7 @@ class AppBarExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: AppBarExample(),
);
return const MaterialApp(home: AppBarExample());
}
}
@@ -37,24 +35,16 @@ class AppBarExample extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: TextField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide(color: colorScheme.primary),
),
border: OutlineInputBorder(borderSide: BorderSide(color: colorScheme.primary)),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: colorScheme.onPrimaryContainer),
),
filled: true,
hintText: 'Enter a search term',
fillColor: colorScheme.surface,
prefixIcon: Icon(
Icons.search_rounded,
color: colorScheme.primary
),
suffixIcon: Icon(
Icons.tune_rounded,
color: colorScheme.primary
),
)
prefixIcon: Icon(Icons.search_rounded, color: colorScheme.primary),
suffixIcon: Icon(Icons.tune_rounded, color: colorScheme.primary),
),
),
),
),
@@ -63,9 +53,7 @@ class AppBarExample extends StatelessWidget {
padding: const EdgeInsets.only(top: 45.0),
itemCount: 20,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text('Item $index'),
);
return ListTile(title: Text('Item $index'));
},
),
);
@@ -75,11 +63,11 @@ class AppBarExample extends StatelessWidget {
class CustomAppBarShape extends OutlinedBorder {
// Implementing the constructor allows the CustomAppBarShape to be
// properly compared when calling the `identical` method.
const CustomAppBarShape({ super.side });
const CustomAppBarShape({super.side});
Path _getPath(Rect rect) {
Path _getPath(Rect rect) {
final Path path = Path();
final Size size = Size(rect.width, rect.height * 1.5) ;
final Size size = Size(rect.width, rect.height * 1.5);
final double p0 = size.height * 0.75;
path.lineTo(0.0, p0);
@@ -92,7 +80,7 @@ class CustomAppBarShape extends OutlinedBorder {
path.close();
return path;
}
}
@override
Path getOuterPath(Rect rect, {TextDirection? textDirection}) {
@@ -109,10 +97,7 @@ class CustomAppBarShape extends OutlinedBorder {
if (rect.isEmpty) {
return;
}
canvas.drawPath(
getOuterPath(rect, textDirection: textDirection),
side.toPaint(),
);
canvas.drawPath(getOuterPath(rect, textDirection: textDirection), side.toPaint());
}
@override

View File

@@ -13,9 +13,7 @@ class AppBarApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: SliverAppBarExample(),
);
return const MaterialApp(home: SliverAppBarExample());
}
}
@@ -31,8 +29,8 @@ class _SliverAppBarExampleState extends State<SliverAppBarExample> {
bool _snap = false;
bool _floating = false;
// [SliverAppBar]s are typically used in [CustomScrollView.slivers], which in
// turn can be placed in a [Scaffold.body].
// [SliverAppBar]s are typically used in [CustomScrollView.slivers], which in
// turn can be placed in a [Scaffold.body].
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -51,24 +49,17 @@ class _SliverAppBarExampleState extends State<SliverAppBarExample> {
const SliverToBoxAdapter(
child: SizedBox(
height: 20,
child: Center(
child: Text('Scroll to see the SliverAppBar in effect.'),
),
child: Center(child: Text('Scroll to see the SliverAppBar in effect.')),
),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
color: index.isOdd ? Colors.white : Colors.black12,
height: 100.0,
child: Center(
child: Text('$index', textScaler: const TextScaler.linear(5)),
),
);
},
childCount: 20,
),
delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
return Container(
color: index.isOdd ? Colors.white : Colors.black12,
height: 100.0,
child: Center(child: Text('$index', textScaler: const TextScaler.linear(5))),
);
}, childCount: 20),
),
],
),

View File

@@ -16,19 +16,14 @@ class AppBarMediumApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
useMaterial3: true,
colorSchemeSeed: const Color(0xff6750A4),
),
theme: ThemeData(useMaterial3: true, colorSchemeSeed: const Color(0xff6750A4)),
home: Material(
child: CustomScrollView(
slivers: <Widget>[
SliverAppBar.medium(
leading: IconButton(icon: const Icon(Icons.menu), onPressed: () {}),
title: const Text('Medium App Bar'),
actions: <Widget>[
IconButton(icon: const Icon(Icons.more_vert), onPressed: () {}),
],
actions: <Widget>[IconButton(icon: const Icon(Icons.more_vert), onPressed: () {})],
),
// Just some content big enough to have something to scroll.
SliverToBoxAdapter(

View File

@@ -16,19 +16,14 @@ class AppBarLargeApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
useMaterial3: true,
colorSchemeSeed: const Color(0xff6750A4),
),
theme: ThemeData(useMaterial3: true, colorSchemeSeed: const Color(0xff6750A4)),
home: Material(
child: CustomScrollView(
slivers: <Widget>[
SliverAppBar.large(
leading: IconButton(icon: const Icon(Icons.menu), onPressed: () {}),
title: const Text('Large App Bar'),
actions: <Widget>[
IconButton(icon: const Icon(Icons.more_vert), onPressed: () {}),
],
actions: <Widget>[IconButton(icon: const Icon(Icons.more_vert), onPressed: () {})],
),
// Just some content big enough to have something to scroll.
SliverToBoxAdapter(

View File

@@ -14,8 +14,7 @@ class StretchableSliverAppBar extends StatefulWidget {
const StretchableSliverAppBar({super.key});
@override
State<StretchableSliverAppBar> createState() =>
_StretchableSliverAppBarState();
State<StretchableSliverAppBar> createState() => _StretchableSliverAppBarState();
}
class _StretchableSliverAppBarState extends State<StretchableSliverAppBar> {
@@ -23,68 +22,64 @@ class _StretchableSliverAppBarState extends State<StretchableSliverAppBar> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: CustomScrollView(
physics: const BouncingScrollPhysics(),
slivers: <Widget>[
SliverAppBar(
stretch: _stretch,
onStretchTrigger: () async {
// Triggers when stretching
},
// [stretchTriggerOffset] describes the amount of overscroll that must occur
// to trigger [onStretchTrigger]
//
// Setting [stretchTriggerOffset] to a value of 300.0 will trigger
// [onStretchTrigger] when the user has overscrolled by 300.0 pixels.
stretchTriggerOffset: 300.0,
expandedHeight: 200.0,
flexibleSpace: const FlexibleSpaceBar(
title: Text('SliverAppBar'),
background: FlutterLogo(),
home: Scaffold(
body: CustomScrollView(
physics: const BouncingScrollPhysics(),
slivers: <Widget>[
SliverAppBar(
stretch: _stretch,
onStretchTrigger: () async {
// Triggers when stretching
},
// [stretchTriggerOffset] describes the amount of overscroll that must occur
// to trigger [onStretchTrigger]
//
// Setting [stretchTriggerOffset] to a value of 300.0 will trigger
// [onStretchTrigger] when the user has overscrolled by 300.0 pixels.
stretchTriggerOffset: 300.0,
expandedHeight: 200.0,
flexibleSpace: const FlexibleSpaceBar(
title: Text('SliverAppBar'),
background: FlutterLogo(),
),
),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
SliverList(
delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
return Container(
color: index.isOdd ? Colors.white : Colors.black12,
height: 100.0,
child: Center(
child: Text('$index', textScaler: const TextScaler.linear(5.0)),
),
child: Center(child: Text('$index', textScaler: const TextScaler.linear(5.0))),
);
},
childCount: 20,
}, childCount: 20),
),
],
),
bottomNavigationBar: BottomAppBar(
child: Padding(
padding: const EdgeInsets.all(8),
child: OverflowBar(
overflowAlignment: OverflowBarAlignment.center,
alignment: MainAxisAlignment.center,
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const Text('stretch'),
Switch(
onChanged: (bool val) {
setState(() {
_stretch = val;
});
},
value: _stretch,
),
],
),
],
),
),
],
),
bottomNavigationBar: BottomAppBar(
child: Padding(
padding: const EdgeInsets.all(8),
child: OverflowBar(
overflowAlignment: OverflowBarAlignment.center,
alignment: MainAxisAlignment.center,
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const Text('stretch'),
Switch(
onChanged: (bool val) {
setState(() {
_stretch = val;
});
},
value: _stretch,
),
],
),
],
),
),
),
));
);
}
}

View File

@@ -15,14 +15,14 @@ class AutocompleteExampleApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Autocomplete Basic'),
),
appBar: AppBar(title: const Text('Autocomplete Basic')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Type below to autocomplete the following possible results: ${AutocompleteBasicExample._kOptions}.'),
Text(
'Type below to autocomplete the following possible results: ${AutocompleteBasicExample._kOptions}.',
),
const AutocompleteBasicExample(),
],
),
@@ -35,11 +35,7 @@ class AutocompleteExampleApp extends StatelessWidget {
class AutocompleteBasicExample extends StatelessWidget {
const AutocompleteBasicExample({super.key});
static const List<String> _kOptions = <String>[
'aardvark',
'bobcat',
'chameleon',
];
static const List<String> _kOptions = <String>['aardvark', 'bobcat', 'chameleon'];
@override
Widget build(BuildContext context) {

View File

@@ -15,14 +15,14 @@ class AutocompleteExampleApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Autocomplete Basic User'),
),
appBar: AppBar(title: const Text('Autocomplete Basic User')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Type below to autocomplete the following possible results: ${AutocompleteBasicUserExample._userOptions}.'),
Text(
'Type below to autocomplete the following possible results: ${AutocompleteBasicUserExample._userOptions}.',
),
const AutocompleteBasicUserExample(),
],
),
@@ -34,10 +34,7 @@ class AutocompleteExampleApp extends StatelessWidget {
@immutable
class User {
const User({
required this.email,
required this.name,
});
const User({required this.email, required this.name});
final String email;
final String name;

View File

@@ -18,14 +18,14 @@ class AutocompleteExampleApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Autocomplete - async'),
),
appBar: AppBar(title: const Text('Autocomplete - async')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Type below to autocomplete the following possible results: ${_FakeAPI._kOptions}.'),
Text(
'Type below to autocomplete the following possible results: ${_FakeAPI._kOptions}.',
),
const _AsyncAutocomplete(),
],
),
@@ -39,10 +39,10 @@ class _AsyncAutocomplete extends StatefulWidget {
const _AsyncAutocomplete();
@override
State<_AsyncAutocomplete > createState() => _AsyncAutocompleteState();
State<_AsyncAutocomplete> createState() => _AsyncAutocompleteState();
}
class _AsyncAutocompleteState extends State<_AsyncAutocomplete > {
class _AsyncAutocompleteState extends State<_AsyncAutocomplete> {
// The query currently being searched for. If null, there is no pending
// request.
String? _searchingWithQuery;
@@ -76,11 +76,7 @@ class _AsyncAutocompleteState extends State<_AsyncAutocomplete > {
// Mimics a remote API.
class _FakeAPI {
static const List<String> _kOptions = <String>[
'aardvark',
'bobcat',
'chameleon',
];
static const List<String> _kOptions = <String>['aardvark', 'bobcat', 'chameleon'];
// Searches the options, but injects a fake "network" delay.
static Future<Iterable<String>> search(String query) async {

View File

@@ -21,14 +21,14 @@ class AutocompleteExampleApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Autocomplete - async and debouncing'),
),
appBar: AppBar(title: const Text('Autocomplete - async and debouncing')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Type below to autocomplete the following possible results: ${_FakeAPI._kOptions}.'),
Text(
'Type below to autocomplete the following possible results: ${_FakeAPI._kOptions}.',
),
const _AsyncAutocomplete(),
],
),
@@ -42,10 +42,10 @@ class _AsyncAutocomplete extends StatefulWidget {
const _AsyncAutocomplete();
@override
State<_AsyncAutocomplete > createState() => _AsyncAutocompleteState();
State<_AsyncAutocomplete> createState() => _AsyncAutocompleteState();
}
class _AsyncAutocompleteState extends State<_AsyncAutocomplete > {
class _AsyncAutocompleteState extends State<_AsyncAutocomplete> {
// The query currently being searched for. If null, there is no pending
// request.
String? _currentQuery;
@@ -98,11 +98,7 @@ class _AsyncAutocompleteState extends State<_AsyncAutocomplete > {
// Mimics a remote API.
class _FakeAPI {
static const List<String> _kOptions = <String>[
'aardvark',
'bobcat',
'chameleon',
];
static const List<String> _kOptions = <String>['aardvark', 'bobcat', 'chameleon'];
// Searches the options, but injects a fake "network" delay.
static Future<Iterable<String>> search(String query) async {
@@ -141,8 +137,7 @@ _Debounceable<S, T> _debounce<S, T>(_Debounceable<S?, T> function) {
// A wrapper around Timer used for debouncing.
class _DebounceTimer {
_DebounceTimer(
) {
_DebounceTimer() {
_timer = Timer(debounceDuration, _onComplete);
}

View File

@@ -22,14 +22,14 @@ class AutocompleteExampleApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Autocomplete - async, debouncing, and network errors'),
),
appBar: AppBar(title: const Text('Autocomplete - async, debouncing, and network errors')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Type below to autocomplete the following possible results: ${_FakeAPI._kOptions}.'),
Text(
'Type below to autocomplete the following possible results: ${_FakeAPI._kOptions}.',
),
const SizedBox(height: 32.0),
const _AsyncAutocomplete(),
],
@@ -44,10 +44,10 @@ class _AsyncAutocomplete extends StatefulWidget {
const _AsyncAutocomplete();
@override
State<_AsyncAutocomplete > createState() => _AsyncAutocompleteState();
State<_AsyncAutocomplete> createState() => _AsyncAutocompleteState();
}
class _AsyncAutocompleteState extends State<_AsyncAutocomplete > {
class _AsyncAutocompleteState extends State<_AsyncAutocomplete> {
// The query currently being searched for. If null, there is no pending
// request.
String? _currentQuery;
@@ -113,11 +113,14 @@ class _AsyncAutocompleteState extends State<_AsyncAutocomplete > {
});
},
),
const SizedBox(
height: 32.0,
),
const SizedBox(height: 32.0),
Autocomplete<String>(
fieldViewBuilder: (BuildContext context, TextEditingController controller, FocusNode focusNode, VoidCallback onFieldSubmitted) {
fieldViewBuilder: (
BuildContext context,
TextEditingController controller,
FocusNode focusNode,
VoidCallback onFieldSubmitted,
) {
return TextFormField(
decoration: InputDecoration(
errorText: _networkError ? 'Network error, please try again.' : null,
@@ -151,11 +154,7 @@ class _AsyncAutocompleteState extends State<_AsyncAutocomplete > {
// Mimics a remote API.
class _FakeAPI {
static const List<String> _kOptions = <String>[
'aardvark',
'bobcat',
'chameleon',
];
static const List<String> _kOptions = <String>['aardvark', 'bobcat', 'chameleon'];
// Searches the options, but injects a fake "network" delay.
static Future<Iterable<String>> search(String query, bool networkEnabled) async {
@@ -197,8 +196,7 @@ _Debounceable<S, T> _debounce<S, T>(_Debounceable<S?, T> function) {
// A wrapper around Timer used for debouncing.
class _DebounceTimer {
_DebounceTimer(
) {
_DebounceTimer() {
_timer = Timer(debounceDuration, _onComplete);
}

View File

@@ -14,10 +14,7 @@ class BadgeExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Badge Sample')),
body: const BadgeExample(),
),
home: Scaffold(appBar: AppBar(title: const Text('Badge Sample')), body: const BadgeExample()),
);
}
}
@@ -41,10 +38,7 @@ class BadgeExample extends StatelessWidget {
),
const SizedBox(height: 20),
IconButton(
icon: Badge.count(
count: 9999,
child: const Icon(Icons.notifications),
),
icon: Badge.count(count: 9999, child: const Icon(Icons.notifications)),
onPressed: () {},
),
],

View File

@@ -13,9 +13,7 @@ class MaterialBannerExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: MaterialBannerExample(),
);
return const MaterialApp(home: MaterialBannerExample());
}
}
@@ -25,23 +23,15 @@ class MaterialBannerExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('The MaterialBanner is below'),
),
appBar: AppBar(title: const Text('The MaterialBanner is below')),
body: const MaterialBanner(
padding: EdgeInsets.all(20),
content: Text('Hello, I am a Material Banner'),
leading: Icon(Icons.agriculture_outlined),
backgroundColor: Color(0xFFE0E0E0),
actions: <Widget>[
TextButton(
onPressed: null,
child: Text('OPEN'),
),
TextButton(
onPressed: null,
child: Text('DISMISS'),
),
TextButton(onPressed: null, child: Text('OPEN')),
TextButton(onPressed: null, child: Text('DISMISS')),
],
),
);

View File

@@ -13,9 +13,7 @@ class MaterialBannerExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: MaterialBannerExample(),
);
return const MaterialApp(home: MaterialBannerExample());
}
}
@@ -25,26 +23,20 @@ class MaterialBannerExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('The MaterialBanner is below'),
),
appBar: AppBar(title: const Text('The MaterialBanner is below')),
body: Center(
child: ElevatedButton(
child: const Text('Show MaterialBanner'),
onPressed: () => ScaffoldMessenger.of(context).showMaterialBanner(
const MaterialBanner(
padding: EdgeInsets.all(20),
content: Text('Hello, I am a Material Banner'),
leading: Icon(Icons.agriculture_outlined),
backgroundColor: Colors.green,
actions: <Widget>[
TextButton(
onPressed: null,
child: Text('DISMISS'),
onPressed:
() => ScaffoldMessenger.of(context).showMaterialBanner(
const MaterialBanner(
padding: EdgeInsets.all(20),
content: Text('Hello, I am a Material Banner'),
leading: Icon(Icons.agriculture_outlined),
backgroundColor: Colors.green,
actions: <Widget>[TextButton(onPressed: null, child: Text('DISMISS'))],
),
],
),
),
),
),
),
);

View File

@@ -44,17 +44,12 @@ class _BottomAppBarDemoState extends State<BottomAppBarDemo> {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: const Text('Bottom App Bar Demo'),
),
appBar: AppBar(automaticallyImplyLeading: false, title: const Text('Bottom App Bar Demo')),
body: ListView(
padding: const EdgeInsets.only(bottom: 88),
children: <Widget>[
SwitchListTile(
title: const Text(
'Floating Action Button',
),
title: const Text('Floating Action Button'),
value: _showFab,
onChanged: _onShowFabChanged,
),
@@ -93,13 +88,14 @@ class _BottomAppBarDemoState extends State<BottomAppBarDemo> {
),
],
),
floatingActionButton: _showFab
? FloatingActionButton(
onPressed: () {},
tooltip: 'Create',
child: const Icon(Icons.add),
)
: null,
floatingActionButton:
_showFab
? FloatingActionButton(
onPressed: () {},
tooltip: 'Create',
child: const Icon(Icons.add),
)
: null,
floatingActionButtonLocation: _fabLocation,
bottomNavigationBar: _DemoBottomAppBar(
fabLocation: _fabLocation,
@@ -139,16 +135,8 @@ class _DemoBottomAppBar extends StatelessWidget {
onPressed: () {},
),
if (centerLocations.contains(fabLocation)) const Spacer(),
IconButton(
tooltip: 'Search',
icon: const Icon(Icons.search),
onPressed: () {},
),
IconButton(
tooltip: 'Favorite',
icon: const Icon(Icons.favorite),
onPressed: () {},
),
IconButton(tooltip: 'Search', icon: const Icon(Icons.search), onPressed: () {}),
IconButton(tooltip: 'Favorite', icon: const Icon(Icons.favorite), onPressed: () {}),
],
),
),

View File

@@ -27,10 +27,11 @@ class _BottomAppBarDemoState extends State<BottomAppBarDemo> {
Colors.cyan,
];
static final List<Widget> items = List<Widget>.generate(
colors.length,
(int index) => Container(color: colors[index], height: 150.0),
).reversed.toList();
static final List<Widget> items =
List<Widget>.generate(
colors.length,
(int index) => Container(color: colors[index], height: 150.0),
).reversed.toList();
late ScrollController _controller;
bool _showFab = true;
@@ -38,7 +39,9 @@ class _BottomAppBarDemoState extends State<BottomAppBarDemo> {
bool _isVisible = true;
FloatingActionButtonLocation get _fabLocation =>
_isVisible ? FloatingActionButtonLocation.endContained : FloatingActionButtonLocation.endFloat;
_isVisible
? FloatingActionButtonLocation.endContained
: FloatingActionButtonLocation.endFloat;
void _listen() {
switch (_controller.position.userScrollDirection) {
@@ -77,10 +80,7 @@ class _BottomAppBarDemoState extends State<BottomAppBarDemo> {
void _addNewItem() {
setState(() {
items.insert(
0,
Container(color: colors[items.length % 5], height: 150.0),
);
items.insert(0, Container(color: colors[items.length % 5], height: 150.0));
});
}
@@ -103,9 +103,7 @@ class _BottomAppBarDemoState extends State<BottomAppBarDemo> {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: Scaffold(
appBar: AppBar(
title: const Text('Bottom App Bar Demo'),
),
appBar: AppBar(title: const Text('Bottom App Bar Demo')),
body: Column(
children: <Widget>[
SwitchListTile(
@@ -118,22 +116,18 @@ class _BottomAppBarDemoState extends State<BottomAppBarDemo> {
value: _isElevated,
onChanged: _onElevatedChanged,
),
Expanded(
child: ListView(
controller: _controller,
children: items.toList(),
),
),
Expanded(child: ListView(controller: _controller, children: items.toList())),
],
),
floatingActionButton: _showFab
? FloatingActionButton(
onPressed: _addNewItem,
tooltip: 'Add New Item',
elevation: _isVisible ? 0.0 : null,
child: const Icon(Icons.add),
)
: null,
floatingActionButton:
_showFab
? FloatingActionButton(
onPressed: _addNewItem,
tooltip: 'Add New Item',
elevation: _isVisible ? 0.0 : null,
child: const Icon(Icons.add),
)
: null,
floatingActionButtonLocation: _fabLocation,
bottomNavigationBar: _DemoBottomAppBar(isElevated: _isElevated, isVisible: _isVisible),
),
@@ -142,10 +136,7 @@ class _BottomAppBarDemoState extends State<BottomAppBarDemo> {
}
class _DemoBottomAppBar extends StatelessWidget {
const _DemoBottomAppBar({
required this.isElevated,
required this.isVisible,
});
const _DemoBottomAppBar({required this.isElevated, required this.isVisible});
final bool isElevated;
final bool isVisible;
@@ -165,10 +156,7 @@ class _DemoBottomAppBar extends StatelessWidget {
onPressed: () {
final SnackBar snackBar = SnackBar(
content: const Text('Yay! A SnackBar!'),
action: SnackBarAction(
label: 'Undo',
onPressed: () {},
),
action: SnackBarAction(label: 'Undo', onPressed: () {}),
);
// Find the ScaffoldMessenger in the widget tree
@@ -176,16 +164,8 @@ class _DemoBottomAppBar extends StatelessWidget {
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
),
IconButton(
tooltip: 'Search',
icon: const Icon(Icons.search),
onPressed: () {},
),
IconButton(
tooltip: 'Favorite',
icon: const Icon(Icons.favorite),
onPressed: () {},
),
IconButton(tooltip: 'Search', icon: const Icon(Icons.search), onPressed: () {}),
IconButton(tooltip: 'Favorite', icon: const Icon(Icons.favorite), onPressed: () {}),
],
),
),

View File

@@ -13,9 +13,7 @@ class BottomNavigationBarExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: BottomNavigationBarExample(),
);
return const MaterialApp(home: BottomNavigationBarExample());
}
}
@@ -30,18 +28,9 @@ class _BottomNavigationBarExampleState extends State<BottomNavigationBarExample>
int _selectedIndex = 0;
static const TextStyle optionStyle = TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static const List<Widget> _widgetOptions = <Widget>[
Text(
'Index 0: Home',
style: optionStyle,
),
Text(
'Index 1: Business',
style: optionStyle,
),
Text(
'Index 2: School',
style: optionStyle,
),
Text('Index 0: Home', style: optionStyle),
Text('Index 1: Business', style: optionStyle),
Text('Index 2: School', style: optionStyle),
];
void _onItemTapped(int index) {
@@ -53,26 +42,13 @@ class _BottomNavigationBarExampleState extends State<BottomNavigationBarExample>
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('BottomNavigationBar Sample'),
),
body: Center(
child: _widgetOptions.elementAt(_selectedIndex),
),
appBar: AppBar(title: const Text('BottomNavigationBar Sample')),
body: Center(child: _widgetOptions.elementAt(_selectedIndex)),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.business),
label: 'Business',
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
label: 'School',
),
BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
BottomNavigationBarItem(icon: Icon(Icons.business), label: 'Business'),
BottomNavigationBarItem(icon: Icon(Icons.school), label: 'School'),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.amber[800],

View File

@@ -13,9 +13,7 @@ class BottomNavigationBarExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: BottomNavigationBarExample(),
);
return const MaterialApp(home: BottomNavigationBarExample());
}
}
@@ -30,22 +28,10 @@ class _BottomNavigationBarExampleState extends State<BottomNavigationBarExample>
int _selectedIndex = 0;
static const TextStyle optionStyle = TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static const List<Widget> _widgetOptions = <Widget>[
Text(
'Index 0: Home',
style: optionStyle,
),
Text(
'Index 1: Business',
style: optionStyle,
),
Text(
'Index 2: School',
style: optionStyle,
),
Text(
'Index 3: Settings',
style: optionStyle,
),
Text('Index 0: Home', style: optionStyle),
Text('Index 1: Business', style: optionStyle),
Text('Index 2: School', style: optionStyle),
Text('Index 3: Settings', style: optionStyle),
];
void _onItemTapped(int index) {
@@ -57,12 +43,8 @@ class _BottomNavigationBarExampleState extends State<BottomNavigationBarExample>
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('BottomNavigationBar Sample'),
),
body: Center(
child: _widgetOptions.elementAt(_selectedIndex),
),
appBar: AppBar(title: const Text('BottomNavigationBar Sample')),
body: Center(child: _widgetOptions.elementAt(_selectedIndex)),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(

View File

@@ -13,9 +13,7 @@ class BottomNavigationBarExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: BottomNavigationBarExample(),
);
return const MaterialApp(home: BottomNavigationBarExample());
}
}
@@ -32,37 +30,24 @@ class _BottomNavigationBarExampleState extends State<BottomNavigationBarExample>
Widget _listViewBody() {
return ListView.separated(
controller: _homeController,
itemBuilder: (BuildContext context, int index) {
return Center(
child: Text(
'Item $index',
),
);
},
separatorBuilder: (BuildContext context, int index) => const Divider(
thickness: 1,
),
itemCount: 50);
controller: _homeController,
itemBuilder: (BuildContext context, int index) {
return Center(child: Text('Item $index'));
},
separatorBuilder: (BuildContext context, int index) => const Divider(thickness: 1),
itemCount: 50,
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('BottomNavigationBar Sample'),
),
appBar: AppBar(title: const Text('BottomNavigationBar Sample')),
body: _listViewBody(),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.open_in_new_rounded),
label: 'Open Dialog',
),
BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
BottomNavigationBarItem(icon: Icon(Icons.open_in_new_rounded), label: 'Open Dialog'),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.amber[800],
@@ -80,11 +65,9 @@ class _BottomNavigationBarExampleState extends State<BottomNavigationBarExample>
case 1:
showModal(context);
}
setState(
() {
_selectedIndex = index;
},
);
setState(() {
_selectedIndex = index;
});
},
),
);
@@ -93,17 +76,18 @@ class _BottomNavigationBarExampleState extends State<BottomNavigationBarExample>
void showModal(BuildContext context) {
showDialog<void>(
context: context,
builder: (BuildContext context) => AlertDialog(
content: const Text('Example Dialog'),
actions: <TextButton>[
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Close'),
)
],
),
builder:
(BuildContext context) => AlertDialog(
content: const Text('Example Dialog'),
actions: <TextButton>[
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Close'),
),
],
),
);
}
}

View File

@@ -23,6 +23,7 @@ class BottomSheetExampleApp extends StatelessWidget {
}
enum AnimationStyles { defaultStyle, custom, none }
const List<(AnimationStyles, String)> animationStyleSegments = <(AnimationStyles, String)>[
(AnimationStyles.defaultStyle, 'Default'),
(AnimationStyles.custom, 'Custom'),
@@ -61,11 +62,12 @@ class _BottomSheetExampleState extends State<BottomSheetExample> {
_animationStyleSelection = styles;
});
},
segments: animationStyleSegments
.map<ButtonSegment<AnimationStyles>>(((AnimationStyles, String) shirt) {
return ButtonSegment<AnimationStyles>(value: shirt.$1, label: Text(shirt.$2));
})
.toList(),
segments:
animationStyleSegments.map<ButtonSegment<AnimationStyles>>((
(AnimationStyles, String) shirt,
) {
return ButtonSegment<AnimationStyles>(value: shirt.$1, label: Text(shirt.$2));
}).toList(),
),
const SizedBox(height: 10),
ElevatedButton(

View File

@@ -14,10 +14,7 @@ class BottomSheetApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
colorSchemeSeed: const Color(0xff6750a4),
useMaterial3: true,
),
theme: ThemeData(colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true),
home: Scaffold(
appBar: AppBar(title: const Text('Bottom Sheet Sample')),
body: const BottomSheetExample(),

View File

@@ -23,6 +23,7 @@ class ModalBottomSheetApp extends StatelessWidget {
}
enum AnimationStyles { defaultStyle, custom, none }
const List<(AnimationStyles, String)> animationStyleSegments = <(AnimationStyles, String)>[
(AnimationStyles.defaultStyle, 'Default'),
(AnimationStyles.custom, 'Custom'),
@@ -61,11 +62,12 @@ class _ModalBottomSheetExampleState extends State<ModalBottomSheetExample> {
_animationStyleSelection = styles;
});
},
segments: animationStyleSegments
.map<ButtonSegment<AnimationStyles>>(((AnimationStyles, String) shirt) {
return ButtonSegment<AnimationStyles>(value: shirt.$1, label: Text(shirt.$2));
})
.toList(),
segments:
animationStyleSegments.map<ButtonSegment<AnimationStyles>>((
(AnimationStyles, String) shirt,
) {
return ButtonSegment<AnimationStyles>(value: shirt.$1, label: Text(shirt.$2));
}).toList(),
),
const SizedBox(height: 10),
ElevatedButton(

View File

@@ -18,9 +18,7 @@ class ButtonApp extends StatelessWidget {
return MaterialApp(
theme: ThemeData(colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true),
title: 'Button Types',
home: const Scaffold(
body: ButtonTypesExample(),
),
home: const Scaffold(body: ButtonTypesExample()),
);
}
}

View File

@@ -15,11 +15,7 @@ class ButtonStyleButtonIconAlignmentApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: ButtonStyleButtonIconAlignmentExample(),
),
);
return const MaterialApp(home: Scaffold(body: ButtonStyleButtonIconAlignmentExample()));
}
}
@@ -27,10 +23,12 @@ class ButtonStyleButtonIconAlignmentExample extends StatefulWidget {
const ButtonStyleButtonIconAlignmentExample({super.key});
@override
State<ButtonStyleButtonIconAlignmentExample> createState() => _ButtonStyleButtonIconAlignmentExampleState();
State<ButtonStyleButtonIconAlignmentExample> createState() =>
_ButtonStyleButtonIconAlignmentExampleState();
}
class _ButtonStyleButtonIconAlignmentExampleState extends State<ButtonStyleButtonIconAlignmentExample> {
class _ButtonStyleButtonIconAlignmentExampleState
extends State<ButtonStyleButtonIconAlignmentExample> {
TextDirection _textDirection = TextDirection.ltr;
IconAlignment _iconAlignment = IconAlignment.start;
@@ -101,13 +99,14 @@ class _ButtonStyleButtonIconAlignmentExampleState extends State<ButtonStyleButto
_iconAlignment = value.first;
});
},
selected: <IconAlignment>{ _iconAlignment },
segments: IconAlignment.values.map((IconAlignment iconAlignment) {
return ButtonSegment<IconAlignment>(
value: iconAlignment,
label: Text(iconAlignment.name),
);
}).toList(),
selected: <IconAlignment>{_iconAlignment},
segments:
IconAlignment.values.map((IconAlignment iconAlignment) {
return ButtonSegment<IconAlignment>(
value: iconAlignment,
label: Text(iconAlignment.name),
);
}).toList(),
),
],
),
@@ -121,7 +120,7 @@ class _ButtonStyleButtonIconAlignmentExampleState extends State<ButtonStyleButto
_textDirection = value.first;
});
},
selected: <TextDirection>{ _textDirection },
selected: <TextDirection>{_textDirection},
segments: const <ButtonSegment<TextDirection>>[
ButtonSegment<TextDirection>(
value: TextDirection.ltr,

View File

@@ -14,10 +14,7 @@ class CardExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Card Sample')),
body: const CardExample(),
),
home: Scaffold(appBar: AppBar(title: const Text('Card Sample')), body: const CardExample()),
);
}
}
@@ -42,12 +39,16 @@ class CardExample extends StatelessWidget {
children: <Widget>[
TextButton(
child: const Text('BUY TICKETS'),
onPressed: () {/* ... */},
onPressed: () {
/* ... */
},
),
const SizedBox(width: 8),
TextButton(
child: const Text('LISTEN'),
onPressed: () {/* ... */},
onPressed: () {
/* ... */
},
),
const SizedBox(width: 8),
],

View File

@@ -14,10 +14,7 @@ class CardExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Card Sample')),
body: const CardExample(),
),
home: Scaffold(appBar: AppBar(title: const Text('Card Sample')), body: const CardExample()),
);
}
}
@@ -39,11 +36,7 @@ class CardExample extends StatelessWidget {
onTap: () {
debugPrint('Card tapped.');
},
child: const SizedBox(
width: 300,
height: 100,
child: Text('A card that can be tapped'),
),
child: const SizedBox(width: 300, height: 100, child: Text('A card that can be tapped')),
),
),
);

View File

@@ -39,10 +39,6 @@ class _SampleCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SizedBox(
width: 300,
height: 100,
child: Center(child: Text(cardName)),
);
return SizedBox(width: 300, height: 100, child: Center(child: Text(cardName)));
}
}

View File

@@ -60,9 +60,10 @@ class _CarouselExampleState extends State<CarouselExample> {
controller: controller,
itemSnapping: true,
flexWeights: const <int>[1, 7, 1],
children: ImageInfo.values.map((ImageInfo image) {
return HeroLayoutCard(imageInfo: image);
}).toList(),
children:
ImageInfo.values.map((ImageInfo image) {
return HeroLayoutCard(imageInfo: image);
}).toList(),
),
),
const SizedBox(height: 20),
@@ -89,20 +90,26 @@ class _CarouselExampleState extends State<CarouselExample> {
child: CarouselView.weighted(
flexWeights: const <int>[3, 3, 3, 2, 1],
consumeMaxWeight: false,
children: CardInfo.values.map((CardInfo info) {
return ColoredBox(
color: info.backgroundColor,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(info.icon, color: info.color, size: 32.0),
Text(info.label, style: const TextStyle(fontWeight: FontWeight.bold), overflow: TextOverflow.clip, softWrap: false),
],
),
),
);
}).toList()
children:
CardInfo.values.map((CardInfo info) {
return ColoredBox(
color: info.backgroundColor,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(info.icon, color: info.color, size: 32.0),
Text(
info.label,
style: const TextStyle(fontWeight: FontWeight.bold),
overflow: TextOverflow.clip,
softWrap: false,
),
],
),
),
);
}).toList(),
),
),
const SizedBox(height: 20),
@@ -115,21 +122,18 @@ class _CarouselExampleState extends State<CarouselExample> {
child: CarouselView(
itemExtent: 330,
shrinkExtent: 200,
children: List<Widget>.generate(20, (int index){
children: List<Widget>.generate(20, (int index) {
return UncontainedLayoutCard(index: index, label: 'Show $index');
}),
),
)
),
],
);
}
}
class HeroLayoutCard extends StatelessWidget {
const HeroLayoutCard({
super.key,
required this.imageInfo,
});
const HeroLayoutCard({super.key, required this.imageInfo});
final ImageInfo imageInfo;
@@ -146,7 +150,7 @@ class HeroLayoutCard extends StatelessWidget {
child: Image(
fit: BoxFit.cover,
image: NetworkImage(
'https://flutter.github.io/assets-for-api-docs/assets/material/${imageInfo.url}'
'https://flutter.github.io/assets-for-api-docs/assets/material/${imageInfo.url}',
),
),
),
@@ -169,21 +173,17 @@ class HeroLayoutCard extends StatelessWidget {
overflow: TextOverflow.clip,
softWrap: false,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(color: Colors.white),
)
),
],
),
),
]
],
);
}
}
class UncontainedLayoutCard extends StatelessWidget {
const UncontainedLayoutCard({
super.key,
required this.index,
required this.label,
});
const UncontainedLayoutCard({super.key, required this.index, required this.label});
final int index;
final String label;
@@ -223,7 +223,11 @@ enum CardInfo {
enum ImageInfo {
image0('The Flow', 'Sponsored | Season 1 Now Streaming', 'content_based_color_scheme_1.png'),
image1('Through the Pane', 'Sponsored | Season 1 Now Streaming', 'content_based_color_scheme_2.png'),
image1(
'Through the Pane',
'Sponsored | Season 1 Now Streaming',
'content_based_color_scheme_2.png',
),
image2('Iridescence', 'Sponsored | Season 1 Now Streaming', 'content_based_color_scheme_3.png'),
image3('Sea Change', 'Sponsored | Season 1 Now Streaming', 'content_based_color_scheme_4.png'),
image4('Blue Symphony', 'Sponsored | Season 1 Now Streaming', 'content_based_color_scheme_5.png'),

View File

@@ -16,9 +16,7 @@ class CheckboxExampleApp extends StatelessWidget {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Checkbox Sample')),
body: const Center(
child: CheckboxExample(),
),
body: const Center(child: CheckboxExample()),
),
);
}

View File

@@ -18,9 +18,7 @@ class CheckboxExampleApp extends StatelessWidget {
title: 'Checkbox Sample',
home: Scaffold(
appBar: AppBar(title: const Text('Checkbox Sample')),
body: const Center(
child: CheckboxExample(),
),
body: const Center(child: CheckboxExample()),
),
);
}
@@ -60,12 +58,7 @@ class _CheckboxExampleState extends State<CheckboxExample> {
});
},
),
Checkbox(
isError: true,
tristate: true,
value: isChecked,
onChanged: null,
),
Checkbox(isError: true, tristate: true, value: isChecked, onChanged: null),
],
);
}

View File

@@ -14,10 +14,7 @@ class CheckboxListTileApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: const CheckboxListTileExample(),
);
return MaterialApp(theme: ThemeData(useMaterial3: true), home: const CheckboxListTileExample());
}
}

View File

@@ -13,10 +13,7 @@ class CheckboxListTileApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: const CheckboxListTileExample(),
);
return MaterialApp(theme: ThemeData(useMaterial3: true), home: const CheckboxListTileExample());
}
}
@@ -58,7 +55,8 @@ class _CheckboxListTileExampleState extends State<CheckboxListTileExample> {
},
title: const Text('Headline'),
subtitle: const Text(
'Longer supporting text to demonstrate how the text wraps and the checkbox is centered vertically with the text.'),
'Longer supporting text to demonstrate how the text wraps and the checkbox is centered vertically with the text.',
),
),
const Divider(height: 0),
CheckboxListTile(
@@ -70,7 +68,8 @@ class _CheckboxListTileExampleState extends State<CheckboxListTileExample> {
},
title: const Text('Headline'),
subtitle: const Text(
"Longer supporting text to demonstrate how the text wraps and how setting 'CheckboxListTile.isThreeLine = true' aligns the checkbox to the top vertically with the text."),
"Longer supporting text to demonstrate how the text wraps and how setting 'CheckboxListTile.isThreeLine = true' aligns the checkbox to the top vertically with the text.",
),
isThreeLine: true,
),
const Divider(height: 0),

View File

@@ -15,10 +15,7 @@ class LabeledCheckboxApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: const LabeledCheckboxExample(),
);
return MaterialApp(theme: ThemeData(useMaterial3: true), home: const LabeledCheckboxExample());
}
}
@@ -50,10 +47,11 @@ class LinkedLabelCheckbox extends StatelessWidget {
color: Colors.blueAccent,
decoration: TextDecoration.underline,
),
recognizer: TapGestureRecognizer()
..onTap = () {
debugPrint('Label has been tapped.');
},
recognizer:
TapGestureRecognizer()
..onTap = () {
debugPrint('Label has been tapped.');
},
),
),
),

View File

@@ -13,10 +13,7 @@ class LabeledCheckboxApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: const LabeledCheckboxExample(),
);
return MaterialApp(theme: ThemeData(useMaterial3: true), home: const LabeledCheckboxExample());
}
}

View File

@@ -13,13 +13,7 @@ class AvatarBoxConstraintsApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: Center(
child: AvatarBoxConstraintsExample(),
),
),
);
return const MaterialApp(home: Scaffold(body: Center(child: AvatarBoxConstraintsExample())));
}
}
@@ -36,11 +30,7 @@ class AvatarBoxConstraintsExample extends StatelessWidget {
avatar: Icon(Icons.star),
label: SizedBox(
width: 150,
child: Text(
'One line text.',
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
child: Text('One line text.', maxLines: 3, overflow: TextOverflow.ellipsis),
),
),
SizedBox(height: 10),

View File

@@ -13,13 +13,7 @@ class ChipAnimationStyleExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: Center(
child: ChipAnimationStyleExample(),
),
),
);
return const MaterialApp(home: Scaffold(body: Center(child: ChipAnimationStyleExample())));
}
}
@@ -27,8 +21,7 @@ class ChipAnimationStyleExample extends StatefulWidget {
const ChipAnimationStyleExample({super.key});
@override
State<ChipAnimationStyleExample> createState() =>
_ChipAnimationStyleExampleState();
State<ChipAnimationStyleExample> createState() => _ChipAnimationStyleExampleState();
}
class _ChipAnimationStyleExampleState extends State<ChipAnimationStyleExample> {
@@ -125,8 +118,7 @@ class _ChipAnimationStyleExampleState extends State<ChipAnimationStyleExample> {
showCheckmark = !showCheckmark;
});
},
child:
Text(showCheckmark ? 'Hide checkmark' : 'Show checkmark'),
child: Text(showCheckmark ? 'Hide checkmark' : 'Show checkmark'),
),
],
),
@@ -151,8 +143,7 @@ class _ChipAnimationStyleExampleState extends State<ChipAnimationStyleExample> {
showDeleteIcon = !showDeleteIcon;
});
},
child: Text(
showDeleteIcon ? 'Hide delete icon' : 'Show delete icon'),
child: Text(showDeleteIcon ? 'Hide delete icon' : 'Show delete icon'),
),
],
),

View File

@@ -14,11 +14,7 @@ class DeleteIconBoxConstraintsApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: Center(
child: DeleteIconBoxConstraintsExample(),
),
),
home: Scaffold(body: Center(child: DeleteIconBoxConstraintsExample())),
);
}
}
@@ -36,11 +32,7 @@ class DeleteIconBoxConstraintsExample extends StatelessWidget {
onDeleted: () {},
label: const SizedBox(
width: 150,
child: Text(
'One line text.',
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
child: Text('One line text.', maxLines: 3, overflow: TextOverflow.ellipsis),
),
),
const SizedBox(height: 10),

View File

@@ -16,9 +16,7 @@ class OnDeletedExampleApp extends StatelessWidget {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('DeletableChipAttributes.onDeleted Sample')),
body: const Center(
child: OnDeletedExample(),
),
body: const Center(child: OnDeletedExample()),
),
);
}
@@ -66,9 +64,7 @@ class CastListState extends State<CastList> {
@override
Widget build(BuildContext context) {
return Wrap(
children: actorWidgets.toList(),
);
return Wrap(children: actorWidgets.toList());
}
}

View File

@@ -35,9 +35,7 @@ class _ActionChoiceExampleState extends State<ActionChoiceExample> {
final TextTheme textTheme = Theme.of(context).textTheme;
return Scaffold(
appBar: AppBar(
title: const Text('ActionChoice Sample'),
),
appBar: AppBar(title: const Text('ActionChoice Sample')),
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -47,20 +45,18 @@ class _ActionChoiceExampleState extends State<ActionChoiceExample> {
const SizedBox(height: 10.0),
Wrap(
spacing: 5.0,
children: List<Widget>.generate(
3,
(int index) {
return ChoiceChip(
label: Text('Item $index'),
selected: _value == index,
onSelected: (bool selected) {
setState(() {
_value = selected ? index : null;
});
},
);
},
).toList(),
children:
List<Widget>.generate(3, (int index) {
return ChoiceChip(
label: Text('Item $index'),
selected: _value == index,
onSelected: (bool selected) {
setState(() {
_value = selected ? index : null;
});
},
);
}).toList(),
),
],
),

View File

@@ -63,14 +63,15 @@ class _ColorSchemeExampleState extends State<ColorSchemeExample> {
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: List<Widget>.generate(schemeVariants.length, (int index) {
return ColorSchemeVariantColumn(
selectedColor: selectedColor,
brightness: selectedBrightness,
schemeVariant: schemeVariants[index],
contrastLevel: selectedContrast,
);
}).toList(),
children:
List<Widget>.generate(schemeVariants.length, (int index) {
return ColorSchemeVariantColumn(
selectedColor: selectedColor,
brightness: selectedBrightness,
schemeVariant: schemeVariants[index],
contrastLevel: selectedContrast,
);
}).toList(),
),
),
],
@@ -110,11 +111,12 @@ class _SettingsState extends State<Settings> {
Widget build(BuildContext context) {
return Theme(
data: Theme.of(context).copyWith(
colorScheme: ColorScheme.fromSeed(
seedColor: selectedColor,
contrastLevel: selectedContrast,
brightness: selectedBrightness,
)),
colorScheme: ColorScheme.fromSeed(
seedColor: selectedColor,
contrastLevel: selectedContrast,
brightness: selectedBrightness,
),
),
child: ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 200),
child: Padding(
@@ -133,19 +135,20 @@ class _SettingsState extends State<Settings> {
});
widget.updateTheme(selectedBrightness, selectedColor, selectedContrast);
},
)
),
],
),
Wrap(crossAxisAlignment: WrapCrossAlignment.center, children: <Widget>[
const Text('Seed color: '),
...List<Widget>.generate(
ColorSeed.values.length,
(int index) {
Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
children: <Widget>[
const Text('Seed color: '),
...List<Widget>.generate(ColorSeed.values.length, (int index) {
final Color itemColor = ColorSeed.values[index].color;
return IconButton(
icon: selectedColor == ColorSeed.values[index].color
? Icon(Icons.circle, color: itemColor)
: Icon(Icons.circle_outlined, color: itemColor),
icon:
selectedColor == ColorSeed.values[index].color
? Icon(Icons.circle, color: itemColor)
: Icon(Icons.circle_outlined, color: itemColor),
onPressed: () {
setState(() {
selectedColor = itemColor;
@@ -153,9 +156,9 @@ class _SettingsState extends State<Settings> {
widget.updateTheme(selectedBrightness, selectedColor, selectedContrast);
},
);
},
),
]),
}),
],
),
Row(
children: <Widget>[
const Text('Contrast level: '),
@@ -206,7 +209,9 @@ class ColorSchemeVariantColumn extends StatelessWidget {
Padding(
padding: const EdgeInsets.symmetric(vertical: 15),
child: Text(
schemeVariant.name == 'tonalSpot' ? '${schemeVariant.name} (Default)' : schemeVariant.name,
schemeVariant.name == 'tonalSpot'
? '${schemeVariant.name} (Default)'
: schemeVariant.name,
style: const TextStyle(fontWeight: FontWeight.bold),
),
),
@@ -236,57 +241,73 @@ class ColorSchemeView extends StatelessWidget {
Widget build(BuildContext context) {
return Column(
children: <Widget>[
ColorGroup(children: <ColorChip>[
ColorChip('primary', colorScheme.primary, colorScheme.onPrimary),
ColorChip('onPrimary', colorScheme.onPrimary, colorScheme.primary),
ColorChip('primaryContainer', colorScheme.primaryContainer, colorScheme.onPrimaryContainer),
ColorChip(
'onPrimaryContainer',
colorScheme.onPrimaryContainer,
colorScheme.primaryContainer,
),
]),
ColorGroup(
children: <ColorChip>[
ColorChip('primary', colorScheme.primary, colorScheme.onPrimary),
ColorChip('onPrimary', colorScheme.onPrimary, colorScheme.primary),
ColorChip(
'primaryContainer',
colorScheme.primaryContainer,
colorScheme.onPrimaryContainer,
),
ColorChip(
'onPrimaryContainer',
colorScheme.onPrimaryContainer,
colorScheme.primaryContainer,
),
],
),
divider,
ColorGroup(children: <ColorChip>[
ColorChip('primaryFixed', colorScheme.primaryFixed, colorScheme.onPrimaryFixed),
ColorChip('onPrimaryFixed', colorScheme.onPrimaryFixed, colorScheme.primaryFixed),
ColorChip('primaryFixedDim', colorScheme.primaryFixedDim, colorScheme.onPrimaryFixedVariant),
ColorChip(
'onPrimaryFixedVariant',
colorScheme.onPrimaryFixedVariant,
colorScheme.primaryFixedDim,
),
]),
ColorGroup(
children: <ColorChip>[
ColorChip('primaryFixed', colorScheme.primaryFixed, colorScheme.onPrimaryFixed),
ColorChip('onPrimaryFixed', colorScheme.onPrimaryFixed, colorScheme.primaryFixed),
ColorChip(
'primaryFixedDim',
colorScheme.primaryFixedDim,
colorScheme.onPrimaryFixedVariant,
),
ColorChip(
'onPrimaryFixedVariant',
colorScheme.onPrimaryFixedVariant,
colorScheme.primaryFixedDim,
),
],
),
divider,
ColorGroup(children: <ColorChip>[
ColorChip('secondary', colorScheme.secondary, colorScheme.onSecondary),
ColorChip('onSecondary', colorScheme.onSecondary, colorScheme.secondary),
ColorChip(
'secondaryContainer',
colorScheme.secondaryContainer,
colorScheme.onSecondaryContainer,
),
ColorChip(
'onSecondaryContainer',
colorScheme.onSecondaryContainer,
colorScheme.secondaryContainer,
),
]),
ColorGroup(
children: <ColorChip>[
ColorChip('secondary', colorScheme.secondary, colorScheme.onSecondary),
ColorChip('onSecondary', colorScheme.onSecondary, colorScheme.secondary),
ColorChip(
'secondaryContainer',
colorScheme.secondaryContainer,
colorScheme.onSecondaryContainer,
),
ColorChip(
'onSecondaryContainer',
colorScheme.onSecondaryContainer,
colorScheme.secondaryContainer,
),
],
),
divider,
ColorGroup(children: <ColorChip>[
ColorChip('secondaryFixed', colorScheme.secondaryFixed, colorScheme.onSecondaryFixed),
ColorChip('onSecondaryFixed', colorScheme.onSecondaryFixed, colorScheme.secondaryFixed),
ColorChip(
'secondaryFixedDim',
colorScheme.secondaryFixedDim,
colorScheme.onSecondaryFixedVariant,
),
ColorChip(
'onSecondaryFixedVariant',
colorScheme.onSecondaryFixedVariant,
colorScheme.secondaryFixedDim,
),
]),
ColorGroup(
children: <ColorChip>[
ColorChip('secondaryFixed', colorScheme.secondaryFixed, colorScheme.onSecondaryFixed),
ColorChip('onSecondaryFixed', colorScheme.onSecondaryFixed, colorScheme.secondaryFixed),
ColorChip(
'secondaryFixedDim',
colorScheme.secondaryFixedDim,
colorScheme.onSecondaryFixedVariant,
),
ColorChip(
'onSecondaryFixedVariant',
colorScheme.onSecondaryFixedVariant,
colorScheme.secondaryFixedDim,
),
],
),
divider,
ColorGroup(
children: <ColorChip>[
@@ -305,16 +326,22 @@ class ColorSchemeView extends StatelessWidget {
],
),
divider,
ColorGroup(children: <ColorChip>[
ColorChip('tertiaryFixed', colorScheme.tertiaryFixed, colorScheme.onTertiaryFixed),
ColorChip('onTertiaryFixed', colorScheme.onTertiaryFixed, colorScheme.tertiaryFixed),
ColorChip('tertiaryFixedDim', colorScheme.tertiaryFixedDim, colorScheme.onTertiaryFixedVariant),
ColorChip(
'onTertiaryFixedVariant',
colorScheme.onTertiaryFixedVariant,
colorScheme.tertiaryFixedDim,
),
]),
ColorGroup(
children: <ColorChip>[
ColorChip('tertiaryFixed', colorScheme.tertiaryFixed, colorScheme.onTertiaryFixed),
ColorChip('onTertiaryFixed', colorScheme.onTertiaryFixed, colorScheme.tertiaryFixed),
ColorChip(
'tertiaryFixedDim',
colorScheme.tertiaryFixedDim,
colorScheme.onTertiaryFixedVariant,
),
ColorChip(
'onTertiaryFixedVariant',
colorScheme.onTertiaryFixedVariant,
colorScheme.tertiaryFixedDim,
),
],
),
divider,
ColorGroup(
children: <ColorChip>[
@@ -330,11 +357,27 @@ class ColorSchemeView extends StatelessWidget {
ColorChip('surfaceDim', colorScheme.surfaceDim, colorScheme.onSurface),
ColorChip('surface', colorScheme.surface, colorScheme.onSurface),
ColorChip('surfaceBright', colorScheme.surfaceBright, colorScheme.onSurface),
ColorChip('surfaceContainerLowest', colorScheme.surfaceContainerLowest, colorScheme.onSurface),
ColorChip('surfaceContainerLow', colorScheme.surfaceContainerLow, colorScheme.onSurface),
ColorChip(
'surfaceContainerLowest',
colorScheme.surfaceContainerLowest,
colorScheme.onSurface,
),
ColorChip(
'surfaceContainerLow',
colorScheme.surfaceContainerLow,
colorScheme.onSurface,
),
ColorChip('surfaceContainer', colorScheme.surfaceContainer, colorScheme.onSurface),
ColorChip('surfaceContainerHigh', colorScheme.surfaceContainerHigh, colorScheme.onSurface),
ColorChip('surfaceContainerHighest', colorScheme.surfaceContainerHighest, colorScheme.onSurface),
ColorChip(
'surfaceContainerHigh',
colorScheme.surfaceContainerHigh,
colorScheme.onSurface,
),
ColorChip(
'surfaceContainerHighest',
colorScheme.surfaceContainerHighest,
colorScheme.onSurface,
),
ColorChip('onSurface', colorScheme.onSurface, colorScheme.surface),
ColorChip(
'onSurfaceVariant',
@@ -391,9 +434,7 @@ class ColorChip extends StatelessWidget {
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: <Expanded>[
Expanded(child: Text(label, style: TextStyle(color: labelColor))),
],
children: <Expanded>[Expanded(child: Text(label, style: TextStyle(color: labelColor)))],
),
),
);
@@ -444,10 +485,11 @@ class SettingsButton extends StatelessWidget {
context: context,
builder: (BuildContext context) {
return Settings(
selectedColor: selectedColor,
selectedBrightness: selectedBrightness,
selectedContrast: selectedContrast,
updateTheme: updateTheme);
selectedColor: selectedColor,
selectedBrightness: selectedBrightness,
selectedContrast: selectedContrast,
updateTheme: updateTheme,
);
},
);
},

View File

@@ -12,30 +12,31 @@ const double narrowScreenWidthThreshold = 400;
void main() => runApp(const DynamicColorExample());
class DynamicColorExample extends StatefulWidget {
const DynamicColorExample({
this.loadColorScheme,
super.key,
});
const DynamicColorExample({this.loadColorScheme, super.key});
static const List<ImageProvider> images = <NetworkImage>[
NetworkImage(
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_1.png'),
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_1.png',
),
NetworkImage(
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_2.png'),
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_2.png',
),
NetworkImage(
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_3.png'),
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_3.png',
),
NetworkImage(
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_4.png'),
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_4.png',
),
NetworkImage(
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_5.png'),
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_5.png',
),
NetworkImage(
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_6.png'),
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_6.png',
),
];
final Future<ColorScheme> Function(
ImageProvider<Object> provider,
Brightness brightness,
)? loadColorScheme;
final Future<ColorScheme> Function(ImageProvider<Object> provider, Brightness brightness)?
loadColorScheme;
@override
State<DynamicColorExample> createState() => _DynamicColorExampleState();
@@ -98,97 +99,104 @@ class _DynamicColorExampleState extends State<DynamicColorExample> {
theme: ThemeData(useMaterial3: true, colorScheme: colorScheme),
debugShowCheckedModeBanner: false,
home: Builder(
builder: (BuildContext context) => Scaffold(
appBar: AppBar(
title: const Text('Content Based Dynamic Color'),
backgroundColor: colorScheme.primary,
foregroundColor: colorScheme.onPrimary,
actions: <Widget>[
const Icon(Icons.light_mode),
Switch(
activeColor: colorScheme.primary,
activeTrackColor: colorScheme.surface,
inactiveTrackColor: colorScheme.onSecondary,
value: isLight,
onChanged: (bool value) {
setState(() {
isLight = value;
_updateImage(DynamicColorExample.images[selectedImage]);
});
})
],
),
body: Center(
child: isLoading
? const CircularProgressIndicator()
: ColoredBox(
color: colorScheme.secondaryContainer,
child: Column(
children: <Widget>[
divider,
_imagesRow(
context,
DynamicColorExample.images,
colorScheme,
),
divider,
Expanded(
child: ColoredBox(
color: colorScheme.surface,
child: LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) {
if (constraints.maxWidth < narrowScreenWidthThreshold) {
return SingleChildScrollView(
child: Column(
children: <Widget>[
divider,
schemeLabel('Light ColorScheme', colorScheme),
schemeView(lightTheme),
divider,
divider,
schemeLabel('Dark ColorScheme', colorScheme),
schemeView(darkTheme),
],
),
);
} else {
return SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.only(top: 5),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: Column(
children: <Widget>[
schemeLabel('Light ColorScheme', colorScheme),
schemeView(lightTheme),
],
),
builder:
(BuildContext context) => Scaffold(
appBar: AppBar(
title: const Text('Content Based Dynamic Color'),
backgroundColor: colorScheme.primary,
foregroundColor: colorScheme.onPrimary,
actions: <Widget>[
const Icon(Icons.light_mode),
Switch(
activeColor: colorScheme.primary,
activeTrackColor: colorScheme.surface,
inactiveTrackColor: colorScheme.onSecondary,
value: isLight,
onChanged: (bool value) {
setState(() {
isLight = value;
_updateImage(DynamicColorExample.images[selectedImage]);
});
},
),
],
),
body: Center(
child:
isLoading
? const CircularProgressIndicator()
: ColoredBox(
color: colorScheme.secondaryContainer,
child: Column(
children: <Widget>[
divider,
_imagesRow(context, DynamicColorExample.images, colorScheme),
divider,
Expanded(
child: ColoredBox(
color: colorScheme.surface,
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
if (constraints.maxWidth < narrowScreenWidthThreshold) {
return SingleChildScrollView(
child: Column(
children: <Widget>[
divider,
schemeLabel('Light ColorScheme', colorScheme),
schemeView(lightTheme),
divider,
divider,
schemeLabel('Dark ColorScheme', colorScheme),
schemeView(darkTheme),
],
),
);
} else {
return SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.only(top: 5),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: Column(
children: <Widget>[
schemeLabel(
'Light ColorScheme',
colorScheme,
),
schemeView(lightTheme),
],
),
),
Expanded(
child: Column(
children: <Widget>[
schemeLabel(
'Dark ColorScheme',
colorScheme,
),
schemeView(darkTheme),
],
),
),
],
),
],
),
Expanded(
child: Column(
children: <Widget>[
schemeLabel('Dark ColorScheme', colorScheme),
schemeView(darkTheme),
],
),
),
],
),
],
),
),
);
}
},
),
);
}
}),
),
),
],
),
),
],
),
),
),
),
),
),
),
);
}
@@ -222,47 +230,57 @@ class _DynamicColorExampleState extends State<DynamicColorExample> {
final double windowWidth = MediaQuery.of(context).size.width;
return Padding(
padding: const EdgeInsets.all(8.0),
child: LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) {
if (constraints.maxWidth > 800) {
return _adaptiveLayoutImagesRow(images, colorScheme, windowHeight);
} else {
return Column(children: <Widget>[
_adaptiveLayoutImagesRow(images.sublist(0, 3), colorScheme, windowWidth),
_adaptiveLayoutImagesRow(images.sublist(3), colorScheme, windowWidth),
]);
}
}),
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
if (constraints.maxWidth > 800) {
return _adaptiveLayoutImagesRow(images, colorScheme, windowHeight);
} else {
return Column(
children: <Widget>[
_adaptiveLayoutImagesRow(images.sublist(0, 3), colorScheme, windowWidth),
_adaptiveLayoutImagesRow(images.sublist(3), colorScheme, windowWidth),
],
);
}
},
),
);
}
Widget _adaptiveLayoutImagesRow(List<ImageProvider> images, ColorScheme colorScheme, double windowWidth) {
Widget _adaptiveLayoutImagesRow(
List<ImageProvider> images,
ColorScheme colorScheme,
double windowWidth,
) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: images
.map(
(ImageProvider image) => Flexible(
flex: (images.length / 3).floor(),
child: GestureDetector(
onTap: () => _updateImage(image),
child: Card(
color: DynamicColorExample.images.indexOf(image) == selectedImage
? colorScheme.primaryContainer
: colorScheme.surface,
child: Padding(
padding: const EdgeInsets.all(5.0),
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: windowWidth * .25),
child: ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Image(image: image),
children:
images
.map(
(ImageProvider image) => Flexible(
flex: (images.length / 3).floor(),
child: GestureDetector(
onTap: () => _updateImage(image),
child: Card(
color:
DynamicColorExample.images.indexOf(image) == selectedImage
? colorScheme.primaryContainer
: colorScheme.surface,
child: Padding(
padding: const EdgeInsets.all(5.0),
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: windowWidth * .25),
child: ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Image(image: image),
),
),
),
),
),
),
),
),
)
.toList(),
)
.toList(),
);
}
}
@@ -276,42 +294,74 @@ class ColorSchemeView extends StatelessWidget {
Widget build(BuildContext context) {
return Column(
children: <Widget>[
ColorGroup(children: <ColorChip>[
ColorChip(label: 'primary', color: colorScheme.primary, onColor: colorScheme.onPrimary),
ColorChip(label: 'onPrimary', color: colorScheme.onPrimary, onColor: colorScheme.primary),
ColorChip(
label: 'primaryContainer', color: colorScheme.primaryContainer, onColor: colorScheme.onPrimaryContainer),
ColorChip(
ColorGroup(
children: <ColorChip>[
ColorChip(label: 'primary', color: colorScheme.primary, onColor: colorScheme.onPrimary),
ColorChip(
label: 'onPrimary',
color: colorScheme.onPrimary,
onColor: colorScheme.primary,
),
ColorChip(
label: 'primaryContainer',
color: colorScheme.primaryContainer,
onColor: colorScheme.onPrimaryContainer,
),
ColorChip(
label: 'onPrimaryContainer',
color: colorScheme.onPrimaryContainer,
onColor: colorScheme.primaryContainer),
]),
divider,
ColorGroup(children: <ColorChip>[
ColorChip(label: 'secondary', color: colorScheme.secondary, onColor: colorScheme.onSecondary),
ColorChip(label: 'onSecondary', color: colorScheme.onSecondary, onColor: colorScheme.secondary),
ColorChip(
label: 'secondaryContainer',
color: colorScheme.secondaryContainer,
onColor: colorScheme.onSecondaryContainer),
ColorChip(
label: 'onSecondaryContainer',
color: colorScheme.onSecondaryContainer,
onColor: colorScheme.secondaryContainer),
]),
onColor: colorScheme.primaryContainer,
),
],
),
divider,
ColorGroup(
children: <ColorChip>[
ColorChip(label: 'tertiary', color: colorScheme.tertiary, onColor: colorScheme.onTertiary),
ColorChip(label: 'onTertiary', color: colorScheme.onTertiary, onColor: colorScheme.tertiary),
ColorChip(
label: 'tertiaryContainer',
color: colorScheme.tertiaryContainer,
onColor: colorScheme.onTertiaryContainer),
label: 'secondary',
color: colorScheme.secondary,
onColor: colorScheme.onSecondary,
),
ColorChip(
label: 'onTertiaryContainer',
color: colorScheme.onTertiaryContainer,
onColor: colorScheme.tertiaryContainer),
label: 'onSecondary',
color: colorScheme.onSecondary,
onColor: colorScheme.secondary,
),
ColorChip(
label: 'secondaryContainer',
color: colorScheme.secondaryContainer,
onColor: colorScheme.onSecondaryContainer,
),
ColorChip(
label: 'onSecondaryContainer',
color: colorScheme.onSecondaryContainer,
onColor: colorScheme.secondaryContainer,
),
],
),
divider,
ColorGroup(
children: <ColorChip>[
ColorChip(
label: 'tertiary',
color: colorScheme.tertiary,
onColor: colorScheme.onTertiary,
),
ColorChip(
label: 'onTertiary',
color: colorScheme.onTertiary,
onColor: colorScheme.tertiary,
),
ColorChip(
label: 'tertiaryContainer',
color: colorScheme.tertiaryContainer,
onColor: colorScheme.onTertiaryContainer,
),
ColorChip(
label: 'onTertiaryContainer',
color: colorScheme.onTertiaryContainer,
onColor: colorScheme.tertiaryContainer,
),
],
),
divider,
@@ -320,18 +370,31 @@ class ColorSchemeView extends StatelessWidget {
ColorChip(label: 'error', color: colorScheme.error, onColor: colorScheme.onError),
ColorChip(label: 'onError', color: colorScheme.onError, onColor: colorScheme.error),
ColorChip(
label: 'errorContainer', color: colorScheme.errorContainer, onColor: colorScheme.onErrorContainer),
label: 'errorContainer',
color: colorScheme.errorContainer,
onColor: colorScheme.onErrorContainer,
),
ColorChip(
label: 'onErrorContainer', color: colorScheme.onErrorContainer, onColor: colorScheme.errorContainer),
label: 'onErrorContainer',
color: colorScheme.onErrorContainer,
onColor: colorScheme.errorContainer,
),
],
),
divider,
ColorGroup(
children: <ColorChip>[
ColorChip(label: 'surface', color: colorScheme.surface, onColor: colorScheme.onSurface),
ColorChip(label: 'onSurface', color: colorScheme.onSurface, onColor: colorScheme.surface),
ColorChip(
label: 'onSurfaceVariant', color: colorScheme.onSurfaceVariant, onColor: colorScheme.surfaceContainerHighest),
label: 'onSurface',
color: colorScheme.onSurface,
onColor: colorScheme.surface,
),
ColorChip(
label: 'onSurfaceVariant',
color: colorScheme.onSurfaceVariant,
onColor: colorScheme.surfaceContainerHighest,
),
],
),
divider,
@@ -340,10 +403,20 @@ class ColorSchemeView extends StatelessWidget {
ColorChip(label: 'outline', color: colorScheme.outline),
ColorChip(label: 'shadow', color: colorScheme.shadow),
ColorChip(
label: 'inverseSurface', color: colorScheme.inverseSurface, onColor: colorScheme.onInverseSurface),
label: 'inverseSurface',
color: colorScheme.inverseSurface,
onColor: colorScheme.onInverseSurface,
),
ColorChip(
label: 'onInverseSurface', color: colorScheme.onInverseSurface, onColor: colorScheme.inverseSurface),
ColorChip(label: 'inversePrimary', color: colorScheme.inversePrimary, onColor: colorScheme.primary),
label: 'onInverseSurface',
color: colorScheme.onInverseSurface,
onColor: colorScheme.inverseSurface,
),
ColorChip(
label: 'inversePrimary',
color: colorScheme.inversePrimary,
onColor: colorScheme.primary,
),
],
),
],
@@ -365,12 +438,7 @@ class ColorGroup extends StatelessWidget {
}
class ColorChip extends StatelessWidget {
const ColorChip({
super.key,
required this.color,
required this.label,
this.onColor,
});
const ColorChip({super.key, required this.color, required this.label, this.onColor});
final Color color;
final Color? onColor;
@@ -379,7 +447,7 @@ class ColorChip extends StatelessWidget {
static Color contrastColor(Color color) {
final Brightness brightness = ThemeData.estimateBrightnessForColor(color);
return switch (brightness) {
Brightness.dark => Colors.white,
Brightness.dark => Colors.white,
Brightness.light => Colors.black,
};
}
@@ -392,9 +460,7 @@ class ColorChip extends StatelessWidget {
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: <Expanded>[
Expanded(child: Text(label, style: TextStyle(color: labelColor))),
],
children: <Expanded>[Expanded(child: Text(label, style: TextStyle(color: labelColor)))],
),
),
);

View File

@@ -53,17 +53,13 @@ class _ContextMenuControllerExampleAppState extends State<ContextMenuControllerE
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Context menu outside of text'),
),
appBar: AppBar(title: const Text('Context menu outside of text')),
body: _ContextMenuRegion(
contextMenuBuilder: (BuildContext context, Offset offset) {
// The custom context menu will look like the default context menu
// on the current platform with a single 'Print' button.
return AdaptiveTextSelectionToolbar.buttonItems(
anchors: TextSelectionToolbarAnchors(
primaryAnchor: offset,
),
anchors: TextSelectionToolbarAnchors(primaryAnchor: offset),
buttonItems: <ContextMenuButtonItem>[
ContextMenuButtonItem(
onPressed: () {
@@ -82,7 +78,8 @@ class _ContextMenuControllerExampleAppState extends State<ContextMenuControllerE
children: <Widget>[
Container(height: 20.0),
const Text(
'Right click (desktop) or long press (mobile) anywhere, not just on this text, to show the custom menu.'),
'Right click (desktop) or long press (mobile) anywhere, not just on this text, to show the custom menu.',
),
],
),
),
@@ -96,10 +93,7 @@ class _ContextMenuControllerExampleAppState extends State<ContextMenuControllerE
/// By default, shows the menu on right clicks and long presses.
class _ContextMenuRegion extends StatefulWidget {
/// Creates an instance of [_ContextMenuRegion].
const _ContextMenuRegion({
required this.child,
required this.contextMenuBuilder,
});
const _ContextMenuRegion({required this.child, required this.contextMenuBuilder});
/// Builds the context menu.
final ContextMenuBuilder contextMenuBuilder;

View File

@@ -16,10 +16,12 @@ class EditableTextToolbarBuilderExampleApp extends StatefulWidget {
const EditableTextToolbarBuilderExampleApp({super.key});
@override
State<EditableTextToolbarBuilderExampleApp> createState() => _EditableTextToolbarBuilderExampleAppState();
State<EditableTextToolbarBuilderExampleApp> createState() =>
_EditableTextToolbarBuilderExampleAppState();
}
class _EditableTextToolbarBuilderExampleAppState extends State<EditableTextToolbarBuilderExampleApp> {
class _EditableTextToolbarBuilderExampleAppState
extends State<EditableTextToolbarBuilderExampleApp> {
final TextEditingController _controller = TextEditingController(
text: 'Right click (desktop) or long press (mobile) to see the menu with custom buttons.',
);
@@ -46,9 +48,7 @@ class _EditableTextToolbarBuilderExampleAppState extends State<EditableTextToolb
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Custom button appearance'),
),
appBar: AppBar(title: const Text('Custom button appearance')),
body: Center(
child: Column(
children: <Widget>[
@@ -61,21 +61,27 @@ class _EditableTextToolbarBuilderExampleAppState extends State<EditableTextToolb
// Build the default buttons, but make them look custom.
// In a real project you may want to build different
// buttons depending on the platform.
children: editableTextState.contextMenuButtonItems.map((ContextMenuButtonItem buttonItem) {
return CupertinoButton(
color: const Color(0xffaaaa00),
disabledColor: const Color(0xffaaaaff),
onPressed: buttonItem.onPressed,
padding: const EdgeInsets.all(10.0),
pressedOpacity: 0.7,
child: SizedBox(
width: 200.0,
child: Text(
CupertinoTextSelectionToolbarButton.getButtonLabel(context, buttonItem),
),
),
);
}).toList(),
children:
editableTextState.contextMenuButtonItems.map((
ContextMenuButtonItem buttonItem,
) {
return CupertinoButton(
color: const Color(0xffaaaa00),
disabledColor: const Color(0xffaaaaff),
onPressed: buttonItem.onPressed,
padding: const EdgeInsets.all(10.0),
pressedOpacity: 0.7,
child: SizedBox(
width: 200.0,
child: Text(
CupertinoTextSelectionToolbarButton.getButtonLabel(
context,
buttonItem,
),
),
),
);
}).toList(),
);
},
),

View File

@@ -18,19 +18,20 @@ class EditableTextToolbarBuilderExampleApp extends StatefulWidget {
const EditableTextToolbarBuilderExampleApp({super.key});
@override
State<EditableTextToolbarBuilderExampleApp> createState() => _EditableTextToolbarBuilderExampleAppState();
State<EditableTextToolbarBuilderExampleApp> createState() =>
_EditableTextToolbarBuilderExampleAppState();
}
class _EditableTextToolbarBuilderExampleAppState extends State<EditableTextToolbarBuilderExampleApp> {
final TextEditingController _controller = TextEditingController(
text: text,
);
class _EditableTextToolbarBuilderExampleAppState
extends State<EditableTextToolbarBuilderExampleApp> {
final TextEditingController _controller = TextEditingController(text: text);
void _showDialog(BuildContext context) {
Navigator.of(context).push(
DialogRoute<void>(
context: context,
builder: (BuildContext context) => const AlertDialog(title: Text('You clicked send email!')),
builder:
(BuildContext context) => const AlertDialog(title: Text('You clicked send email!')),
),
);
}
@@ -57,9 +58,7 @@ class _EditableTextToolbarBuilderExampleAppState extends State<EditableTextToolb
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Custom button for emails'),
),
appBar: AppBar(title: const Text('Custom button for emails')),
body: Center(
child: Column(
children: <Widget>[
@@ -67,7 +66,8 @@ class _EditableTextToolbarBuilderExampleAppState extends State<EditableTextToolb
TextField(
controller: _controller,
contextMenuBuilder: (BuildContext context, EditableTextState editableTextState) {
final List<ContextMenuButtonItem> buttonItems = editableTextState.contextMenuButtonItems;
final List<ContextMenuButtonItem> buttonItems =
editableTextState.contextMenuButtonItems;
// Here we add an "Email" button to the default TextField
// context menu for the current platform, but only if an email
// address is currently selected.

View File

@@ -15,10 +15,12 @@ class EditableTextToolbarBuilderExampleApp extends StatefulWidget {
const EditableTextToolbarBuilderExampleApp({super.key});
@override
State<EditableTextToolbarBuilderExampleApp> createState() => _EditableTextToolbarBuilderExampleAppState();
State<EditableTextToolbarBuilderExampleApp> createState() =>
_EditableTextToolbarBuilderExampleAppState();
}
class _EditableTextToolbarBuilderExampleAppState extends State<EditableTextToolbarBuilderExampleApp> {
class _EditableTextToolbarBuilderExampleAppState
extends State<EditableTextToolbarBuilderExampleApp> {
final TextEditingController _controller = TextEditingController(
text: 'Right click (desktop) or long press (mobile) to see the menu with a custom toolbar.',
);
@@ -45,9 +47,7 @@ class _EditableTextToolbarBuilderExampleAppState extends State<EditableTextToolb
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Custom toolbar, default-looking buttons'),
),
appBar: AppBar(title: const Text('Custom toolbar, default-looking buttons')),
body: Center(
child: Column(
children: <Widget>[
@@ -59,32 +59,33 @@ class _EditableTextToolbarBuilderExampleAppState extends State<EditableTextToolb
anchor: editableTextState.contextMenuAnchors.primaryAnchor,
// getAdaptiveButtons creates the default button widgets for
// the current platform.
children: AdaptiveTextSelectionToolbar.getAdaptiveButtons(
context,
// These buttons just close the menu when clicked.
<ContextMenuButtonItem>[
ContextMenuButtonItem(
label: 'One',
onPressed: () => ContextMenuController.removeAny(),
),
ContextMenuButtonItem(
label: 'Two',
onPressed: () => ContextMenuController.removeAny(),
),
ContextMenuButtonItem(
label: 'Three',
onPressed: () => ContextMenuController.removeAny(),
),
ContextMenuButtonItem(
label: 'Four',
onPressed: () => ContextMenuController.removeAny(),
),
ContextMenuButtonItem(
label: 'Five',
onPressed: () => ContextMenuController.removeAny(),
),
],
).toList(),
children:
AdaptiveTextSelectionToolbar.getAdaptiveButtons(
context,
// These buttons just close the menu when clicked.
<ContextMenuButtonItem>[
ContextMenuButtonItem(
label: 'One',
onPressed: () => ContextMenuController.removeAny(),
),
ContextMenuButtonItem(
label: 'Two',
onPressed: () => ContextMenuController.removeAny(),
),
ContextMenuButtonItem(
label: 'Three',
onPressed: () => ContextMenuController.removeAny(),
),
ContextMenuButtonItem(
label: 'Four',
onPressed: () => ContextMenuController.removeAny(),
),
ContextMenuButtonItem(
label: 'Five',
onPressed: () => ContextMenuController.removeAny(),
),
],
).toList(),
);
},
),
@@ -100,10 +101,7 @@ class _EditableTextToolbarBuilderExampleAppState extends State<EditableTextToolb
///
/// Displays its children in a scrollable grid.
class _MyTextSelectionToolbar extends StatelessWidget {
const _MyTextSelectionToolbar({
required this.anchor,
required this.children,
});
const _MyTextSelectionToolbar({required this.anchor, required this.children});
final Offset anchor;
final List<Widget> children;

View File

@@ -18,10 +18,12 @@ class SelectableRegionToolbarBuilderExampleApp extends StatefulWidget {
const SelectableRegionToolbarBuilderExampleApp({super.key});
@override
State<SelectableRegionToolbarBuilderExampleApp> createState() => _SelectableRegionToolbarBuilderExampleAppState();
State<SelectableRegionToolbarBuilderExampleApp> createState() =>
_SelectableRegionToolbarBuilderExampleAppState();
}
class _SelectableRegionToolbarBuilderExampleAppState extends State<SelectableRegionToolbarBuilderExampleApp> {
class _SelectableRegionToolbarBuilderExampleAppState
extends State<SelectableRegionToolbarBuilderExampleApp> {
void _showDialog(BuildContext context) {
Navigator.of(context).push(
DialogRoute<void>(
@@ -53,9 +55,7 @@ class _SelectableRegionToolbarBuilderExampleAppState extends State<SelectableReg
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Context menu anywhere'),
),
appBar: AppBar(title: const Text('Context menu anywhere')),
body: Center(
child: SizedBox(
width: 200.0,
@@ -78,12 +78,7 @@ class _SelectableRegionToolbarBuilderExampleAppState extends State<SelectableReg
],
);
},
child: ListView(
children: const <Widget>[
SizedBox(height: 20.0),
Text(text),
],
),
child: ListView(children: const <Widget>[SizedBox(height: 20.0), Text(text)]),
),
),
),

View File

@@ -30,28 +30,13 @@ class DataTableExample extends StatelessWidget {
return DataTable(
columns: const <DataColumn>[
DataColumn(
label: Expanded(
child: Text(
'Name',
style: TextStyle(fontStyle: FontStyle.italic),
),
),
label: Expanded(child: Text('Name', style: TextStyle(fontStyle: FontStyle.italic))),
),
DataColumn(
label: Expanded(
child: Text(
'Age',
style: TextStyle(fontStyle: FontStyle.italic),
),
),
label: Expanded(child: Text('Age', style: TextStyle(fontStyle: FontStyle.italic))),
),
DataColumn(
label: Expanded(
child: Text(
'Role',
style: TextStyle(fontStyle: FontStyle.italic),
),
),
label: Expanded(child: Text('Role', style: TextStyle(fontStyle: FontStyle.italic))),
),
],
rows: const <DataRow>[

View File

@@ -37,11 +37,7 @@ class _DataTableExampleState extends State<DataTableExample> {
Widget build(BuildContext context) {
return SingleChildScrollView(
child: DataTable(
columns: const <DataColumn>[
DataColumn(
label: Text('Number'),
),
],
columns: const <DataColumn>[DataColumn(label: Text('Number'))],
rows: List<DataRow>.generate(
numItems,
(int index) => DataRow(

View File

@@ -20,13 +20,9 @@ class DatePickerApp extends StatelessWidget {
todayForegroundColor: const WidgetStatePropertyAll<Color>(Colors.black),
todayBorder: const BorderSide(width: 2),
dayShape: WidgetStatePropertyAll<OutlinedBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)),
),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16.0)),
),
),
home: const DatePickerExample(),

Some files were not shown because too many files have changed in this diff Show More