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

@@ -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(),

View File

@@ -37,21 +37,19 @@ class _DatePickerExampleState extends State<DatePickerExample> with RestorationM
String? get restorationId => widget.restorationId;
final RestorableDateTime _selectedDate = RestorableDateTime(DateTime(2021, 7, 25));
late final RestorableRouteFuture<DateTime?> _restorableDatePickerRouteFuture = RestorableRouteFuture<DateTime?>(
onComplete: _selectDate,
onPresent: (NavigatorState navigator, Object? arguments) {
return navigator.restorablePush(
_datePickerRoute,
arguments: _selectedDate.value.millisecondsSinceEpoch,
late final RestorableRouteFuture<DateTime?> _restorableDatePickerRouteFuture =
RestorableRouteFuture<DateTime?>(
onComplete: _selectDate,
onPresent: (NavigatorState navigator, Object? arguments) {
return navigator.restorablePush(
_datePickerRoute,
arguments: _selectedDate.value.millisecondsSinceEpoch,
);
},
);
},
);
@pragma('vm:entry-point')
static Route<DateTime> _datePickerRoute(
BuildContext context,
Object? arguments,
) {
static Route<DateTime> _datePickerRoute(BuildContext context, Object? arguments) {
return DialogRoute<DateTime>(
context: context,
builder: (BuildContext context) {
@@ -76,10 +74,13 @@ class _DatePickerExampleState extends State<DatePickerExample> with RestorationM
if (newSelectedDate != null) {
setState(() {
_selectedDate.value = newSelectedDate;
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content:
Text('Selected: ${_selectedDate.value.day}/${_selectedDate.value.month}/${_selectedDate.value.year}'),
));
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'Selected: ${_selectedDate.value.day}/${_selectedDate.value.month}/${_selectedDate.value.year}',
),
),
);
});
}
}

View File

@@ -53,13 +53,10 @@ class _DatePickerExampleState extends State<DatePickerExample> {
children: <Widget>[
Text(
selectedDate != null
? '${selectedDate!.day}/${selectedDate!.month}/${selectedDate!.year}'
: 'No date selected',
),
OutlinedButton(
onPressed: _selectDate,
child: const Text('Select Date'),
? '${selectedDate!.day}/${selectedDate!.month}/${selectedDate!.year}'
: 'No date selected',
),
OutlinedButton(onPressed: _selectDate, child: const Text('Select Date')),
],
);
}

View File

@@ -40,14 +40,17 @@ class _DatePickerExampleState extends State<DatePickerExample> with RestorationM
final RestorableDateTimeN _endDate = RestorableDateTimeN(DateTime(2021, 1, 5));
late final RestorableRouteFuture<DateTimeRange?> _restorableDateRangePickerRouteFuture =
RestorableRouteFuture<DateTimeRange?>(
onComplete: _selectDateRange,
onPresent: (NavigatorState navigator, Object? arguments) {
return navigator.restorablePush(_dateRangePickerRoute, arguments: <String, dynamic>{
'initialStartDate': _startDate.value?.millisecondsSinceEpoch,
'initialEndDate': _endDate.value?.millisecondsSinceEpoch,
});
},
);
onComplete: _selectDateRange,
onPresent: (NavigatorState navigator, Object? arguments) {
return navigator.restorablePush(
_dateRangePickerRoute,
arguments: <String, dynamic>{
'initialStartDate': _startDate.value?.millisecondsSinceEpoch,
'initialEndDate': _endDate.value?.millisecondsSinceEpoch,
},
);
},
);
void _selectDateRange(DateTimeRange? newSelectedDate) {
if (newSelectedDate != null) {
@@ -66,10 +69,7 @@ class _DatePickerExampleState extends State<DatePickerExample> with RestorationM
}
@pragma('vm:entry-point')
static Route<DateTimeRange?> _dateRangePickerRoute(
BuildContext context,
Object? arguments,
) {
static Route<DateTimeRange?> _dateRangePickerRoute(BuildContext context, Object? arguments) {
return DialogRoute<DateTimeRange?>(
context: context,
builder: (BuildContext context) {

View File

@@ -19,9 +19,7 @@ class AdaptiveAlertDialogApp extends StatelessWidget {
theme: ThemeData(platform: TargetPlatform.iOS, useMaterial3: true),
home: Scaffold(
appBar: AppBar(title: const Text('AlertDialog Sample')),
body: const Center(
child: AdaptiveDialogExample(),
),
body: const Center(child: AdaptiveDialogExample()),
),
);
}
@@ -33,7 +31,7 @@ class AdaptiveDialogExample extends StatelessWidget {
Widget adaptiveAction({
required BuildContext context,
required VoidCallback onPressed,
required Widget child
required Widget child,
}) {
final ThemeData theme = Theme.of(context);
switch (theme.platform) {
@@ -51,25 +49,27 @@ class AdaptiveDialogExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return TextButton(
onPressed: () => showAdaptiveDialog<String>(
context: context,
builder: (BuildContext context) => AlertDialog.adaptive(
title: const Text('AlertDialog Title'),
content: const Text('AlertDialog description'),
actions: <Widget>[
adaptiveAction(
context: context,
onPressed: () => Navigator.pop(context, 'Cancel'),
child: const Text('Cancel'),
),
adaptiveAction(
context: context,
onPressed: () => Navigator.pop(context, 'OK'),
child: const Text('OK'),
),
],
),
),
onPressed:
() => showAdaptiveDialog<String>(
context: context,
builder:
(BuildContext context) => AlertDialog.adaptive(
title: const Text('AlertDialog Title'),
content: const Text('AlertDialog description'),
actions: <Widget>[
adaptiveAction(
context: context,
onPressed: () => Navigator.pop(context, 'Cancel'),
child: const Text('Cancel'),
),
adaptiveAction(
context: context,
onPressed: () => Navigator.pop(context, 'OK'),
child: const Text('OK'),
),
],
),
),
child: const Text('Show Dialog'),
);
}

View File

@@ -16,9 +16,7 @@ class AlertDialogExampleApp extends StatelessWidget {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('AlertDialog Sample')),
body: const Center(
child: DialogExample(),
),
body: const Center(child: DialogExample()),
),
);
}
@@ -30,23 +28,25 @@ class DialogExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return TextButton(
onPressed: () => showDialog<String>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('AlertDialog Title'),
content: const Text('AlertDialog description'),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context, 'Cancel'),
child: const Text('Cancel'),
),
TextButton(
onPressed: () => Navigator.pop(context, 'OK'),
child: const Text('OK'),
),
],
),
),
onPressed:
() => showDialog<String>(
context: context,
builder:
(BuildContext context) => AlertDialog(
title: const Text('AlertDialog Title'),
content: const Text('AlertDialog description'),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context, 'Cancel'),
child: const Text('Cancel'),
),
TextButton(
onPressed: () => Navigator.pop(context, 'OK'),
child: const Text('OK'),
),
],
),
),
child: const Text('Show Dialog'),
);
}

