Rename Sample classes (#124080)

Rename Sample classes
This commit is contained in:
Greg Spencer
2023-04-04 13:34:29 -07:00
committed by GitHub
parent c8a3dbaf06
commit e3bc8efd39
480 changed files with 3125 additions and 3816 deletions

View File

@@ -2,28 +2,25 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [AboutListTile].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [AboutListTile].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const AboutListTileExampleApp());
static const String _title = 'Flutter Code Sample';
class AboutListTileExampleApp extends StatelessWidget {
const AboutListTileExampleApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyStatelessWidget(),
home: AboutListTileExample(),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class AboutListTileExample extends StatelessWidget {
const AboutListTileExample({super.key});
@override
Widget build(BuildContext context) {
@@ -39,9 +36,7 @@ class MyStatelessWidget extends StatelessWidget {
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.copyWith(color: theme.colorScheme.primary), text: 'https://flutter.dev'),
TextSpan(style: textStyle, text: '.'),
],
),

View File

@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [ActionIconTheme].
import 'package:flutter/material.dart';
/// Flutter code sample for [ActionIconTheme].
void main() {
runApp(const MyApp());
runApp(const ActionIconThemeExampleApp());
}
class _CustomEndDrawerIcon extends StatelessWidget {
@@ -36,13 +36,12 @@ class _CustomDrawerIcon extends StatelessWidget {
}
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
class ActionIconThemeExampleApp extends StatelessWidget {
const ActionIconThemeExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
useMaterial3: true,

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [AnimatedIcon].
import 'package:flutter/material.dart';
/// Flutter code sample for [AnimatedIcon].
void main() {
runApp(const AnimatedIconApp());
}
@@ -44,8 +44,9 @@ class _AnimatedIconExampleState extends State<AnimatedIconExample> with SingleTi
controller = AnimationController(
vsync: this,
duration: const Duration(seconds: 2),
)..forward()
..repeat(reverse: true);
)
..forward()
..repeat(reverse: true);
animation = Tween<double>(begin: 0.0, end: 1.0).animate(controller);
}

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [AnimatedIcon].
import 'package:flutter/material.dart';
/// Flutter code sample for [AnimatedIcon].
final Map<String, AnimatedIconData> iconsList = <String, AnimatedIconData>{
'add_event': AnimatedIcons.add_event,
'arrow_menu': AnimatedIcons.arrow_menu,
@@ -61,8 +61,9 @@ class _AnimatedIconExampleState extends State<AnimatedIconExample> with SingleTi
controller = AnimationController(
vsync: this,
duration: const Duration(seconds: 2),
)..forward()
..repeat(reverse: true);
)
..forward()
..repeat(reverse: true);
animation = Tween<double>(begin: 0.0, end: 1.0).animate(controller);
}

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [AppBar].
import 'package:flutter/material.dart';
/// Flutter code sample for [AppBar].
void main() => runApp(const AppBarApp());
class AppBarApp extends StatelessWidget {
@@ -32,8 +32,7 @@ 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(

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [AppBar].
import 'package:flutter/material.dart';
/// Flutter code sample for [AppBar].
final List<int> _items = List<int>.generate(51, (int index) => index);
void main() => runApp(const AppBarApp());

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [AppBar].
import 'package:flutter/material.dart';
/// Flutter code sample for [AppBar].
void main() => runApp(const AppBarApp());
class AppBarApp extends StatelessWidget {

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [AppBar].
import 'package:flutter/material.dart';
/// Flutter code sample for [AppBar].
List<String> titles = <String>[
'Cloud',
'Beach',
@@ -80,7 +80,7 @@ class AppBarExample extends StatelessWidget {
ListView.builder(
itemCount: 25,
itemBuilder: (BuildContext context, int index) {
return ListTile(
return ListTile(
tileColor: index.isOdd ? oddItemColor : evenItemColor,
title: Text('${titles[0]} $index'),
);
@@ -89,7 +89,7 @@ class AppBarExample extends StatelessWidget {
ListView.builder(
itemCount: 25,
itemBuilder: (BuildContext context, int index) {
return ListTile(
return ListTile(
tileColor: index.isOdd ? oddItemColor : evenItemColor,
title: Text('${titles[1]} $index'),
);
@@ -98,7 +98,7 @@ class AppBarExample extends StatelessWidget {
ListView.builder(
itemCount: 25,
itemBuilder: (BuildContext context, int index) {
return ListTile(
return ListTile(
tileColor: index.isOdd ? oddItemColor : evenItemColor,
title: Text('${titles[2]} $index'),
);

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [SliverAppBar].
import 'package:flutter/material.dart';
/// Flutter code sample for [SliverAppBar].
void main() => runApp(const AppBarApp());
class AppBarApp extends StatelessWidget {

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [SliverAppBar.medium].
import 'package:flutter/material.dart';
/// Flutter code sample for [SliverAppBar.medium].
void main() {
runApp(const AppBarMediumApp());
}
@@ -18,7 +18,7 @@ class AppBarMediumApp extends StatelessWidget {
return MaterialApp(
theme: ThemeData(
useMaterial3: true,
colorSchemeSeed: const Color(0xff6750A4)
colorSchemeSeed: const Color(0xff6750A4),
),
home: Material(
child: CustomScrollView(

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [SliverAppBar.large].
import 'package:flutter/material.dart';
/// Flutter code sample for [SliverAppBar.large].
void main() {
runApp(const AppBarLargeApp());
}
@@ -18,7 +18,7 @@ class AppBarLargeApp extends StatelessWidget {
return MaterialApp(
theme: ThemeData(
useMaterial3: true,
colorSchemeSeed: const Color(0xff6750A4)
colorSchemeSeed: const Color(0xff6750A4),
),
home: Material(
child: CustomScrollView(

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [Autocomplete].
import 'package:flutter/material.dart';
/// Flutter code sample for [Autocomplete].
void main() => runApp(const AutocompleteExampleApp());
class AutocompleteExampleApp extends StatelessWidget {

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [Autocomplete].
import 'package:flutter/material.dart';
/// Flutter code sample for [Autocomplete].
void main() => runApp(const AutocompleteExampleApp());
class AutocompleteExampleApp extends StatelessWidget {
@@ -73,9 +73,7 @@ class AutocompleteBasicUserExample extends StatelessWidget {
return const Iterable<User>.empty();
}
return _userOptions.where((User option) {
return option
.toString()
.contains(textEditingValue.text.toLowerCase());
return option.toString().contains(textEditingValue.text.toLowerCase());
});
},
onSelected: (User selection) {

View File

@@ -2,28 +2,25 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [MaterialBanner].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [MaterialBanner].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const MaterialBannerExampleApp());
static const String _title = 'Flutter Code Sample';
class MaterialBannerExampleApp extends StatelessWidget {
const MaterialBannerExampleApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyStatelessWidget(),
home: MaterialBannerExample(),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class MaterialBannerExample extends StatelessWidget {
const MaterialBannerExample({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,28 +2,25 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [MaterialBanner].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [MaterialBanner].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const MaterialBannerExampleApp());
static const String _title = 'Flutter Code Sample';
class MaterialBannerExampleApp extends StatelessWidget {
const MaterialBannerExampleApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyStatelessWidget(),
home: MaterialBannerExample(),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class MaterialBannerExample extends StatelessWidget {
const MaterialBannerExample({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [BottomAppBar].
import 'package:flutter/material.dart';
/// Flutter code sample for [BottomAppBar].
void main() {
runApp(const BottomAppBarDemo());
}
@@ -20,8 +20,7 @@ class BottomAppBarDemo extends StatefulWidget {
class _BottomAppBarDemoState extends State<BottomAppBarDemo> {
bool _showFab = true;
bool _showNotch = true;
FloatingActionButtonLocation _fabLocation =
FloatingActionButtonLocation.endDocked;
FloatingActionButtonLocation _fabLocation = FloatingActionButtonLocation.endDocked;
void _onShowNotchChanged(bool value) {
setState(() {
@@ -120,8 +119,7 @@ class _DemoBottomAppBar extends StatelessWidget {
final FloatingActionButtonLocation fabLocation;
final NotchedShape? shape;
static final List<FloatingActionButtonLocation> centerLocations =
<FloatingActionButtonLocation>[
static final List<FloatingActionButtonLocation> centerLocations = <FloatingActionButtonLocation>[
FloatingActionButtonLocation.centerDocked,
FloatingActionButtonLocation.centerFloat,
];

View File

@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for BottomAppBar with Material 3
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
/// Flutter code sample for [BottomAppBar] with Material 3.
void main() {
runApp(const BottomAppBarDemo());
}
@@ -37,9 +37,8 @@ class _BottomAppBarDemoState extends State<BottomAppBarDemo> {
bool _isElevated = true;
bool _isVisible = true;
FloatingActionButtonLocation get _fabLocation => _isVisible
? FloatingActionButtonLocation.endContained
: FloatingActionButtonLocation.endFloat;
FloatingActionButtonLocation get _fabLocation =>
_isVisible ? FloatingActionButtonLocation.endContained : FloatingActionButtonLocation.endFloat;
void _listen() {
final ScrollDirection direction = _controller.position.userScrollDirection;

View File

@@ -2,37 +2,33 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [BottomNavigationBar].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [BottomNavigationBar].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const BottomNavigationBarExampleApp());
static const String _title = 'Flutter Code Sample';
class BottomNavigationBarExampleApp extends StatelessWidget {
const BottomNavigationBarExampleApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyStatefulWidget(),
home: BottomNavigationBarExample(),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
class BottomNavigationBarExample extends StatefulWidget {
const BottomNavigationBarExample({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<BottomNavigationBarExample> createState() => _BottomNavigationBarExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _BottomNavigationBarExampleState extends State<BottomNavigationBarExample> {
int _selectedIndex = 0;
static const TextStyle optionStyle =
TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static const TextStyle optionStyle = TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static const List<Widget> _widgetOptions = <Widget>[
Text(
'Index 0: Home',

View File

@@ -2,37 +2,33 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [BottomNavigationBar].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [BottomNavigationBar].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const BottomNavigationBarExampleApp());
static const String _title = 'Flutter Code Sample';
class BottomNavigationBarExampleApp extends StatelessWidget {
const BottomNavigationBarExampleApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyStatefulWidget(),
home: BottomNavigationBarExample(),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
class BottomNavigationBarExample extends StatefulWidget {
const BottomNavigationBarExample({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<BottomNavigationBarExample> createState() => _BottomNavigationBarExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _BottomNavigationBarExampleState extends State<BottomNavigationBarExample> {
int _selectedIndex = 0;
static const TextStyle optionStyle =
TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static const TextStyle optionStyle = TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static const List<Widget> _widgetOptions = <Widget>[
Text(
'Index 0: Home',

View File

@@ -2,34 +2,31 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [BottomNavigationBar].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [BottomNavigationBar].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const BottomNavigationBarExampleApp());
static const String _title = 'Flutter Code Sample';
class BottomNavigationBarExampleApp extends StatelessWidget {
const BottomNavigationBarExampleApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyStatefulWidget(),
home: BottomNavigationBarExample(),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
class BottomNavigationBarExample extends StatefulWidget {
const BottomNavigationBarExample({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<BottomNavigationBarExample> createState() => _BottomNavigationBarExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _BottomNavigationBarExampleState extends State<BottomNavigationBarExample> {
int _selectedIndex = 0;
final ScrollController _homeController = ScrollController();

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [showModalBottomSheet].
import 'package:flutter/material.dart';
/// Flutter code sample for [showModalBottomSheet].
void main() => runApp(const BottomSheetApp());
class BottomSheetApp extends StatelessWidget {

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [showModalBottomSheet].
import 'package:flutter/material.dart';
/// Flutter code sample for [showModalBottomSheet].
void main() => runApp(const BottomSheetApp());
class BottomSheetApp extends StatelessWidget {

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [ElevatedButton].
import 'package:flutter/material.dart';
/// Flutter code sample for [ElevatedButton].
void main() {
runApp(const ButtonApp());
}
@@ -45,7 +45,7 @@ class ButtonTypesExample extends StatelessWidget {
}
class ButtonTypesGroup extends StatelessWidget {
const ButtonTypesGroup({ super.key, required this.enabled });
const ButtonTypesGroup({super.key, required this.enabled});
final bool enabled;

View File

@@ -2,31 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [Card].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [Card].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const CardExampleApp());
static const String _title = 'Flutter Code Sample';
class CardExampleApp extends StatelessWidget {
const CardExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
appBar: AppBar(title: const Text('Card Sample')),
body: const CardExample(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class CardExample extends StatelessWidget {
const CardExample({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,31 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [Card].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [Card].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const CardExampleApp());
static const String _title = 'Flutter Code Sample';
class CardExampleApp extends StatelessWidget {
const CardExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
appBar: AppBar(title: const Text('Card Sample')),
body: const CardExample(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class CardExample extends StatelessWidget {
const CardExample({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,11 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [Card].
import 'package:flutter/material.dart';
void main() { runApp(const CardExamplesApp()); }
/// Flutter code sample for [Card].
void main() {
runApp(const CardExamplesApp());
}
class CardExamplesApp extends StatelessWidget {
const CardExamplesApp({super.key});
@@ -38,7 +40,7 @@ class CardExamplesApp extends StatelessWidget {
///
/// https://m3.material.io/components/cards/specs#a012d40d-7a5c-4b07-8740-491dec79d58b
class ElevatedCardExample extends StatelessWidget {
const ElevatedCardExample({ super.key });
const ElevatedCardExample({super.key});
@override
Widget build(BuildContext context) {
@@ -61,7 +63,7 @@ class ElevatedCardExample extends StatelessWidget {
///
/// https://m3.material.io/components/cards/specs#0f55bf62-edf2-4619-b00d-b9ed462f2c5a
class FilledCardExample extends StatelessWidget {
const FilledCardExample({ super.key });
const FilledCardExample({super.key});
@override
Widget build(BuildContext context) {
@@ -86,7 +88,7 @@ class FilledCardExample extends StatelessWidget {
///
/// https://m3.material.io/components/cards/specs#0f55bf62-edf2-4619-b00d-b9ed462f2c5a
class OutlinedCardExample extends StatelessWidget {
const OutlinedCardExample({ super.key });
const OutlinedCardExample({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,39 +2,36 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [Checkbox].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [Checkbox].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const CheckboxExampleApp());
static const String _title = 'Flutter Code Sample';
class CheckboxExampleApp extends StatelessWidget {
const CheckboxExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
appBar: AppBar(title: const Text('Checkbox Sample')),
body: const Center(
child: MyStatefulWidget(),
child: CheckboxExample(),
),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
class CheckboxExample extends StatefulWidget {
const CheckboxExample({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<CheckboxExample> createState() => _CheckboxExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _CheckboxExampleState extends State<CheckboxExample> {
bool isChecked = false;
@override

View File

@@ -2,40 +2,38 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for M3 Checkbox with error state
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for M3 [Checkbox] with error state.
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const CheckboxExampleApp());
static const String _title = 'Flutter Code Sample';
class CheckboxExampleApp extends StatelessWidget {
const CheckboxExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3: true, colorSchemeSeed: const Color(0xff6750a4)),
title: _title,
title: 'Checkbox Sample',
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
appBar: AppBar(title: const Text('Checkbox Sample')),
body: const Center(
child: MyStatefulWidget(),
child: CheckboxExample(),
),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
class CheckboxExample extends StatefulWidget {
const CheckboxExample({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<CheckboxExample> createState() => _CheckboxExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _CheckboxExampleState extends State<CheckboxExample> {
bool? isChecked = true;
@override

View File

@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [CheckboxListTile].
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart' show timeDilation;
/// Flutter code sample for [CheckboxListTile].
void main() => runApp(const CheckboxListTileApp());
class CheckboxListTileApp extends StatelessWidget {

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [CheckboxListTile].
import 'package:flutter/material.dart';
/// Flutter code sample for [CheckboxListTile].
void main() => runApp(const CheckboxListTileApp());
class CheckboxListTileApp extends StatelessWidget {
@@ -57,7 +57,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.'),
subtitle: const Text(
'Longer supporting text to demonstrate how the text wraps and the checkbox is centered vertically with the text.'),
),
const Divider(height: 0),
CheckboxListTile(
@@ -68,7 +69,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."),
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."),
isThreeLine: true,
),
const Divider(height: 0),

View File

@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for custom labeled checkbox.
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
/// Flutter code sample for custom labeled checkbox.
void main() => runApp(const LabeledCheckboxApp());
class LabeledCheckboxApp extends StatelessWidget {

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for custom labeled checkbox.
import 'package:flutter/material.dart';
/// Flutter code sample for custom labeled checkbox.
void main() => runApp(const LabeledCheckboxApp());
class LabeledCheckboxApp extends StatelessWidget {

View File

@@ -2,25 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [DeletableChipAttributes.onDeleted].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [DeletableChipAttributes.onDeleted].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const OnDeletedExampleApp());
static const String _title = 'Flutter Code Sample';
class OnDeletedExampleApp extends StatelessWidget {
const OnDeletedExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
appBar: AppBar(title: const Text('DeletableChipAttributes.onDeleted Sample')),
body: const Center(
child: MyStatefulWidget(),
child: OnDeletedExample(),
),
),
);
@@ -75,14 +72,14 @@ class CastListState extends State<CastList> {
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
class OnDeletedExample extends StatefulWidget {
const OnDeletedExample({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<OnDeletedExample> createState() => _OnDeletedExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _OnDeletedExampleState extends State<OnDeletedExample> {
@override
Widget build(BuildContext context) {
return const CastList();

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [ActionChoice].
import 'package:flutter/material.dart';
/// Flutter code sample for [ActionChoice].
void main() => runApp(const ChipApp());
class ChipApp extends StatelessWidget {

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [ColorScheme.fromImageProvider] with content-based dynamic color.
import 'package:flutter/material.dart';
/// Flutter code sample for [ColorScheme.fromImageProvider] with content-based dynamic color.
const Widget divider = SizedBox(height: 10);
const double narrowScreenWidthThreshold = 400;
const double imageSize = 150;
@@ -16,12 +16,18 @@ class DynamicColorExample extends StatefulWidget {
DynamicColorExample({super.key});
final List<ImageProvider> images = <NetworkImage>[
const NetworkImage('https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_1.png'),
const NetworkImage('https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_2.png'),
const NetworkImage('https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_3.png'),
const NetworkImage('https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_4.png'),
const NetworkImage('https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_5.png'),
const NetworkImage('https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_6.png'),
const NetworkImage(
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_1.png'),
const NetworkImage(
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_2.png'),
const NetworkImage(
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_3.png'),
const NetworkImage(
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_4.png'),
const NetworkImage(
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_5.png'),
const NetworkImage(
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_6.png'),
];
@override
@@ -69,9 +75,7 @@ class _DynamicColorExampleState extends State<DynamicColorExample> {
padding: const EdgeInsets.symmetric(vertical: 15),
child: Text(
brightness,
style: TextStyle(
fontWeight: FontWeight.bold,
color: colorScheme.onSecondaryContainer),
style: TextStyle(fontWeight: FontWeight.bold, color: colorScheme.onSecondaryContainer),
),
);
}
@@ -84,7 +88,6 @@ class _DynamicColorExampleState extends State<DynamicColorExample> {
}
return MaterialApp(
title: 'Content Based Dynamic Color',
theme: ThemeData(useMaterial3: true, colorScheme: colorScheme),
debugShowCheckedModeBanner: false,
home: Builder(
@@ -125,21 +128,17 @@ class _DynamicColorExampleState extends State<DynamicColorExample> {
Expanded(
child: ColoredBox(
color: colorScheme.background,
child: LayoutBuilder(builder: (BuildContext context,
BoxConstraints constraints) {
if (constraints.maxWidth <
narrowScreenWidthThreshold) {
child: LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) {
if (constraints.maxWidth < narrowScreenWidthThreshold) {
return SingleChildScrollView(
child: Column(
children: <Widget>[
divider,
schemeLabel(
'Light ColorScheme', colorScheme),
schemeLabel('Light ColorScheme', colorScheme),
schemeView(lightTheme),
divider,
divider,
schemeLabel(
'Dark ColorScheme', colorScheme),
schemeLabel('Dark ColorScheme', colorScheme),
schemeView(darkTheme),
],
),
@@ -155,9 +154,7 @@ class _DynamicColorExampleState extends State<DynamicColorExample> {
Expanded(
child: Column(
children: <Widget>[
schemeLabel(
'Light ColorScheme',
colorScheme),
schemeLabel('Light ColorScheme', colorScheme),
schemeView(lightTheme),
],
),
@@ -165,9 +162,7 @@ class _DynamicColorExampleState extends State<DynamicColorExample> {
Expanded(
child: Column(
children: <Widget>[
schemeLabel(
'Dark ColorScheme',
colorScheme),
schemeLabel('Dark ColorScheme', colorScheme),
schemeView(darkTheme),
],
),
@@ -193,8 +188,7 @@ class _DynamicColorExampleState extends State<DynamicColorExample> {
Future<void> _updateImage(ImageProvider provider) async {
final ColorScheme newColorScheme = await ColorScheme.fromImageProvider(
provider: provider,
brightness: isLight ? Brightness.light : Brightness.dark);
provider: provider, brightness: isLight ? Brightness.light : Brightness.dark);
setState(() {
selectedImage = widget.images.indexOf(provider);
currentColorScheme = newColorScheme;
@@ -203,30 +197,25 @@ class _DynamicColorExampleState extends State<DynamicColorExample> {
// For small screens, have two rows of image selection. For wide screens,
// fit them onto one row.
Widget _imagesRow(BuildContext context, List<ImageProvider> images,
ColorScheme colorScheme) {
Widget _imagesRow(BuildContext context, List<ImageProvider> images, ColorScheme colorScheme) {
final double windowHeight = MediaQuery.of(context).size.height;
final double windowWidth = MediaQuery.of(context).size.width;
return Padding(
padding: const EdgeInsets.all(8.0),
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
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),
_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
@@ -268,18 +257,10 @@ class ColorSchemeView extends StatelessWidget {
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: '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),
label: 'primaryContainer', color: colorScheme.primaryContainer, onColor: colorScheme.onPrimaryContainer),
ColorChip(
label: 'onPrimaryContainer',
color: colorScheme.onPrimaryContainer,
@@ -287,14 +268,8 @@ class ColorSchemeView extends StatelessWidget {
]),
divider,
ColorGroup(children: <ColorChip>[
ColorChip(
label: 'secondary',
color: colorScheme.secondary,
onColor: colorScheme.onSecondary),
ColorChip(
label: 'onSecondary',
color: colorScheme.onSecondary,
onColor: colorScheme.secondary),
ColorChip(label: 'secondary', color: colorScheme.secondary, onColor: colorScheme.onSecondary),
ColorChip(label: 'onSecondary', color: colorScheme.onSecondary, onColor: colorScheme.secondary),
ColorChip(
label: 'secondaryContainer',
color: colorScheme.secondaryContainer,
@@ -307,14 +282,8 @@ class ColorSchemeView extends StatelessWidget {
divider,
ColorGroup(
children: <ColorChip>[
ColorChip(
label: 'tertiary',
color: colorScheme.tertiary,
onColor: colorScheme.onTertiary),
ColorChip(
label: 'onTertiary',
color: colorScheme.onTertiary,
onColor: colorScheme.tertiary),
ColorChip(label: 'tertiary', color: colorScheme.tertiary, onColor: colorScheme.onTertiary),
ColorChip(label: 'onTertiary', color: colorScheme.onTertiary, onColor: colorScheme.tertiary),
ColorChip(
label: 'tertiaryContainer',
color: colorScheme.tertiaryContainer,
@@ -328,56 +297,30 @@ class ColorSchemeView extends StatelessWidget {
divider,
ColorGroup(
children: <ColorChip>[
ColorChip(label: 'error', color: colorScheme.error, onColor: colorScheme.onError),
ColorChip(label: 'onError', color: colorScheme.onError, onColor: colorScheme.error),
ColorChip(
label: 'error',
color: colorScheme.error,
onColor: colorScheme.onError),
label: 'errorContainer', color: colorScheme.errorContainer, onColor: colorScheme.onErrorContainer),
ColorChip(
label: 'onError',
color: colorScheme.onError,
onColor: colorScheme.error),
ColorChip(
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: 'background',
color: colorScheme.background,
onColor: colorScheme.onBackground),
ColorChip(
label: 'onBackground',
color: colorScheme.onBackground,
onColor: colorScheme.background),
ColorChip(label: 'background', color: colorScheme.background, onColor: colorScheme.onBackground),
ColorChip(label: 'onBackground', color: colorScheme.onBackground, onColor: colorScheme.background),
],
),
divider,
ColorGroup(
children: <ColorChip>[
ColorChip(label: 'surface', color: colorScheme.surface, onColor: colorScheme.onSurface),
ColorChip(label: 'onSurface', color: colorScheme.onSurface, onColor: colorScheme.surface),
ColorChip(
label: 'surface',
color: colorScheme.surface,
onColor: colorScheme.onSurface),
label: 'surfaceVariant', color: colorScheme.surfaceVariant, onColor: colorScheme.onSurfaceVariant),
ColorChip(
label: 'onSurface',
color: colorScheme.onSurface,
onColor: colorScheme.surface),
ColorChip(
label: 'surfaceVariant',
color: colorScheme.surfaceVariant,
onColor: colorScheme.onSurfaceVariant),
ColorChip(
label: 'onSurfaceVariant',
color: colorScheme.onSurfaceVariant,
onColor: colorScheme.surfaceVariant),
label: 'onSurfaceVariant', color: colorScheme.onSurfaceVariant, onColor: colorScheme.surfaceVariant),
],
),
divider,
@@ -386,17 +329,10 @@ 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),
],
),
],
@@ -412,8 +348,7 @@ class ColorGroup extends StatelessWidget {
@override
Widget build(BuildContext context) {
return RepaintBoundary(
child:
Card(clipBehavior: Clip.antiAlias, child: Column(children: children)),
child: Card(clipBehavior: Clip.antiAlias, child: Column(children: children)),
);
}
}

View File

@@ -9,25 +9,24 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() => runApp(const MyApp());
void main() => runApp(const ContextMenuControllerExampleApp());
/// A builder that includes an Offset to draw the context menu at.
typedef ContextMenuBuilder = Widget Function(BuildContext context, Offset offset);
class MyApp extends StatefulWidget {
const MyApp({super.key});
class ContextMenuControllerExampleApp extends StatefulWidget {
const ContextMenuControllerExampleApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
State<ContextMenuControllerExampleApp> createState() => _ContextMenuControllerExampleAppState();
}
class _MyAppState extends State<MyApp> {
void _showDialog (BuildContext context) {
class _ContextMenuControllerExampleAppState extends State<ContextMenuControllerExampleApp> {
void _showDialog(BuildContext context) {
Navigator.of(context).push(
DialogRoute<void>(
context: context,
builder: (BuildContext context) =>
const AlertDialog(title: Text('You clicked print!')),
builder: (BuildContext context) => const AlertDialog(title: Text('You clicked print!')),
),
);
}
@@ -82,7 +81,8 @@ class _MyAppState extends State<MyApp> {
child: ListView(
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.'),
const Text(
'Right click (desktop) or long press (mobile) anywhere, not just on this text, to show the custom menu.'),
],
),
),

View File

@@ -10,16 +10,16 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() => runApp(const MyApp());
void main() => runApp(const EditableTextToolbarBuilderExampleApp());
class MyApp extends StatefulWidget {
const MyApp({super.key});
class EditableTextToolbarBuilderExampleApp extends StatefulWidget {
const EditableTextToolbarBuilderExampleApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
State<EditableTextToolbarBuilderExampleApp> createState() => _EditableTextToolbarBuilderExampleAppState();
}
class _MyAppState extends State<MyApp> {
class _EditableTextToolbarBuilderExampleAppState extends State<EditableTextToolbarBuilderExampleApp> {
final TextEditingController _controller = TextEditingController(
text: 'Right click (desktop) or long press (mobile) to see the menu with custom buttons.',
);

View File

@@ -9,30 +9,28 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() => runApp(const MyApp());
void main() => runApp(const EditableTextToolbarBuilderExampleApp());
const String emailAddress = 'me@example.com';
const String text = 'Select the email address and open the menu: $emailAddress';
class MyApp extends StatefulWidget {
const MyApp({super.key});
class EditableTextToolbarBuilderExampleApp extends StatefulWidget {
const EditableTextToolbarBuilderExampleApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
State<EditableTextToolbarBuilderExampleApp> createState() => _EditableTextToolbarBuilderExampleAppState();
}
class _MyAppState extends State<MyApp> {
class _EditableTextToolbarBuilderExampleAppState extends State<EditableTextToolbarBuilderExampleApp> {
final TextEditingController _controller = TextEditingController(
text: text,
);
void _showDialog (BuildContext context) {
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!')),
),
);
}
@@ -69,20 +67,22 @@ class _MyAppState extends State<MyApp> {
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.
final TextEditingValue value = _controller.value;
if (_isValidEmail(value.selection.textInside(value.text))) {
buttonItems.insert(0, ContextMenuButtonItem(
label: 'Send email',
onPressed: () {
ContextMenuController.removeAny();
_showDialog(context);
},
));
buttonItems.insert(
0,
ContextMenuButtonItem(
label: 'Send email',
onPressed: () {
ContextMenuController.removeAny();
_showDialog(context);
},
),
);
}
return AdaptiveTextSelectionToolbar.buttonItems(
anchors: editableTextState.contextMenuAnchors,

View File

@@ -9,16 +9,16 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() => runApp(const MyApp());
void main() => runApp(const EditableTextToolbarBuilderExampleApp());
class MyApp extends StatefulWidget {
const MyApp({super.key});
class EditableTextToolbarBuilderExampleApp extends StatefulWidget {
const EditableTextToolbarBuilderExampleApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
State<EditableTextToolbarBuilderExampleApp> createState() => _EditableTextToolbarBuilderExampleAppState();
}
class _MyAppState extends State<MyApp> {
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.',
);

View File

@@ -9,24 +9,24 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() => runApp(const MyApp());
void main() => runApp(const SelectableRegionToolbarBuilderExampleApp());
const String text = 'I am some text inside of SelectionArea. Right click (desktop) or long press (mobile) me to show the customized context menu.';
const String text =
'I am some text inside of SelectionArea. Right click (desktop) or long press (mobile) me to show the customized context menu.';
class MyApp extends StatefulWidget {
const MyApp({super.key});
class SelectableRegionToolbarBuilderExampleApp extends StatefulWidget {
const SelectableRegionToolbarBuilderExampleApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
State<SelectableRegionToolbarBuilderExampleApp> createState() => _SelectableRegionToolbarBuilderExampleAppState();
}
class _MyAppState extends State<MyApp> {
void _showDialog (BuildContext context) {
class _SelectableRegionToolbarBuilderExampleAppState extends State<SelectableRegionToolbarBuilderExampleApp> {
void _showDialog(BuildContext context) {
Navigator.of(context).push(
DialogRoute<void>(
context: context,
builder: (BuildContext context) =>
const AlertDialog(title: Text('You clicked print!')),
builder: (BuildContext context) => const AlertDialog(title: Text('You clicked print!')),
),
);
}

View File

@@ -2,31 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [DataTable].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [DataTable].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const DataTableExampleApp());
static const String _title = 'Flutter Code Sample';
class DataTableExampleApp extends StatelessWidget {
const DataTableExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
appBar: AppBar(title: const Text('DataTable Sample')),
body: const DataTableExample(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class DataTableExample extends StatelessWidget {
const DataTableExample({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,37 +2,34 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [DataTable].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [DataTable].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const DataTableExampleApp());
static const String _title = 'Flutter Code Sample';
class DataTableExampleApp extends StatelessWidget {
const DataTableExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatefulWidget(),
appBar: AppBar(title: const Text('DataTable Sample')),
body: const DataTableExample(),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
class DataTableExample extends StatefulWidget {
const DataTableExample({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<DataTableExample> createState() => _DataTableExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _DataTableExampleState extends State<DataTableExample> {
static const int numItems = 10;
List<bool> selected = List<bool>.generate(numItems, (int index) => false);
@@ -49,8 +46,7 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
rows: List<DataRow>.generate(
numItems,
(int index) => DataRow(
color: MaterialStateProperty.resolveWith<Color?>(
(Set<MaterialState> states) {
color: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) {
// All rows will have the same selected color.
if (states.contains(MaterialState.selected)) {
return Theme.of(context).colorScheme.primary.withOpacity(0.08);

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [showDatePicker].
import 'package:flutter/material.dart';
/// Flutter code sample for [showDatePicker].
void main() => runApp(const DatePickerApp());
class DatePickerApp extends StatelessWidget {
@@ -31,17 +31,14 @@ class DatePickerExample extends StatefulWidget {
}
/// RestorationProperty objects can be used because of RestorationMixin.
class _DatePickerExampleState extends State<DatePickerExample>
with RestorationMixin {
class _DatePickerExampleState extends State<DatePickerExample> with RestorationMixin {
// In this example, the restoration ID for the mixin is passed in through
// the [StatefulWidget]'s constructor.
@override
String? get restorationId => widget.restorationId;
final RestorableDateTime _selectedDate =
RestorableDateTime(DateTime(2021, 7, 25));
late final RestorableRouteFuture<DateTime?> _restorableDatePickerRouteFuture =
RestorableRouteFuture<DateTime?>(
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(
@@ -73,8 +70,7 @@ class _DatePickerExampleState extends State<DatePickerExample>
@override
void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
registerForRestoration(_selectedDate, 'selected_date');
registerForRestoration(
_restorableDatePickerRouteFuture, 'date_picker_route_future');
registerForRestoration(_restorableDatePickerRouteFuture, 'date_picker_route_future');
}
void _selectDate(DateTime? newSelectedDate) {
@@ -82,8 +78,8 @@ class _DatePickerExampleState extends State<DatePickerExample>
setState(() {
_selectedDate.value = newSelectedDate;
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
'Selected: ${_selectedDate.value.day}/${_selectedDate.value.month}/${_selectedDate.value.year}'),
content:
Text('Selected: ${_selectedDate.value.day}/${_selectedDate.value.month}/${_selectedDate.value.year}'),
));
});
}

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [showDateRangePicker].
import 'package:flutter/material.dart';
/// Flutter code sample for [showDateRangePicker].
void main() => runApp(const DatePickerApp());
class DatePickerApp extends StatelessWidget {
@@ -21,7 +21,6 @@ class DatePickerApp extends StatelessWidget {
}
}
class DatePickerExample extends StatefulWidget {
const DatePickerExample({super.key, this.restorationId});
@@ -32,24 +31,19 @@ class DatePickerExample extends StatefulWidget {
}
/// RestorationProperty objects can be used because of RestorationMixin.
class _DatePickerExampleState extends State<DatePickerExample>
with RestorationMixin {
class _DatePickerExampleState extends State<DatePickerExample> with RestorationMixin {
// In this example, the restoration ID for the mixin is passed in through
// the [StatefulWidget]'s constructor.
@override
String? get restorationId => widget.restorationId;
final RestorableDateTimeN _startDate =
RestorableDateTimeN(DateTime(2021));
final RestorableDateTimeN _endDate =
RestorableDateTimeN(DateTime(2021, 1, 5));
late final RestorableRouteFuture<DateTimeRange?>
_restorableDateRangePickerRouteFuture =
final RestorableDateTimeN _startDate = RestorableDateTimeN(DateTime(2021));
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>{
return navigator.restorablePush(_dateRangePickerRoute, arguments: <String, dynamic>{
'initialStartDate': _startDate.value?.millisecondsSinceEpoch,
'initialEndDate': _endDate.value?.millisecondsSinceEpoch,
});
@@ -69,8 +63,7 @@ class _DatePickerExampleState extends State<DatePickerExample>
void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
registerForRestoration(_startDate, 'start_date');
registerForRestoration(_endDate, 'end_date');
registerForRestoration(
_restorableDateRangePickerRouteFuture, 'date_picker_route_future');
registerForRestoration(_restorableDateRangePickerRouteFuture, 'date_picker_route_future');
}
@pragma('vm:entry-point')
@@ -83,8 +76,7 @@ class _DatePickerExampleState extends State<DatePickerExample>
builder: (BuildContext context) {
return DateRangePickerDialog(
restorationId: 'date_picker_dialog',
initialDateRange:
_initialDateTimeRange(arguments! as Map<dynamic, dynamic>),
initialDateRange: _initialDateTimeRange(arguments! as Map<dynamic, dynamic>),
firstDate: DateTime(2021),
currentDate: DateTime(2021, 1, 25),
lastDate: DateTime(2022),
@@ -94,13 +86,10 @@ class _DatePickerExampleState extends State<DatePickerExample>
}
static DateTimeRange? _initialDateTimeRange(Map<dynamic, dynamic> arguments) {
if (arguments['initialStartDate'] != null &&
arguments['initialEndDate'] != null) {
if (arguments['initialStartDate'] != null && arguments['initialEndDate'] != null) {
return DateTimeRange(
start: DateTime.fromMillisecondsSinceEpoch(
arguments['initialStartDate'] as int),
end: DateTime.fromMillisecondsSinceEpoch(
arguments['initialEndDate'] as int),
start: DateTime.fromMillisecondsSinceEpoch(arguments['initialStartDate'] as int),
end: DateTime.fromMillisecondsSinceEpoch(arguments['initialEndDate'] as int),
);
}

View File

@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [AlertDialog].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [AlertDialog].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const AlertDialogExampleApp());
class AlertDialogExampleApp extends StatelessWidget {
const AlertDialogExampleApp({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [AlertDialog].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [AlertDialog].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const AlertDialogExampleApp());
class AlertDialogExampleApp extends StatelessWidget {
const AlertDialogExampleApp({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [Dialog].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [Dialog].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const DialogExampleApp());
class DialogExampleApp extends StatelessWidget {
const DialogExampleApp({super.key});
@override
Widget build(BuildContext context) {
@@ -42,7 +42,7 @@ class DialogExample extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('This is a typical dialog.'),
const Text('This is a typical dialog.'),
const SizedBox(height: 15),
TextButton(
onPressed: () {
@@ -66,7 +66,7 @@ class DialogExample extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('This is a fullscreen dialog.'),
const Text('This is a fullscreen dialog.'),
const SizedBox(height: 15),
TextButton(
onPressed: () {

View File

@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [showDialog].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [showDialog].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const ShowDialogExampleApp());
class ShowDialogExampleApp extends StatelessWidget {
const ShowDialogExampleApp({super.key});
@override
Widget build(BuildContext context) {
@@ -42,10 +42,11 @@ class DialogExample extends StatelessWidget {
return AlertDialog(
title: const Text('Basic dialog title'),
content: const Text(
'A dialog is a type of modal window that\n'
'appears in front of app content to\n'
'provide critical information, or prompt\n'
'for a decision to be made.'),
'A dialog is a type of modal window that\n'
'appears in front of app content to\n'
'provide critical information, or prompt\n'
'for a decision to be made.',
),
actions: <Widget>[
TextButton(
style: TextButton.styleFrom(

View File

@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [showDialog].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [showDialog].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const ShowDialogExampleApp());
class ShowDialogExampleApp extends StatelessWidget {
const ShowDialogExampleApp({super.key});
@override
Widget build(BuildContext context) {
@@ -43,10 +43,11 @@ class DialogExample extends StatelessWidget {
return AlertDialog(
title: const Text('Basic dialog title'),
content: const Text(
'A dialog is a type of modal window that\n'
'appears in front of app content to\n'
'provide critical information, or prompt\n'
'for a decision to be made.'),
'A dialog is a type of modal window that\n'
'appears in front of app content to\n'
'provide critical information, or prompt\n'
'for a decision to be made.',
),
actions: <Widget>[
TextButton(
style: TextButton.styleFrom(

View File

@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [showDialog].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [showDialog].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const ShowDialogExampleApp());
class ShowDialogExampleApp extends StatelessWidget {
const ShowDialogExampleApp({super.key});
@override
Widget build(BuildContext context) {
@@ -39,18 +39,18 @@ class DialogExample extends StatelessWidget {
}
@pragma('vm:entry-point')
static Route<Object?> _dialogBuilder(
BuildContext context, Object? arguments) {
static Route<Object?> _dialogBuilder(BuildContext context, Object? arguments) {
return DialogRoute<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Basic dialog title'),
content: const Text(
'A dialog is a type of modal window that\n'
'appears in front of app content to\n'
'provide critical information, or prompt\n'
'for a decision to be made.'),
'A dialog is a type of modal window that\n'
'appears in front of app content to\n'
'provide critical information, or prompt\n'
'for a decision to be made.',
),
actions: <Widget>[
TextButton(
style: TextButton.styleFrom(

View File

@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [Divider].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [Divider].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const DividerExampleApp());
class DividerExampleApp extends StatelessWidget {
const DividerExampleApp({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [Divider].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [Divider].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const DividerExampleApp());
class DividerExampleApp extends StatelessWidget {
const DividerExampleApp({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [VerticalDivider].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [VerticalDivider].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const VerticalDividerExampleApp());
class VerticalDividerExampleApp extends StatelessWidget {
const VerticalDividerExampleApp({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [Divider].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [Divider].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const VerticalDividerExampleApp());
class VerticalDividerExampleApp extends StatelessWidget {
const VerticalDividerExampleApp({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [DropdownButton].
import 'package:flutter/material.dart';
/// Flutter code sample for [DropdownButton].
const List<String> list = <String>['One', 'Two', 'Three', 'Four'];
void main() => runApp(const DropdownButtonApp());

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [DropdownButton.selectedItemBuilder].
import 'package:flutter/material.dart';
/// Flutter code sample for [DropdownButton.selectedItemBuilder].
Map<String, String> cities = <String, String>{
'New York': 'NYC',
'Los Angeles': 'LA',
@@ -61,7 +61,7 @@ class _DropdownButtonExampleState extends State<DropdownButtonExample> {
// Here custom text style, alignment and layout size can be applied
// to selected item string.
return Container(
alignment:Alignment.centerLeft,
alignment: Alignment.centerLeft,
constraints: const BoxConstraints(minWidth: 100),
child: Text(
item,

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [DropdownButton.style].
import 'package:flutter/material.dart';
/// Flutter code sample for [DropdownButton.style].
void main() => runApp(const DropdownButtonApp());
class DropdownButtonApp extends StatelessWidget {

View File

@@ -2,11 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [DropdownMenu]s. The first dropdown menu has an outlined border
// which is the default configuration, and the second one has a filled input decoration.
import 'package:flutter/material.dart';
/// Flutter code sample for [DropdownMenu]s. The first dropdown menu has an outlined border.
void main() => runApp(const DropdownMenuExample());
class DropdownMenuExample extends StatefulWidget {
@@ -27,7 +28,8 @@ class _DropdownMenuExampleState extends State<DropdownMenuExample> {
final List<DropdownMenuEntry<ColorLabel>> colorEntries = <DropdownMenuEntry<ColorLabel>>[];
for (final ColorLabel color in ColorLabel.values) {
colorEntries.add(
DropdownMenuEntry<ColorLabel>(value: color, label: color.label, enabled: color.label != 'Grey'));
DropdownMenuEntry<ColorLabel>(value: color, label: color.label, enabled: color.label != 'Grey'),
);
}
final List<DropdownMenuEntry<IconLabel>> iconEntries = <DropdownMenuEntry<IconLabel>>[];
@@ -38,7 +40,7 @@ class _DropdownMenuExampleState extends State<DropdownMenuExample> {
return MaterialApp(
theme: ThemeData(
useMaterial3: true,
colorSchemeSeed: Colors.green
colorSchemeSeed: Colors.green,
),
home: Scaffold(
body: SafeArea(
@@ -69,7 +71,8 @@ class _DropdownMenuExampleState extends State<DropdownMenuExample> {
dropdownMenuEntries: iconEntries,
inputDecorationTheme: const InputDecorationTheme(
filled: true,
contentPadding: EdgeInsets.symmetric(vertical: 5.0)),
contentPadding: EdgeInsets.symmetric(vertical: 5.0),
),
onSelected: (IconLabel? icon) {
setState(() {
selectedIcon = icon;
@@ -86,12 +89,17 @@ 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.')
else
const Text('Please select a color and an icon.')
],
)
),
),
),
);
@@ -112,7 +120,10 @@ enum ColorLabel {
enum IconLabel {
smile('Smile', Icons.sentiment_satisfied_outlined),
cloud('Cloud', Icons.cloud_outlined,),
cloud(
'Cloud',
Icons.cloud_outlined,
),
brush('Brush', Icons.brush_outlined),
heart('Heart', Icons.favorite);

View File

@@ -2,41 +2,37 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [ElevatedButton].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [ElevatedButton].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const ElevatedButtonExampleApp());
static const String _title = 'Flutter Code Sample';
class ElevatedButtonExampleApp extends StatelessWidget {
const ElevatedButtonExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatefulWidget(),
appBar: AppBar(title: const Text('ElevatedButton Sample')),
body: const ElevatedButtonExample(),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
class ElevatedButtonExample extends StatefulWidget {
const ElevatedButtonExample({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<ElevatedButtonExample> createState() => _ElevatedButtonExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _ElevatedButtonExampleState extends State<ElevatedButtonExample> {
@override
Widget build(BuildContext context) {
final ButtonStyle style =
ElevatedButton.styleFrom(textStyle: const TextStyle(fontSize: 20));
final ButtonStyle style = ElevatedButton.styleFrom(textStyle: const TextStyle(fontSize: 20));
return Center(
child: Column(

View File

@@ -2,24 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [ExpansionPanelList].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [ExpansionPanelList].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const ExpansionPanelListExampleApp());
static const String _title = 'Flutter Code Sample';
class ExpansionPanelListExampleApp extends StatelessWidget {
const ExpansionPanelListExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatefulWidget(),
appBar: AppBar(title: const Text('ExpansionPanelList Sample')),
body: const ExpansionPanelListExample(),
),
);
}
@@ -47,14 +44,14 @@ List<Item> generateItems(int numberOfItems) {
});
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
class ExpansionPanelListExample extends StatefulWidget {
const ExpansionPanelListExample({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<ExpansionPanelListExample> createState() => _ExpansionPanelListExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _ExpansionPanelListExampleState extends State<ExpansionPanelListExample> {
final List<Item> _data = generateItems(8);
@override
@@ -82,8 +79,7 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
},
body: ListTile(
title: Text(item.expandedValue),
subtitle:
const Text('To delete this panel, tap the trash can icon'),
subtitle: const Text('To delete this panel, tap the trash can icon'),
trailing: const Icon(Icons.delete),
onTap: () {
setState(() {

View File

@@ -2,24 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [ExpansionPanelList.ExpansionPanelList.radio].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [ExpansionPanelList.ExpansionPanelList.radio].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const ExpansionPanelListRadioExampleApp());
static const String _title = 'Flutter Code Sample';
class ExpansionPanelListRadioExampleApp extends StatelessWidget {
const ExpansionPanelListRadioExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatefulWidget(),
appBar: AppBar(title: const Text('ExpansionPanelList.radio Sample')),
body: const ExpansionPanelListRadioExample(),
),
);
}
@@ -48,14 +45,14 @@ List<Item> generateItems(int numberOfItems) {
});
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
class ExpansionPanelListRadioExample extends StatefulWidget {
const ExpansionPanelListRadioExample({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<ExpansionPanelListRadioExample> createState() => _ExpansionPanelListRadioExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _ExpansionPanelListRadioExampleState extends State<ExpansionPanelListRadioExample> {
final List<Item> _data = generateItems(8);
@override
@@ -80,13 +77,11 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
},
body: ListTile(
title: Text(item.expandedValue),
subtitle:
const Text('To delete this panel, tap the trash can icon'),
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);
_data.removeWhere((Item currentItem) => item == currentItem);
});
}));
}).toList(),

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [ExpansionTile].
import 'package:flutter/material.dart';
/// Flutter code sample for [ExpansionTile].
void main() => runApp(const ExpansionTileApp());
class ExpansionTileApp extends StatelessWidget {
@@ -48,9 +48,7 @@ class _ExpansionTileExampleState extends State<ExpansionTileExample> {
title: const Text('ExpansionTile 2'),
subtitle: const Text('Custom expansion arrow icon'),
trailing: Icon(
_customTileExpanded
? Icons.arrow_drop_down_circle
: Icons.arrow_drop_down,
_customTileExpanded ? Icons.arrow_drop_down_circle : Icons.arrow_drop_down,
),
children: const <Widget>[
ListTile(title: Text('This is tile number 2')),

View File

@@ -2,16 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [ExpansionTile] and [ExpansionTileController]
import 'package:flutter/material.dart';
/// Flutter code sample for [ExpansionTile] and [ExpansionTileController].
void main() {
runApp(const ExpansionTileControllerApp());
}
class ExpansionTileControllerApp extends StatefulWidget {
const ExpansionTileControllerApp({ super.key });
const ExpansionTileControllerApp({super.key});
@override
State<ExpansionTileControllerApp> createState() => _ExpansionTileControllerAppState();
@@ -23,10 +23,9 @@ class _ExpansionTileControllerAppState extends State<ExpansionTileControllerApp>
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Code Sample for ExpansionTileController.',
theme: ThemeData(useMaterial3: true),
home: Scaffold(
appBar: AppBar(title: const Text('ExpansionTileController Example')),
appBar: AppBar(title: const Text('ExpansionTileController Sample')),
body: Column(
children: <Widget>[
// A controller has been provided to the ExpansionTile because it's

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [FilledButton].
import 'package:flutter/material.dart';
/// Flutter code sample for [FilledButton].
void main() {
runApp(const FilledButtonApp());
}

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [FilterChip].
import 'package:flutter/material.dart';
/// Flutter code sample for [FilterChip].
enum ExerciseFilter { walking, running, cycling, hiking }
void main() => runApp(const ChipApp());
@@ -67,8 +67,7 @@ class _FilterChipExampleState extends State<FilterChipExample> {
),
const SizedBox(height: 10.0),
Text(
'Looking for: ${filters.map(
(ExerciseFilter e) => e.name).join(', ')}',
'Looking for: ${filters.map((ExerciseFilter e) => e.name).join(', ')}',
style: textTheme.labelLarge,
),
],

View File

@@ -2,21 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [FlexibleSpaceBar].
import 'package:flutter/material.dart';
void main() => runApp(const MaterialApp(home: MyApp()));
/// Flutter code sample for [FlexibleSpaceBar].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const MaterialApp(home: FlexibleSpaceBarExampleApp()));
class FlexibleSpaceBarExampleApp extends StatelessWidget {
const FlexibleSpaceBarExampleApp({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
physics: const BouncingScrollPhysics(
parent: AlwaysScrollableScrollPhysics()),
physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
slivers: <Widget>[
SliverAppBar(
stretch: true,

View File

@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [FloatingActionButton].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [FloatingActionButton].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const FloatingActionButtonExampleApp());
class FloatingActionButtonExampleApp extends StatelessWidget {
const FloatingActionButtonExampleApp({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [FloatingActionButton].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [FloatingActionButton].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const FloatingActionButtonExampleApp());
class FloatingActionButtonExampleApp extends StatelessWidget {
const FloatingActionButtonExampleApp({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [FloatingActionButton].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [FloatingActionButton].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const FloatingActionButtonExampleApp());
class FloatingActionButtonExampleApp extends StatelessWidget {
const FloatingActionButtonExampleApp({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [FloatingActionButton].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [FloatingActionButton].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const FloatingActionButtonExampleApp());
class FloatingActionButtonExampleApp extends StatelessWidget {
const FloatingActionButtonExampleApp({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,40 +2,33 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [StandardFabLocation].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [StandardFabLocation].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const StandardFabLocationExampleApp());
static const String _title = 'Flutter Code Sample';
class StandardFabLocationExampleApp extends StatelessWidget {
const StandardFabLocationExampleApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyStatelessWidget(),
home: StandardFabLocationExample(),
);
}
}
class AlmostEndFloatFabLocation extends StandardFabLocation
with FabEndOffsetX, FabFloatOffsetY {
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;
return super.getOffsetX(scaffoldGeometry, adjustment) +
directionalAdjustment;
double getOffsetX(ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment) {
final double directionalAdjustment = scaffoldGeometry.textDirection == TextDirection.ltr ? -50.0 : 50.0;
return super.getOffsetX(scaffoldGeometry, adjustment) + directionalAdjustment;
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class StandardFabLocationExample extends StatelessWidget {
const StandardFabLocationExample({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,25 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [IconButton].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [IconButton].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const IconButtonExampleApp());
static const String _title = 'Flutter Code Sample';
class IconButtonExampleApp extends StatelessWidget {
const IconButtonExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
appBar: AppBar(title: const Text('IconButton Sample')),
body: const Center(
child: MyStatefulWidget(),
child: IconButtonExample(),
),
),
);
@@ -29,14 +26,14 @@ class MyApp extends StatelessWidget {
double _volume = 0.0;
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
class IconButtonExample extends StatefulWidget {
const IconButtonExample({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<IconButtonExample> createState() => _IconButtonExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _IconButtonExampleState extends State<IconButtonExample> {
@override
Widget build(BuildContext context) {
return Column(

View File

@@ -2,31 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [IconButton].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [IconButton].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const IconButtonExampleApp());
static const String _title = 'Flutter Code Sample';
class IconButtonExampleApp extends StatelessWidget {
const IconButtonExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
appBar: AppBar(title: const Text('IconButton Sample')),
body: const IconButtonExample(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class IconButtonExample extends StatelessWidget {
const IconButtonExample({super.key});
@override
@override

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [IconButton].
import 'package:flutter/material.dart';
/// Flutter code sample for [IconButton].
void main() {
runApp(const IconButtonApp());
}
@@ -45,7 +45,7 @@ class ButtonTypesExample extends StatelessWidget {
}
class ButtonTypesGroup extends StatelessWidget {
const ButtonTypesGroup({ super.key, required this.enabled });
const ButtonTypesGroup({super.key, required this.enabled});
final bool enabled;

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [IconButton] with toggle feature.
import 'package:flutter/material.dart';
/// Flutter code sample for [IconButton] with toggle feature.
void main() {
runApp(const IconButtonToggleApp());
}
@@ -134,7 +134,7 @@ class _DemoIconToggleButtonsState extends State<DemoIconToggleButtons> {
),
],
),
]
],
);
}
}

View File

@@ -2,26 +2,27 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [Image.frameBuilder].
import 'package:flutter/material.dart';
/// Flutter code sample for [Image.frameBuilder].
void main() {
runApp(MaterialApp(
title: 'Flutter Code Sample',
home: Scaffold(
appBar: AppBar(title: const Text('Flutter Code Sample')),
body: const Center(
child: MyStatelessWidget(
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 MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key, required this.image});
class ImageClipExample extends StatelessWidget {
const ImageClipExample({super.key, required this.image});
final ImageProvider image;

View File

@@ -2,17 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [Image.frameBuilder].
import 'package:flutter/material.dart';
/// Flutter code sample for [Image.frameBuilder].
void main() {
runApp(MaterialApp(
title: 'Flutter Code Sample',
home: Scaffold(
appBar: AppBar(title: const Text('Flutter Code Sample')),
appBar: AppBar(title: const Text('Image.frameBuilder Sample')),
body: const Center(
child: MyStatelessWidget(
child: ImageClipExample(
image: NetworkImage('https://flutter.github.io/assets-for-api-docs/assets/widgets/puffin.jpg'),
),
),
@@ -20,8 +19,8 @@ void main() {
));
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key, required this.image});
class ImageClipExample extends StatelessWidget {
const ImageClipExample({super.key, required this.image});
final ImageProvider image;

View File

@@ -2,39 +2,36 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [InkWell].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [InkWell].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const InkWellExampleApp());
static const String _title = 'Flutter Code Sample';
class InkWellExampleApp extends StatelessWidget {
const InkWellExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
appBar: AppBar(title: const Text('InkWell Sample')),
body: const Center(
child: MyStatefulWidget(),
child: InkWellExample(),
),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
class InkWellExample extends StatefulWidget {
const InkWellExample({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<InkWellExample> createState() => _InkWellExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _InkWellExampleState extends State<InkWellExample> {
double sideLength = 50;
@override

View File

@@ -2,31 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [InputDecoration].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [InputDecoration].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const InputDecorationExampleApp());
static const String _title = 'Flutter Code Sample';
class InputDecorationExampleApp extends StatelessWidget {
const InputDecorationExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
appBar: AppBar(title: const Text('InputDecoration Sample')),
body: const InputDecorationExample(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class InputDecorationExample extends StatelessWidget {
const InputDecorationExample({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,31 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [InputDecoration].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [InputDecoration].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const InputDecorationExampleApp());
static const String _title = 'Flutter Code Sample';
class InputDecorationExampleApp extends StatelessWidget {
const InputDecorationExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
appBar: AppBar(title: const Text('InputDecoration Sample')),
body: const InputDecorationExample(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class InputDecorationExample extends StatelessWidget {
const InputDecorationExample({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,31 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [InputDecoration].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [InputDecoration].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const InputDecorationExampleApp());
static const String _title = 'Flutter Code Sample';
class InputDecorationExampleApp extends StatelessWidget {
const InputDecorationExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
appBar: AppBar(title: const Text('InputDecoration Sample')),
body: const InputDecorationExample(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class InputDecorationExample extends StatelessWidget {
const InputDecorationExample({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,31 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [InputDecoration].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [InputDecoration].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const InputDecorationExampleApp());
static const String _title = 'Flutter Code Sample';
class InputDecorationExampleApp extends StatelessWidget {
const InputDecorationExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
appBar: AppBar(title: const Text('InputDecoration Sample')),
body: const InputDecorationExample(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class InputDecorationExample extends StatelessWidget {
const InputDecorationExample({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,23 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [InputDecorator].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [InputDecorator].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const FloatingLabelStyleErrorExampleApp());
static const String _title = 'Flutter Code Sample';
class FloatingLabelStyleErrorExampleApp extends StatelessWidget {
const FloatingLabelStyleErrorExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
appBar: AppBar(title: const Text('InputDecorator Sample')),
body: const Center(
child: InputDecoratorExample(),
),
@@ -41,9 +38,10 @@ class InputDecoratorExample extends StatelessWidget {
// is in its error state.
floatingLabelStyle: MaterialStateTextStyle.resolveWith(
(Set<MaterialState> states) {
final Color color = states.contains(MaterialState.error) ? Theme.of(context).colorScheme.error: Colors.orange;
final Color color =
states.contains(MaterialState.error) ? Theme.of(context).colorScheme.error : Colors.orange;
return TextStyle(color: color, letterSpacing: 1.3);
}
},
),
),
validator: (String? value) {

View File

@@ -2,31 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [InputDecoration.label].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [InputDecoration.label].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const LabelExampleApp());
static const String _title = 'Flutter Code Sample';
class LabelExampleApp extends StatelessWidget {
const LabelExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
appBar: AppBar(title: const Text('InputDecoration.label Sample')),
body: const LabelExample(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class LabelExample extends StatelessWidget {
const LabelExample({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,23 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [InputDecorator].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [InputDecorator].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const LabelStyleErrorExampleApp());
static const String _title = 'Flutter Code Sample';
class LabelStyleErrorExampleApp extends StatelessWidget {
const LabelStyleErrorExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
appBar: AppBar(title: const Text('InputDecorator Sample')),
body: const Center(
child: InputDecoratorExample(),
),
@@ -41,9 +38,10 @@ class InputDecoratorExample extends StatelessWidget {
// is in its error state.
labelStyle: MaterialStateTextStyle.resolveWith(
(Set<MaterialState> states) {
final Color color = states.contains(MaterialState.error) ? Theme.of(context).colorScheme.error: Colors.orange;
final Color color =
states.contains(MaterialState.error) ? Theme.of(context).colorScheme.error : Colors.orange;
return TextStyle(color: color, letterSpacing: 1.3);
}
},
),
),
validator: (String? value) {

View File

@@ -2,31 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [InputDecoration].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [InputDecoration].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const MaterialStateExampleApp());
static const String _title = 'Flutter Code Sample';
class MaterialStateExampleApp extends StatelessWidget {
const MaterialStateExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
appBar: AppBar(title: const Text('InputDecoration Sample')),
body: const MaterialStateExample(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class MaterialStateExample extends StatelessWidget {
const MaterialStateExample({super.key});
@override
Widget build(BuildContext context) {
@@ -37,7 +34,8 @@ class MyStatelessWidget extends StatelessWidget {
prefixIconColor: MaterialStateColor.resolveWith((Set<MaterialState> states) {
if (states.contains(MaterialState.focused)) {
return Colors.green;
} if (states.contains(MaterialState.error)) {
}
if (states.contains(MaterialState.error)) {
return Colors.red;
}
return Colors.grey;

View File

@@ -2,31 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [InputDecoration].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [InputDecoration].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const MaterialStateExampleApp());
static const String _title = 'Flutter Code Sample';
class MaterialStateExampleApp extends StatelessWidget {
const MaterialStateExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
appBar: AppBar(title: const Text('InputDecoration Sample')),
body: const MaterialStateExample(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class MaterialStateExample extends StatelessWidget {
const MaterialStateExample({super.key});
@override
Widget build(BuildContext context) {
@@ -34,15 +31,18 @@ class MyStatelessWidget extends StatelessWidget {
return Theme(
data: themeData.copyWith(
inputDecorationTheme: themeData.inputDecorationTheme.copyWith(
prefixIconColor: MaterialStateColor.resolveWith((Set<MaterialState> states) {
if (states.contains(MaterialState.focused)) {
return Colors.green;
} if (states.contains(MaterialState.error)) {
return Colors.red;
}
return Colors.grey;
}),
)
prefixIconColor: MaterialStateColor.resolveWith(
(Set<MaterialState> states) {
if (states.contains(MaterialState.focused)) {
return Colors.green;
}
if (states.contains(MaterialState.error)) {
return Colors.red;
}
return Colors.grey;
},
),
),
),
child: TextFormField(
initialValue: 'abc',

View File

@@ -2,19 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [InputDecorator].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [InputDecorator].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const PrefixIconExampleApp());
class PrefixIconExampleApp extends StatelessWidget {
const PrefixIconExampleApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Input Decorator Sample',
home: Scaffold(body: InputDecoratorExample()),
);
}

View File

@@ -2,31 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [InputDecoration.prefixIconConstraints].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [InputDecoration.prefixIconConstraints].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const PrefixIconConstraintsExampleApp());
static const String _title = 'Flutter Code Sample';
class PrefixIconConstraintsExampleApp extends StatelessWidget {
const PrefixIconConstraintsExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
appBar: AppBar(title: const Text('InputDecoration Sample')),
body: const PrefixIconConstraintsExample(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class PrefixIconConstraintsExample extends StatelessWidget {
const PrefixIconConstraintsExample({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,19 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [InputDecorator].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [InputDecorator].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const SuffixIconExampleApp());
class SuffixIconExampleApp extends StatelessWidget {
const SuffixIconExampleApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Input Decorator Sample',
home: Scaffold(body: InputDecoratorExample()),
);
}

View File

@@ -2,31 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [InputDecoration.suffixIconConstraints].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [InputDecoration.suffixIconConstraints].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const SuffixIconConstraintsExampleApp());
static const String _title = 'Flutter Code Sample';
class SuffixIconConstraintsExampleApp extends StatelessWidget {
const SuffixIconConstraintsExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
appBar: AppBar(title: const Text('InputDecoration Sample')),
body: const SuffixIconConstraintsExample(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class SuffixIconConstraintsExample extends StatelessWidget {
const SuffixIconConstraintsExample({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for custom list items.
import 'package:flutter/material.dart';
/// Flutter code sample for custom list items.
void main() => runApp(const CustomListItemApp());
class CustomListItemApp extends StatelessWidget {

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for custom list items.
import 'package:flutter/material.dart';
/// Flutter code sample for custom list items.
void main() => runApp(const CustomListItemApp());
class CustomListItemApp extends StatelessWidget {

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [ListTile].
import 'package:flutter/material.dart';
/// Flutter code sample for [ListTile].
void main() => runApp(const ListTileApp());
class ListTileApp extends StatelessWidget {
@@ -86,8 +86,9 @@ class _LisTileExampleState extends State<LisTileExample> with TickerProviderStat
subtitle: const Text('Tap here for Hero transition'),
tileColor: Colors.cyan,
onTap: () {
Navigator.push(context, MaterialPageRoute<Widget>(
builder: (BuildContext context) {
Navigator.push(
context,
MaterialPageRoute<Widget>(builder: (BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('ListTile Hero')),
body: Center(

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [ListTile].
import 'package:flutter/material.dart';
/// Flutter code sample for [ListTile].
void main() => runApp(const ListTileApp());
class ListTileApp extends StatelessWidget {
@@ -67,9 +67,7 @@ class LisTileExample extends StatelessWidget {
child: ListTile(
leading: FlutterLogo(size: 72.0),
title: Text('Three-line ListTile'),
subtitle: Text(
'A sufficiently long subtitle warrants three lines.'
),
subtitle: Text('A sufficiently long subtitle warrants three lines.'),
trailing: Icon(Icons.more_vert),
isThreeLine: true,
),

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [ListTile].
import 'package:flutter/material.dart';
/// Flutter code sample for [ListTile].
void main() => runApp(const ListTileApp());
class ListTileApp extends StatelessWidget {
@@ -30,29 +30,25 @@ class ListTileExample extends StatelessWidget {
body: ListView(
children: const <Widget>[
ListTile(
leading: CircleAvatar(
child: Text('A')
),
leading: CircleAvatar(child: Text('A')),
title: Text('Headline'),
subtitle: Text('Supporting text'),
trailing: Icon(Icons.favorite_rounded),
),
Divider(height: 0),
ListTile(
leading: CircleAvatar(
child: Text('B')
),
leading: CircleAvatar(child: Text('B')),
title: Text('Headline'),
subtitle: Text('Longer supporting text to demonstrate how the text wraps and how the leading and trailing widgets are centered vertically with the text.'),
subtitle: Text(
'Longer supporting text to demonstrate how the text wraps and how the leading and trailing widgets are centered vertically with the text.'),
trailing: Icon(Icons.favorite_rounded),
),
Divider(height: 0),
ListTile(
leading: CircleAvatar(
child: Text('C')
),
leading: CircleAvatar(child: Text('C')),
title: Text('Headline'),
subtitle: Text("Longer supporting text to demonstrate how the text wraps and how setting 'ListTile.isThreeLine = true' aligns leading and trailing widgets to the top vertically with the text."),
subtitle: Text(
"Longer supporting text to demonstrate how the text wraps and how setting 'ListTile.isThreeLine = true' aligns leading and trailing widgets to the top vertically with the text."),
trailing: Icon(Icons.favorite_rounded),
isThreeLine: true,
),

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [ListTile].
import 'package:flutter/material.dart';
/// Flutter code sample for [ListTile].
void main() => runApp(const ListTileApp());
class ListTileApp extends StatelessWidget {

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [ListTile].
import 'package:flutter/material.dart';
/// Flutter code sample for [ListTile].
void main() => runApp(const ListTileApp());
class ListTileApp extends StatelessWidget {
@@ -41,10 +41,11 @@ class _ListTileExampleState extends State<ListTileExample> {
titleAlignment: titleAlignment,
leading: Checkbox(
value: true,
onChanged:(bool? value) { },
onChanged: (bool? value) {},
),
title: const Text('Headline Text'),
subtitle: const Text('Tapping on the trailing widget will show a menu that allows you to change the title alignment. The title alignment is set to threeLine by default if `ThemeData.useMaterial3` is true. Otherwise, defaults to titleHeight.'),
subtitle: const Text(
'Tapping on the trailing widget will show a menu that allows you to change the title alignment. The title alignment is set to threeLine by default if `ThemeData.useMaterial3` is true. Otherwise, defaults to titleHeight.'),
trailing: PopupMenuButton<ListTileTitleAlignment>(
onSelected: (ListTileTitleAlignment? value) {
setState(() {

View File

@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [ListTile.selected].
import 'package:flutter/material.dart';
/// Flutter code sample for [ListTile.selected].
void main() => runApp(const ListTileApp());
class ListTileApp extends StatelessWidget {
@@ -19,6 +19,7 @@ class ListTileApp extends StatelessWidget {
);
}
}
class LisTileExample extends StatefulWidget {
const LisTileExample({super.key});

View File

@@ -2,39 +2,36 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [MaterialStateBorderSide].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// Flutter code sample for [MaterialStateBorderSide].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const MaterialStateBorderSideExampleApp());
static const String _title = 'Flutter Code Sample';
class MaterialStateBorderSideExampleApp extends StatelessWidget {
const MaterialStateBorderSideExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
appBar: AppBar(title: const Text('MaterialStateBorderSide Sample')),
body: const Center(
child: MyStatefulWidget(),
child: MaterialStateBorderSideExample(),
),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
class MaterialStateBorderSideExample extends StatefulWidget {
const MaterialStateBorderSideExample({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<MaterialStateBorderSideExample> createState() => _MaterialStateBorderSideExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _MaterialStateBorderSideExampleState extends State<MaterialStateBorderSideExample> {
bool isSelected = true;
@override

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