View File

@@ -17,9 +17,7 @@ class AlertDialogExampleApp extends StatelessWidget {
theme: ThemeData(colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true),
home: Scaffold(
appBar: AppBar(title: const Text('AlertDialog Sample')),
body: const Center(
child: DialogExample(),
),
body: const Center(child: DialogExample()),
),
);
}
@@ -31,23 +29,25 @@ class DialogExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return TextButton(
onPressed: () => showDialog<String>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('AlertDialog Title'),
content: const Text('AlertDialog description'),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context, 'Cancel'),
child: const Text('Cancel'),
),
TextButton(
onPressed: () => Navigator.pop(context, 'OK'),
child: const Text('OK'),
),
],
),
),
onPressed:
() => showDialog<String>(
context: context,
builder:
(BuildContext context) => AlertDialog(
title: const Text('AlertDialog Title'),
content: const Text('AlertDialog description'),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context, 'Cancel'),
child: const Text('Cancel'),
),
TextButton(
onPressed: () => Navigator.pop(context, 'OK'),
child: const Text('OK'),
),
],
),
),
child: const Text('Show Dialog'),
);
}

View File

@@ -16,9 +16,7 @@ class DialogExampleApp extends StatelessWidget {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Dialog Sample')),
body: const Center(
child: DialogExample(),
),
body: const Center(child: DialogExample()),
),
);
}
@@ -33,51 +31,55 @@ class DialogExample extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextButton(
onPressed: () => showDialog<String>(
context: context,
builder: (BuildContext context) => Dialog(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('This is a typical dialog.'),
const SizedBox(height: 15),
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Close'),
onPressed:
() => showDialog<String>(
context: context,
builder:
(BuildContext context) => Dialog(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('This is a typical dialog.'),
const SizedBox(height: 15),
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Close'),
),
],
),
),
),
],
),
),
),
),
child: const Text('Show Dialog'),
),
const SizedBox(height: 10),
TextButton(
onPressed: () => showDialog<String>(
context: context,
builder: (BuildContext context) => Dialog.fullscreen(
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('This is a fullscreen dialog.'),
const SizedBox(height: 15),
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Close'),
),
],
onPressed:
() => showDialog<String>(
context: context,
builder:
(BuildContext context) => Dialog.fullscreen(
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('This is a fullscreen dialog.'),
const SizedBox(height: 15),
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Close'),
),
],
),
),
),
),
),
child: const Text('Show Fullscreen Dialog'),
),
],

View File

@@ -13,9 +13,7 @@ class ShowDialogExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: DialogExample(),
);
return const MaterialApp(home: DialogExample());
}
}
@@ -49,18 +47,14 @@ class DialogExample extends StatelessWidget {
),
actions: <Widget>[
TextButton(
style: TextButton.styleFrom(
textStyle: Theme.of(context).textTheme.labelLarge,
),
style: TextButton.styleFrom(textStyle: Theme.of(context).textTheme.labelLarge),
child: const Text('Disable'),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
style: TextButton.styleFrom(
textStyle: Theme.of(context).textTheme.labelLarge,
),
style: TextButton.styleFrom(textStyle: Theme.of(context).textTheme.labelLarge),
child: const Text('Enable'),
onPressed: () {
Navigator.of(context).pop();

View File

@@ -50,18 +50,14 @@ class DialogExample extends StatelessWidget {
),
actions: <Widget>[
TextButton(
style: TextButton.styleFrom(
textStyle: Theme.of(context).textTheme.labelLarge,
),
style: TextButton.styleFrom(textStyle: Theme.of(context).textTheme.labelLarge),
child: const Text('Disable'),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
style: TextButton.styleFrom(
textStyle: Theme.of(context).textTheme.labelLarge,
),
style: TextButton.styleFrom(textStyle: Theme.of(context).textTheme.labelLarge),
child: const Text('Enable'),
onPressed: () {
Navigator.of(context).pop();

View File

@@ -13,10 +13,7 @@ class ShowDialogExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
restorationScopeId: 'app',
home: DialogExample(),
);
return const MaterialApp(restorationScopeId: 'app', home: DialogExample());
}
}
@@ -53,18 +50,14 @@ class DialogExample extends StatelessWidget {
),
actions: <Widget>[
TextButton(
style: TextButton.styleFrom(
textStyle: Theme.of(context).textTheme.labelLarge,
),
style: TextButton.styleFrom(textStyle: Theme.of(context).textTheme.labelLarge),
child: const Text('Disable'),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
style: TextButton.styleFrom(
textStyle: Theme.of(context).textTheme.labelLarge,
),
style: TextButton.styleFrom(textStyle: Theme.of(context).textTheme.labelLarge),
child: const Text('Enable'),
onPressed: () {
Navigator.of(context).pop();

View File

@@ -31,20 +31,9 @@ class DividerExample extends StatelessWidget {
child: Column(
children: <Widget>[
const Expanded(
child: ColoredBox(
color: Colors.amber,
child: Center(
child: Text('Above'),
),
),
),
const Divider(
height: 20,
thickness: 5,
indent: 20,
endIndent: 0,
color: Colors.black,
child: ColoredBox(color: Colors.amber, child: Center(child: Text('Above'))),
),
const Divider(height: 20, thickness: 5, indent: 20, endIndent: 0, color: Colors.black),
// Subheader example from Material spec.
// https://material.io/components/dividers#types
Container(
@@ -61,9 +50,7 @@ class DividerExample extends StatelessWidget {
Expanded(
child: ColoredBox(
color: Theme.of(context).colorScheme.primary,
child: const Center(
child: Text('Below'),
),
child: const Center(child: Text('Below')),
),
),
],

View File

@@ -33,17 +33,9 @@ class DividerExample extends StatelessWidget {
padding: EdgeInsets.all(16.0),
child: Column(
children: <Widget>[
Expanded(
child: Card(
child: SizedBox.expand(),
),
),
Expanded(child: Card(child: SizedBox.expand())),
Divider(),
Expanded(
child: Card(
child: SizedBox.expand(),
),
),
Expanded(child: Card(child: SizedBox.expand())),
],
),
),

View File

@@ -33,17 +33,9 @@ class DividerExample extends StatelessWidget {
padding: EdgeInsets.all(16.0),
child: Row(
children: <Widget>[
Expanded(
child: Card(
child: SizedBox.expand(),
),
),
Expanded(child: Card(child: SizedBox.expand())),
VerticalDivider(),
Expanded(
child: Card(
child: SizedBox.expand(),
),
),
Expanded(child: Card(child: SizedBox.expand())),
],
),
),

View File

@@ -13,10 +13,7 @@ class DrawerApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: const DrawerExample(),
);
return MaterialApp(theme: ThemeData(useMaterial3: true), home: const DrawerExample());
}
}
@@ -33,24 +30,14 @@ class _DrawerExampleState extends State<DrawerExample> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Drawer Example'),
),
appBar: AppBar(title: const Text('Drawer Example')),
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
const DrawerHeader(
decoration: BoxDecoration(
color: Colors.blue,
),
child: Text(
'Drawer Header',
style: TextStyle(
color: Colors.white,
fontSize: 24,
),
),
decoration: BoxDecoration(color: Colors.blue),
child: Text('Drawer Header', style: TextStyle(color: Colors.white, fontSize: 24)),
),
ListTile(
leading: const Icon(Icons.message),
@@ -82,9 +69,7 @@ class _DrawerExampleState extends State<DrawerExample> {
],
),
),
body: Center(
child: Text('Page: $selectedPage'),
),
body: Center(child: Text('Page: $selectedPage')),
);
}
}

View File

@@ -18,9 +18,7 @@ class DropdownButtonApp extends StatelessWidget {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('DropdownButton Sample')),
body: const Center(
child: DropdownButtonExample(),
),
body: const Center(child: DropdownButtonExample()),
),
);
}
@@ -43,22 +41,17 @@ class _DropdownButtonExampleState extends State<DropdownButtonExample> {
icon: const Icon(Icons.arrow_downward),
elevation: 16,
style: const TextStyle(color: Colors.deepPurple),
underline: Container(
height: 2,
color: Colors.deepPurpleAccent,
),
underline: Container(height: 2, color: Colors.deepPurpleAccent),
onChanged: (String? value) {
// This is called when the user selects an item.
setState(() {
dropdownValue = value!;
});
},
items: list.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
items:
list.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(value: value, child: Text(value));
}).toList(),
);
}
}

View File

@@ -70,12 +70,10 @@ class _DropdownButtonExampleState extends State<DropdownButtonExample> {
);
}).toList();
},
items: cities.keys.map<DropdownMenuItem<String>>((String item) {
return DropdownMenuItem<String>(
value: item,
child: Text(item),
);
}).toList(),
items:
cities.keys.map<DropdownMenuItem<String>>((String item) {
return DropdownMenuItem<String>(value: item, child: Text(item));
}).toList(),
),
),
],

View File

@@ -54,19 +54,14 @@ class _DropdownButtonExampleState extends State<DropdownButtonExample> {
return options.map((String value) {
return Align(
alignment: Alignment.centerLeft,
child: Text(
dropdownValue,
style: const TextStyle(color: Colors.white),
),
child: Text(dropdownValue, style: const TextStyle(color: Colors.white)),
);
}).toList();
},
items: options.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
items:
options.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(value: value, child: Text(value));
}).toList(),
),
);
}

View File

@@ -35,15 +35,13 @@ enum ColorLabel {
value: color,
label: color.label,
enabled: color.label != 'Grey',
style: MenuItemButton.styleFrom(
foregroundColor: color.color,
),
style: MenuItemButton.styleFrom(foregroundColor: color.color),
),
),
);
}
typedef IconEntry = DropdownMenuEntry<IconLabel>;
typedef IconEntry = DropdownMenuEntry<IconLabel>;
// DropdownMenuEntry labels and values for the second dropdown menu.
enum IconLabel {
@@ -58,11 +56,7 @@ enum IconLabel {
static final List<IconEntry> entries = UnmodifiableListView<IconEntry>(
values.map<IconEntry>(
(IconLabel icon) => IconEntry(
value: icon,
label: icon.label,
leadingIcon: Icon(icon.icon),
),
(IconLabel icon) => IconEntry(value: icon, label: icon.label, leadingIcon: Icon(icon.icon)),
),
);
}
@@ -83,10 +77,7 @@ class _DropdownMenuExampleState extends State<DropdownMenuExample> {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
useMaterial3: true,
colorSchemeSeed: Colors.green,
),
theme: ThemeData(useMaterial3: true, colorSchemeSeed: Colors.green),
home: Scaffold(
body: SafeArea(
child: Column(
@@ -140,15 +131,12 @@ class _DropdownMenuExampleState extends State<DropdownMenuExample> {
Text('You selected a ${selectedColor?.label} ${selectedIcon?.label}'),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 5),
child: Icon(
selectedIcon?.icon,
color: selectedColor?.color,
),
)
child: Icon(selectedIcon?.icon, color: selectedColor?.color),
),
],
)
else
const Text('Please select a color and an icon.')
const Text('Please select a color and an icon.'),
],
),
),

View File

@@ -17,12 +17,10 @@ class DropdownMenuApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3:true),
theme: ThemeData(useMaterial3: true),
home: Scaffold(
appBar: AppBar(title: const Text('DropdownMenu Sample')),
body: const Center(
child: DropdownMenuExample(),
),
body: const Center(child: DropdownMenuExample()),
),
);
}
@@ -35,7 +33,7 @@ class DropdownMenuExample extends StatefulWidget {
State<DropdownMenuExample> createState() => _DropdownMenuExampleState();
}
typedef MenuEntry = DropdownMenuEntry<String>;
typedef MenuEntry = DropdownMenuEntry<String>;
class _DropdownMenuExampleState extends State<DropdownMenuExample> {
static final List<MenuEntry> menuEntries = UnmodifiableListView<MenuEntry>(

View File

@@ -19,9 +19,7 @@ class DropdownMenuApp extends StatelessWidget {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('DropdownMenu Sample')),
body: const Center(
child: DropdownMenuExample(),
),
body: const Center(child: DropdownMenuExample()),
),
);
}
@@ -52,10 +50,7 @@ class _DropdownMenuExampleState extends State<DropdownMenuExample> {
tileColor: colorScheme.primaryContainer,
title: const Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('enabled: true'),
Text('requestFocusOnTap: true'),
],
children: <Widget>[Text('enabled: true'), Text('requestFocusOnTap: true')],
),
subtitle: Column(
children: <Widget>[
@@ -79,10 +74,7 @@ class _DropdownMenuExampleState extends State<DropdownMenuExample> {
tileColor: colorScheme.primaryContainer,
title: const Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('enabled: true'),
Text('requestFocusOnTap: false'),
],
children: <Widget>[Text('enabled: true'), Text('requestFocusOnTap: false')],
),
subtitle: Column(
children: <Widget>[
@@ -106,10 +98,7 @@ class _DropdownMenuExampleState extends State<DropdownMenuExample> {
tileColor: colorScheme.onInverseSurface,
title: const Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('enabled: false'),
Text('requestFocusOnTap: true'),
],
children: <Widget>[Text('enabled: false'), Text('requestFocusOnTap: true')],
),
subtitle: Column(
children: <Widget>[
@@ -134,10 +123,7 @@ class _DropdownMenuExampleState extends State<DropdownMenuExample> {
tileColor: colorScheme.onInverseSurface,
title: const Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('enabled: false'),
Text('requestFocusOnTap: false'),
],
children: <Widget>[Text('enabled: false'), Text('requestFocusOnTap: false')],
),
subtitle: Column(
children: <Widget>[

View File

@@ -19,10 +19,11 @@ enum ColorItem {
}
class DropdownMenuEntryLabelWidgetExample extends StatefulWidget {
const DropdownMenuEntryLabelWidgetExample({ super.key });
const DropdownMenuEntryLabelWidgetExample({super.key});
@override
State<DropdownMenuEntryLabelWidgetExample> createState() => _DropdownMenuEntryLabelWidgetExampleState();
State<DropdownMenuEntryLabelWidgetExample> createState() =>
_DropdownMenuEntryLabelWidgetExampleState();
}
class _DropdownMenuEntryLabelWidgetExampleState extends State<DropdownMenuEntryLabelWidgetExample> {
@@ -43,7 +44,8 @@ class _DropdownMenuEntryLabelWidgetExampleState extends State<DropdownMenuEntryL
@override
Widget build(BuildContext context) {
// Created by Google Bard from 'create a lyrical phrase of about 25 words that begins with "is a color"'.
const String longText = 'is a color that sings of hope, A hue that shines like gold. It is the color of dreams, A shade that never grows old.';
const String longText =
'is a color that sings of hope, A hue that shines like gold. It is the color of dreams, A shade that never grows old.';
return Scaffold(
body: Center(
@@ -55,20 +57,17 @@ class _DropdownMenuEntryLabelWidgetExampleState extends State<DropdownMenuEntryL
onSelected: (ColorItem? color) {
print('Selected $color');
},
dropdownMenuEntries: ColorItem.values.map<DropdownMenuEntry<ColorItem>>((ColorItem item) {
final String labelText = '${item.label} $longText\n';
return DropdownMenuEntry<ColorItem>(
value: item,
label: labelText,
// Try commenting the labelWidget out or changing
// the labelWidget's Text parameters.
labelWidget: Text(
labelText,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
);
}).toList(),
dropdownMenuEntries:
ColorItem.values.map<DropdownMenuEntry<ColorItem>>((ColorItem item) {
final String labelText = '${item.label} $longText\n';
return DropdownMenuEntry<ColorItem>(
value: item,
label: labelText,
// Try commenting the labelWidget out or changing
// the labelWidget's Text parameters.
labelWidget: Text(labelText, maxLines: 1, overflow: TextOverflow.ellipsis),
);
}).toList(),
),
),
);
@@ -76,13 +75,11 @@ class _DropdownMenuEntryLabelWidgetExampleState extends State<DropdownMenuEntryL
}
class DropdownMenuEntryLabelWidgetExampleApp extends StatelessWidget {
const DropdownMenuEntryLabelWidgetExampleApp({ super.key });
const DropdownMenuEntryLabelWidgetExampleApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: DropdownMenuEntryLabelWidgetExample(),
);
return const MaterialApp(home: DropdownMenuEntryLabelWidgetExample());
}
}

View File

@@ -38,17 +38,9 @@ class _ElevatedButtonExampleState extends State<ElevatedButtonExample> {
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ElevatedButton(
style: style,
onPressed: null,
child: const Text('Disabled'),
),
ElevatedButton(style: style, onPressed: null, child: const Text('Disabled')),
const SizedBox(height: 30),
ElevatedButton(
style: style,
onPressed: () {},
child: const Text('Enabled'),
),
ElevatedButton(style: style, onPressed: () {}, child: const Text('Enabled')),
],
),
);

View File

@@ -24,11 +24,7 @@ class ExpansionPanelListExampleApp extends StatelessWidget {
// stores ExpansionPanel state information
class Item {
Item({
required this.expandedValue,
required this.headerValue,
this.isExpanded = false,
});
Item({required this.expandedValue, required this.headerValue, this.isExpanded = false});
String expandedValue;
String headerValue;
@@ -37,10 +33,7 @@ class Item {
List<Item> generateItems(int numberOfItems) {
return List<Item>.generate(numberOfItems, (int index) {
return Item(
headerValue: 'Panel $index',
expandedValue: 'This is item number $index',
);
return Item(headerValue: 'Panel $index', expandedValue: 'This is item number $index');
});
}
@@ -56,11 +49,7 @@ class _ExpansionPanelListExampleState extends State<ExpansionPanelListExample> {
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Container(
child: _buildPanel(),
),
);
return SingleChildScrollView(child: Container(child: _buildPanel()));
}
Widget _buildPanel() {
@@ -70,25 +59,25 @@ class _ExpansionPanelListExampleState extends State<ExpansionPanelListExample> {
_data[index].isExpanded = isExpanded;
});
},
children: _data.map<ExpansionPanel>((Item item) {
return ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile(
title: Text(item.headerValue),
children:
_data.map<ExpansionPanel>((Item item) {
return ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile(title: Text(item.headerValue));
},
body: ListTile(
title: Text(item.expandedValue),
subtitle: const Text('To delete this panel, tap the trash can icon'),
trailing: const Icon(Icons.delete),
onTap: () {
setState(() {
_data.removeWhere((Item currentItem) => item == currentItem);
});
},
),
isExpanded: item.isExpanded,
);
},
body: ListTile(
title: Text(item.expandedValue),
subtitle: const Text('To delete this panel, tap the trash can icon'),
trailing: const Icon(Icons.delete),
onTap: () {
setState(() {
_data.removeWhere((Item currentItem) => item == currentItem);
});
}),
isExpanded: item.isExpanded,
);
}).toList(),
}).toList(),
);
}
}

View File

@@ -24,11 +24,7 @@ class ExpansionPanelListRadioExampleApp extends StatelessWidget {
// stores ExpansionPanel state information
class Item {
Item({
required this.id,
required this.expandedValue,
required this.headerValue,
});
Item({required this.id, required this.expandedValue, required this.headerValue});
int id;
String expandedValue;
@@ -57,25 +53,20 @@ class _ExpansionPanelListRadioExampleState extends State<ExpansionPanelListRadio
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Container(
child: _buildPanel(),
),
);
return SingleChildScrollView(child: Container(child: _buildPanel()));
}
Widget _buildPanel() {
return ExpansionPanelList.radio(
initialOpenPanelValue: 2,
children: _data.map<ExpansionPanelRadio>((Item item) {
return ExpansionPanelRadio(
value: item.id,
headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile(
title: Text(item.headerValue),
);
},
body: ListTile(
children:
_data.map<ExpansionPanelRadio>((Item item) {
return ExpansionPanelRadio(
value: item.id,
headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile(title: Text(item.headerValue));
},
body: ListTile(
title: Text(item.expandedValue),
subtitle: const Text('To delete this panel, tap the trash can icon'),
trailing: const Icon(Icons.delete),
@@ -83,8 +74,10 @@ class _ExpansionPanelListRadioExampleState extends State<ExpansionPanelListRadio
setState(() {
_data.removeWhere((Item currentItem) => item == currentItem);
});
}));
}).toList(),
},
),
);
}).toList(),
);
}
}

View File

@@ -40,9 +40,7 @@ class _ExpansionTileExampleState extends State<ExpansionTileExample> {
const ExpansionTile(
title: Text('ExpansionTile 1'),
subtitle: Text('Trailing expansion arrow icon'),
children: <Widget>[
ListTile(title: Text('This is tile number 1')),
],
children: <Widget>[ListTile(title: Text('This is tile number 1'))],
),
ExpansionTile(
title: const Text('ExpansionTile 2'),
@@ -50,9 +48,7 @@ class _ExpansionTileExampleState extends State<ExpansionTileExample> {
trailing: Icon(
_customTileExpanded ? Icons.arrow_drop_down_circle : Icons.arrow_drop_down,
),
children: const <Widget>[
ListTile(title: Text('This is tile number 2')),
],
children: const <Widget>[ListTile(title: Text('This is tile number 2'))],
onExpansionChanged: (bool expanded) {
setState(() {
_customTileExpanded = expanded;
@@ -63,9 +59,7 @@ class _ExpansionTileExampleState extends State<ExpansionTileExample> {
title: Text('ExpansionTile 3'),
subtitle: Text('Leading expansion arrow icon'),
controlAffinity: ListTileControlAffinity.leading,
children: <Widget>[
ListTile(title: Text('This is tile number 3')),
],
children: <Widget>[ListTile(title: Text('This is tile number 3'))],
),
],
);

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'),
@@ -54,11 +55,12 @@ class _ExpansionTileAnimationStyleAppState extends State<ExpansionTileAnimationS
}
});
},
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: 20),
ExpansionTile(
@@ -68,7 +70,7 @@ class _ExpansionTileAnimationStyleAppState extends State<ExpansionTileAnimationS
ListTile(title: Text('Expanded Item 1')),
ListTile(title: Text('Expanded Item 2')),
],
)
),
],
),
),

View File

@@ -23,35 +23,27 @@ class FilledButtonApp extends StatelessWidget {
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Column(children: <Widget>[
const SizedBox(height: 30),
const Text('Filled'),
const SizedBox(height: 15),
FilledButton(
onPressed: () {},
child: const Text('Enabled'),
),
const SizedBox(height: 30),
const FilledButton(
onPressed: null,
child: Text('Disabled'),
),
]),
Column(
children: <Widget>[
const SizedBox(height: 30),
const Text('Filled'),
const SizedBox(height: 15),
FilledButton(onPressed: () {}, child: const Text('Enabled')),
const SizedBox(height: 30),
const FilledButton(onPressed: null, child: Text('Disabled')),
],
),
const SizedBox(width: 30),
Column(children: <Widget>[
const SizedBox(height: 30),
const Text('Filled tonal'),
const SizedBox(height: 15),
FilledButton.tonal(
onPressed: () {},
child: const Text('Enabled'),
),
const SizedBox(height: 30),
const FilledButton.tonal(
onPressed: null,
child: Text('Disabled'),
),
])
Column(
children: <Widget>[
const SizedBox(height: 30),
const Text('Filled tonal'),
const SizedBox(height: 15),
FilledButton.tonal(onPressed: () {}, child: const Text('Enabled')),
const SizedBox(height: 30),
const FilledButton.tonal(onPressed: null, child: Text('Disabled')),
],
),
],
),
),

View File

@@ -18,9 +18,7 @@ class ChipApp extends StatelessWidget {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: Scaffold(
appBar: AppBar(
title: const Text('FilterChip Sample'),
),
appBar: AppBar(title: const Text('FilterChip Sample')),
body: const FilterChipExample(),
),
);
@@ -49,21 +47,22 @@ class _FilterChipExampleState extends State<FilterChipExample> {
const SizedBox(height: 5.0),
Wrap(
spacing: 5.0,
children: ExerciseFilter.values.map((ExerciseFilter exercise) {
return FilterChip(
label: Text(exercise.name),
selected: filters.contains(exercise),
onSelected: (bool selected) {
setState(() {
if (selected) {
filters.add(exercise);
} else {
filters.remove(exercise);
}
});
},
);
}).toList(),
children:
ExerciseFilter.values.map((ExerciseFilter exercise) {
return FilterChip(
label: Text(exercise.name),
selected: filters.contains(exercise),
onSelected: (bool selected) {
setState(() {
if (selected) {
filters.add(exercise);
} else {
filters.remove(exercise);
}
});
},
);
}).toList(),
),
const SizedBox(height: 10.0),
Text(

View File

@@ -49,10 +49,7 @@ class FlexibleSpaceBarExampleApp extends StatelessWidget {
gradient: LinearGradient(
begin: Alignment(0.0, 0.5),
end: Alignment.center,
colors: <Color>[
Color(0x60000000),
Color(0x00000000),
],
colors: <Color>[Color(0x60000000), Color(0x00000000)],
),
),
),
@@ -61,21 +58,19 @@ class FlexibleSpaceBarExampleApp extends StatelessWidget {
),
),
SliverList(
delegate: SliverChildListDelegate(
const <Widget>[
ListTile(
leading: Icon(Icons.wb_sunny),
title: Text('Sunday'),
subtitle: Text('sunny, h: 80, l: 65'),
),
ListTile(
leading: Icon(Icons.wb_sunny),
title: Text('Monday'),
subtitle: Text('sunny, h: 80, l: 65'),
),
// ListTiles++
],
),
delegate: SliverChildListDelegate(const <Widget>[
ListTile(
leading: Icon(Icons.wb_sunny),
title: Text('Sunday'),
subtitle: Text('sunny, h: 80, l: 65'),
),
ListTile(
leading: Icon(Icons.wb_sunny),
title: Text('Monday'),
subtitle: Text('sunny, h: 80, l: 65'),
),
// ListTiles++
]),
),
],
),

View File

@@ -11,7 +11,7 @@ void main() {
}
class FloatingActionButtonExampleApp extends StatelessWidget {
const FloatingActionButtonExampleApp({ super.key });
const FloatingActionButtonExampleApp({super.key});
@override
Widget build(BuildContext context) {
@@ -23,7 +23,7 @@ class FloatingActionButtonExampleApp extends StatelessWidget {
}
class FloatingActionButtonExample extends StatefulWidget {
const FloatingActionButtonExample({ super.key });
const FloatingActionButtonExample({super.key});
@override
State<FloatingActionButtonExample> createState() => _FloatingActionButtonExampleState();
@@ -31,20 +31,19 @@ class FloatingActionButtonExample extends StatefulWidget {
class _FloatingActionButtonExampleState extends State<FloatingActionButtonExample> {
// The FAB's foregroundColor, backgroundColor, and shape
static const List<(Color?, Color? background, ShapeBorder?)> customizations = <(Color?, Color?, ShapeBorder?)>[
(null, null, null), // The FAB uses its default for null parameters.
(null, Colors.green, null),
(Colors.white, Colors.green, null),
(Colors.white, Colors.green, CircleBorder()),
];
static const List<(Color?, Color? background, ShapeBorder?)> customizations =
<(Color?, Color?, ShapeBorder?)>[
(null, null, null), // The FAB uses its default for null parameters.
(null, Colors.green, null),
(Colors.white, Colors.green, null),
(Colors.white, Colors.green, CircleBorder()),
];
int index = 0; // Selects the customization.
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('FloatingActionButton Sample'),
),
appBar: AppBar(title: const Text('FloatingActionButton Sample')),
body: const Center(child: Text('Press the button below!')),
floatingActionButton: FloatingActionButton(
onPressed: () {

View File

@@ -26,9 +26,7 @@ class FloatingActionButtonExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('FloatingActionButton Sample'),
),
appBar: AppBar(title: const Text('FloatingActionButton Sample')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,

View File

@@ -41,9 +41,7 @@ class FloatingActionButtonExample extends StatelessWidget {
}
return Scaffold(
appBar: AppBar(
title: const Text('FAB Additional Color Mappings'),
),
appBar: AppBar(title: const Text('FAB Additional Color Mappings')),
body: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,

View File

@@ -13,16 +13,15 @@ class StandardFabLocationExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: StandardFabLocationExample(),
);
return const MaterialApp(home: StandardFabLocationExample());
}
}
class AlmostEndFloatFabLocation extends StandardFabLocation with FabEndOffsetX, FabFloatOffsetY {
@override
double getOffsetX(ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment) {
final double directionalAdjustment = scaffoldGeometry.textDirection == TextDirection.ltr ? -50.0 : 50.0;
final double directionalAdjustment =
scaffoldGeometry.textDirection == TextDirection.ltr ? -50.0 : 50.0;
return super.getOffsetX(scaffoldGeometry, adjustment) + directionalAdjustment;
}
}
@@ -33,9 +32,7 @@ class StandardFabLocationExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Home page'),
),
appBar: AppBar(title: const Text('Home page')),
floatingActionButton: FloatingActionButton(
onPressed: () {
debugPrint('FAB pressed.');

View File

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

View File

@@ -32,15 +32,8 @@ class IconButtonExample extends StatelessWidget {
color: Colors.white,
child: Center(
child: Ink(
decoration: const ShapeDecoration(
color: Colors.lightBlue,
shape: CircleBorder(),
),
child: IconButton(
icon: const Icon(Icons.android),
color: Colors.white,
onPressed: () {},
),
decoration: const ShapeDecoration(color: Colors.lightBlue, shape: CircleBorder()),
child: IconButton(icon: const Icon(Icons.android), color: Colors.white, onPressed: () {}),
),
),
);

View File

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

View File

@@ -16,14 +16,9 @@ class IconButtonToggleApp 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),
title: 'Icon Button Types',
home: const Scaffold(
body: DemoIconToggleButtons(),
),
home: const Scaffold(body: DemoIconToggleButtons()),
);
}
}

View File

@@ -13,7 +13,9 @@ void main() {
appBar: AppBar(title: const Text('Image.frameBuilder Sample')),
body: const Center(
child: ImageClipExample(
image: NetworkImage('https://flutter.github.io/assets-for-api-docs/assets/widgets/puffin.jpg'),
image: NetworkImage(
'https://flutter.github.io/assets-for-api-docs/assets/widgets/puffin.jpg',
),
),
),
),
@@ -36,16 +38,15 @@ class ImageClipExample extends StatelessWidget {
height: 300,
image: image,
child: InkWell(
onTap: () {/* ... */},
onTap: () {
/* ... */
},
child: const Align(
child: Padding(
padding: EdgeInsets.all(10.0),
child: Text(
'PUFFIN',
style: TextStyle(
fontWeight: FontWeight.w900,
color: Colors.white,
),
style: TextStyle(fontWeight: FontWeight.w900, color: Colors.white),
),
),
),

View File

@@ -7,16 +7,20 @@ import 'package:flutter/material.dart';
/// Flutter code sample for [Image.frameBuilder].
void main() {
runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Image.frameBuilder Sample')),
body: const Center(
child: ImageClipExample(
image: NetworkImage('https://flutter.github.io/assets-for-api-docs/assets/widgets/puffin.jpg'),
runApp(
MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Image.frameBuilder Sample')),
body: const Center(
child: ImageClipExample(
image: NetworkImage(
'https://flutter.github.io/assets-for-api-docs/assets/widgets/puffin.jpg',
),
),
),
),
),
));
);
}
class ImageClipExample extends StatelessWidget {
@@ -35,16 +39,15 @@ class ImageClipExample extends StatelessWidget {
height: 300,
image: image,
child: InkWell(
onTap: () {/* ... */},
onTap: () {
/* ... */
},
child: const Align(
child: Padding(
padding: EdgeInsets.all(10.0),
child: Text(
'PUFFIN',
style: TextStyle(
fontWeight: FontWeight.w900,
color: Colors.white,
),
style: TextStyle(fontWeight: FontWeight.w900, color: Colors.white),
),
),
),

View File

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

View File

@@ -34,9 +34,7 @@ class _InputChipExampleState extends State<InputChipExample> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('InputChip Sample'),
),
appBar: AppBar(title: const Text('InputChip Sample')),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
@@ -45,29 +43,27 @@ class _InputChipExampleState extends State<InputChipExample> {
Wrap(
alignment: WrapAlignment.center,
spacing: 5.0,
children: List<Widget>.generate(
inputs,
(int index) {
return InputChip(
label: Text('Person ${index + 1}'),
selected: selectedIndex == index,
onSelected: (bool selected) {
setState(() {
if (selectedIndex == index) {
selectedIndex = null;
} else {
selectedIndex = index;
}
});
},
onDeleted: () {
setState(() {
inputs = inputs - 1;
});
},
);
},
).toList(),
children:
List<Widget>.generate(inputs, (int index) {
return InputChip(
label: Text('Person ${index + 1}'),
selected: selectedIndex == index,
onSelected: (bool selected) {
setState(() {
if (selectedIndex == index) {
selectedIndex = null;
} else {
selectedIndex = index;
}
});
},
onDeleted: () {
setState(() {
inputs = inputs - 1;
});
},
);
}).toList(),
),
const SizedBox(height: 10),
ElevatedButton(
@@ -77,7 +73,7 @@ class _InputChipExampleState extends State<InputChipExample> {
});
},
child: const Text('Reset'),
)
),
],
),
),

View File

@@ -49,9 +49,7 @@ class EditableChipFieldExampleState extends State<EditableChipFieldExample> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Editable Chip Field Sample'),
),
appBar: AppBar(title: const Text('Editable Chip Field Sample')),
body: Column(
children: <Widget>[
Padding(
@@ -74,10 +72,7 @@ class EditableChipFieldExampleState extends State<EditableChipFieldExample> {
child: ListView.builder(
itemCount: _suggestions.length,
itemBuilder: (BuildContext context, int index) {
return ToppingSuggestion(
_suggestions[index],
onTap: _selectSuggestion,
);
return ToppingSuggestion(_suggestions[index], onTap: _selectSuggestion);
},
),
),
@@ -89,18 +84,12 @@ class EditableChipFieldExampleState extends State<EditableChipFieldExample> {
Future<void> _onSearchChanged(String value) async {
final List<String> results = await _suggestionCallback(value);
setState(() {
_suggestions = results
.where((String topping) => !_toppings.contains(topping))
.toList();
_suggestions = results.where((String topping) => !_toppings.contains(topping)).toList();
});
}
Widget _chipBuilder(BuildContext context, String topping) {
return ToppingInputChip(
topping: topping,
onDeleted: _onChipDeleted,
onSelected: _onChipTapped,
);
return ToppingInputChip(topping: topping, onDeleted: _onChipDeleted, onSelected: _onChipTapped);
}
void _selectSuggestion(String topping) {
@@ -189,10 +178,7 @@ class ChipsInputState<T> extends State<ChipsInput<T>> {
void initState() {
super.initState();
controller = ChipsInputEditingController<T>(
<T>[...widget.values],
widget.chipBuilder,
);
controller = ChipsInputEditingController<T>(<T>[...widget.values], widget.chipBuilder);
controller.addListener(_textListener);
}
@@ -240,8 +226,8 @@ class ChipsInputState<T> extends State<ChipsInput<T>> {
static int countReplacements(String text) {
return text.codeUnits
.where((int u) => u == ChipsInputEditingController.kObjectReplacementChar)
.length;
.where((int u) => u == ChipsInputEditingController.kObjectReplacementChar)
.length;
}
@override
@@ -255,19 +241,15 @@ class ChipsInputState<T> extends State<ChipsInput<T>> {
style: widget.style,
strutStyle: widget.strutStyle,
controller: controller,
onChanged: (String value) =>
widget.onTextChanged?.call(controller.textWithoutReplacements),
onSubmitted: (String value) =>
widget.onSubmitted?.call(controller.textWithoutReplacements),
onChanged: (String value) => widget.onTextChanged?.call(controller.textWithoutReplacements),
onSubmitted: (String value) => widget.onSubmitted?.call(controller.textWithoutReplacements),
);
}
}
class ChipsInputEditingController<T> extends TextEditingController {
ChipsInputEditingController(this.values, this.chipBuilder)
: super(
text: String.fromCharCode(kObjectReplacementChar) * values.length,
);
: super(text: String.fromCharCode(kObjectReplacementChar) * values.length);
// This constant character acts as a placeholder in the TextField text value.
// There will be one character for each of the InputChip displayed.
@@ -299,18 +281,20 @@ class ChipsInputEditingController<T> extends TextEditingController {
String get textWithReplacements => text;
@override
TextSpan buildTextSpan(
{required BuildContext context, TextStyle? style, required bool withComposing}) {
final Iterable<WidgetSpan> chipWidgets =
values.map((T v) => WidgetSpan(child: chipBuilder(context, v)));
TextSpan buildTextSpan({
required BuildContext context,
TextStyle? style,
required bool withComposing,
}) {
final Iterable<WidgetSpan> chipWidgets = values.map(
(T v) => WidgetSpan(child: chipBuilder(context, v)),
);
return TextSpan(
style: style,
children: <InlineSpan>[
...chipWidgets,
if (textWithoutReplacements.isNotEmpty)
TextSpan(text: textWithoutReplacements)
if (textWithoutReplacements.isNotEmpty) TextSpan(text: textWithoutReplacements),
],
);
}
@@ -326,11 +310,7 @@ class ToppingSuggestion extends StatelessWidget {
Widget build(BuildContext context) {
return ListTile(
key: ObjectKey(topping),
leading: CircleAvatar(
child: Text(
topping[0].toUpperCase(),
),
),
leading: CircleAvatar(child: Text(topping[0].toUpperCase())),
title: Text(topping),
onTap: () => onTap?.call(topping),
);
@@ -356,9 +336,7 @@ class ToppingInputChip extends StatelessWidget {
child: InputChip(
key: ObjectKey(topping),
label: Text(topping),
avatar: CircleAvatar(
child: Text(topping[0].toUpperCase()),
),
avatar: CircleAvatar(child: Text(topping[0].toUpperCase())),
onDeleted: () => onDeleted(topping),
onSelected: (bool value) => onSelected(topping),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,

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