Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- novelforge-project/docs/project_enhancement_completion_report.pdf+2-2
- novelforge-project/flutter/examples/api/android/build.gradleAdded+33
- novelforge-project/flutter/examples/api/android/gradle.propertiesAdded+3
- novelforge-project/flutter/examples/api/android/settings.gradleAdded+15
- novelforge-project/flutter/examples/api/ios/PodfileAdded+41
- novelforge-project/flutter/examples/api/lib/material/about/about_list_tile.0.dartAdded+81
- novelforge-project/flutter/examples/api/lib/material/action_buttons/action_icon_theme.0.dartAdded+121
- novelforge-project/flutter/examples/api/lib/material/action_chip/action_chip.0.dartAdded+52
- novelforge-project/flutter/examples/api/lib/material/animated_icon/animated_icon.0.dartAdded+72
- novelforge-project/flutter/examples/api/lib/material/animated_icon/animated_icons_data.0.dartAdded+105
- novelforge-project/flutter/examples/api/lib/material/app/app.0.dartAdded+87
- novelforge-project/flutter/examples/api/lib/material/app_bar/app_bar.0.dartAdded+69
- novelforge-project/flutter/examples/api/lib/material/app_bar/app_bar.1.dartAdded+124
- novelforge-project/flutter/examples/api/lib/material/app_bar/app_bar.2.dartAdded+47
- novelforge-project/flutter/examples/api/lib/material/app_bar/app_bar.3.dartAdded+112
- novelforge-project/flutter/examples/api/lib/material/app_bar/app_bar.4.dartAdded+149
- novelforge-project/flutter/examples/api/lib/material/app_bar/sliver_app_bar.1.dartAdded+132
- novelforge-project/flutter/examples/api/lib/material/app_bar/sliver_app_bar.2.dartAdded+53
- novelforge-project/flutter/examples/api/lib/material/app_bar/sliver_app_bar.3.dartAdded+53
- novelforge-project/flutter/examples/api/lib/material/app_bar/sliver_app_bar.4.dartAdded+90
- novelforge-project/flutter/examples/api/lib/material/autocomplete/autocomplete.0.dartAdded+60
- novelforge-project/flutter/examples/api/lib/material/autocomplete/autocomplete.1.dartAdded+90
- novelforge-project/flutter/examples/api/lib/material/autocomplete/autocomplete.2.dartAdded+95
- novelforge-project/flutter/examples/api/lib/material/autocomplete/autocomplete.3.dartAdded+172
- novelforge-project/flutter/examples/api/lib/material/autocomplete/autocomplete.4.dartAdded+234
- novelforge-project/flutter/examples/api/lib/material/badge/badge.0.dartAdded+54
- novelforge-project/flutter/examples/api/lib/material/banner/material_banner.0.dartAdded+49
- novelforge-project/flutter/examples/api/lib/material/banner/material_banner.1.dartAdded+52
- novelforge-project/flutter/examples/api/lib/material/bottom_app_bar/bottom_app_bar.1.dartAdded+157
- novelforge-project/flutter/examples/api/lib/material/bottom_app_bar/bottom_app_bar.2.dartAdded+192
- novelforge-project/flutter/examples/api/lib/material/bottom_navigation_bar/bottom_navigation_bar.0.dartAdded+83
- novelforge-project/flutter/examples/api/lib/material/bottom_navigation_bar/bottom_navigation_bar.1.dartAdded+95
- novelforge-project/flutter/examples/api/lib/material/bottom_navigation_bar/bottom_navigation_bar.2.dartAdded+109
- novelforge-project/flutter/examples/api/lib/material/bottom_sheet/show_bottom_sheet.0.dartAdded+101
- novelforge-project/flutter/examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.0.dartAdded+60
- novelforge-project/flutter/examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.1.dartAdded+63
- novelforge-project/flutter/examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.2.dartAdded+101
- novelforge-project/flutter/examples/api/lib/material/button_style/button_style.0.dartAdded+69
- novelforge-project/flutter/examples/api/lib/material/button_style_button/button_style_button.icon_alignment.0.dartAdded+147
- novelforge-project/flutter/examples/api/lib/material/card/card.0.dartAdded+60
- novelforge-project/flutter/examples/api/lib/material/card/card.1.dartAdded+51
- novelforge-project/flutter/examples/api/lib/material/card/card.2.dartAdded+48
- novelforge-project/flutter/examples/api/lib/material/carousel/carousel.0.dartAdded+77
- novelforge-project/flutter/examples/api/lib/material/checkbox/checkbox.0.dartAdded+62
- novelforge-project/flutter/examples/api/lib/material/checkbox/checkbox.1.dartAdded+72
- novelforge-project/flutter/examples/api/lib/material/checkbox_list_tile/checkbox_list_tile.0.dartAdded+50
- novelforge-project/flutter/examples/api/lib/material/checkbox_list_tile/checkbox_list_tile.1.dartAdded+81
- novelforge-project/flutter/examples/api/lib/material/checkbox_list_tile/custom_labeled_checkbox.0.dartAdded+100
- novelforge-project/flutter/examples/api/lib/material/checkbox_list_tile/custom_labeled_checkbox.1.dartAdded+89
- novelforge-project/flutter/examples/api/lib/material/chip/chip_attributes.avatar_box_constraints.0.dartAdded+75
123version https://git-lfs.github.com/spec/v1oid sha256:d3fd8415d7c16da731f6e162f118ffcee140b50d4ab5405250aa2e8127b758a3size 794208123version https://git-lfs.github.com/spec/v1oid sha256:6101489c4f2564d988289bbf5c6bbcb69a460a07a788f9d8cebf2ab3645a73e8size 131
123456789101112131415161718192021222324252627282930313233// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
buildscript { ext.kotlin_version = '1.6.10' repositories { google() mavenCentral() }
dependencies { classpath 'com.android.tools.build:gradle:7.2.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" }}
allprojects { repositories { google() mavenCentral() }}
rootProject.buildDir = '../build'subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" project.evaluationDependsOn(':app')}
tasks.register("clean", Delete) { delete rootProject.buildDir}123org.gradle.jvmargs=-Xmx4Gandroid.useAndroidX=trueandroid.enableJetifier=true123456789101112131415// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
include ':app'
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")def properties = new Properties()
assert localPropertiesFile.exists()localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
def flutterSdkPath = properties.getProperty("flutter.sdk")assert flutterSdkPath != null, "flutter.sdk not set in local.properties"apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"1234567891011121314151617181920212223242526272829303132333435363738394041# Uncomment this line to define a global platform for your project# platform :ios, '12.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.ENV['COCOAPODS_DISABLE_STATS'] = 'true'
project 'Runner', { 'Debug' => :debug, 'Profile' => :release, 'Release' => :release,}
def flutter_root generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) unless File.exist?(generated_xcode_build_settings_path) raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" end
File.foreach(generated_xcode_build_settings_path) do |line| matches = line.match(/FLUTTER_ROOT\=(.*)/) return matches[1].strip if matches end raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"end
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
flutter_ios_podfile_setup
target 'Runner' do use_frameworks! use_modular_headers!
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))end
post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) endend123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [AboutListTile].
void main() => runApp(const AboutListTileExampleApp());
class AboutListTileExampleApp extends StatelessWidget { const AboutListTileExampleApp({super.key});
@override Widget build(BuildContext context) { return const MaterialApp( home: AboutListTileExample(), ); }}
class AboutListTileExample extends StatelessWidget { const AboutListTileExample({super.key});
@override Widget build(BuildContext context) { final ThemeData theme = Theme.of(context); final TextStyle textStyle = theme.textTheme.bodyMedium!; final List<Widget> aboutBoxChildren = <Widget>[ const SizedBox(height: 24), RichText( text: TextSpan( children: <TextSpan>[ TextSpan( style: textStyle, text: "Flutter is Google's UI toolkit for building beautiful, " 'natively compiled applications for mobile, web, and desktop ' 'from a single codebase. Learn more about Flutter at '), TextSpan(style: textStyle.copyWith(color: theme.colorScheme.primary), text: 'https://flutter.dev'), TextSpan(style: textStyle, text: '.'), ], ), ), ];
return Scaffold( appBar: AppBar( title: const Text('Show About Example'), ), drawer: Drawer( child: SingleChildScrollView( child: SafeArea( child: AboutListTile( icon: const Icon(Icons.info), applicationIcon: const FlutterLogo(), applicationName: 'Show About Example', applicationVersion: 'August 2019', applicationLegalese: '\u{a9} 2014 The Flutter Authors', aboutBoxChildren: aboutBoxChildren, ), ), ), ), body: Center( child: ElevatedButton( child: const Text('Show About Example'), onPressed: () { showAboutDialog( context: context, applicationIcon: const FlutterLogo(), applicationName: 'Show About Example', applicationVersion: 'August 2019', applicationLegalese: '\u{a9} 2014 The Flutter Authors', children: aboutBoxChildren, ); }, ), ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [ActionIconTheme].
void main() { runApp(const ActionIconThemeExampleApp());}
class _CustomEndDrawerIcon extends StatelessWidget { const _CustomEndDrawerIcon();
@override Widget build(BuildContext context) { final MaterialLocalizations localization = MaterialLocalizations.of(context); return Icon( Icons.more_horiz, semanticLabel: localization.openAppDrawerTooltip, ); }}
class _CustomDrawerIcon extends StatelessWidget { const _CustomDrawerIcon();
@override Widget build(BuildContext context) { final MaterialLocalizations localization = MaterialLocalizations.of(context); return Icon( Icons.segment, semanticLabel: localization.openAppDrawerTooltip, ); }}
class ActionIconThemeExampleApp extends StatelessWidget { const ActionIconThemeExampleApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, theme: ThemeData( useMaterial3: true, actionIconTheme: ActionIconThemeData( backButtonIconBuilder: (BuildContext context) { return const Icon(Icons.arrow_back_ios_new_rounded); }, drawerButtonIconBuilder: (BuildContext context) { return const _CustomDrawerIcon(); }, endDrawerButtonIconBuilder: (BuildContext context) { return const _CustomEndDrawerIcon(); }, ), ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); }}
class MyHomePage extends StatelessWidget { const MyHomePage({super.key, required this.title});
final String title;
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(title), ), drawer: Drawer( child: Column( children: <Widget>[ TextButton(child: const Text('Drawer Item'), onPressed: () {}), ], ), ), body: const Center( child: NextPageButton(), ), ); }}
class NextPageButton extends StatelessWidget { const NextPageButton({super.key});
@override Widget build(BuildContext context) { return ElevatedButton.icon( onPressed: () { Navigator.of(context).push( MaterialPageRoute<MySecondPage>(builder: (BuildContext context) { return const MySecondPage(); }), ); }, icon: const Icon(Icons.arrow_forward), label: const Text('Next page'), ); }}
class MySecondPage extends StatelessWidget { const MySecondPage({super.key});
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Second page'), ), endDrawer: const Drawer(), ); }}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
// Flutter code sample [ActionChip].
import 'package:flutter/material.dart';
void main() => runApp(const ChipApp());
class ChipApp extends StatelessWidget { const ChipApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData(colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true), home: const ActionChipExample(), ); }}
class ActionChipExample extends StatefulWidget { const ActionChipExample({super.key});
@override State<ActionChipExample> createState() => _ActionChipExampleState();}
class _ActionChipExampleState extends State<ActionChipExample> { bool favorite = false;
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('ActionChip Sample'), ), body: Center( child: ActionChip( avatar: Icon(favorite ? Icons.favorite : Icons.favorite_border), label: const Text('Save to favorites'), onPressed: () { setState(() { favorite = !favorite; }); }, ), ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [AnimatedIcon].
void main() { runApp(const AnimatedIconApp());}
class AnimatedIconApp extends StatelessWidget { const AnimatedIconApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData( colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true, ), home: const Scaffold( body: AnimatedIconExample(), ), ); }}
class AnimatedIconExample extends StatefulWidget { const AnimatedIconExample({super.key});
@override State<AnimatedIconExample> createState() => _AnimatedIconExampleState();}
class _AnimatedIconExampleState extends State<AnimatedIconExample> with SingleTickerProviderStateMixin { late AnimationController controller; late Animation<double> animation;
@override void initState() { super.initState(); controller = AnimationController( vsync: this, duration: const Duration(seconds: 2), ) ..forward() ..repeat(reverse: true); animation = Tween<double>(begin: 0.0, end: 1.0).animate(controller); }
@override void dispose() { controller.dispose(); super.dispose(); }
@override Widget build(BuildContext context) { return Scaffold( body: Center( child: AnimatedIcon( icon: AnimatedIcons.menu_arrow, progress: animation, size: 72.0, semanticLabel: 'Show menu', ), ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
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, 'close_menu': AnimatedIcons.close_menu, 'ellipsis_search': AnimatedIcons.ellipsis_search, 'event_add': AnimatedIcons.event_add, 'home_menu': AnimatedIcons.home_menu, 'list_view': AnimatedIcons.list_view, 'menu_arrow': AnimatedIcons.menu_arrow, 'menu_close': AnimatedIcons.menu_close, 'menu_home': AnimatedIcons.menu_home, 'pause_play': AnimatedIcons.pause_play, 'play_pause': AnimatedIcons.play_pause, 'search_ellipsis': AnimatedIcons.search_ellipsis, 'view_list': AnimatedIcons.view_list,};
void main() { runApp(const AnimatedIconApp());}
class AnimatedIconApp extends StatelessWidget { const AnimatedIconApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData( colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true, ), home: const Scaffold( body: AnimatedIconExample(), ), ); }}
class AnimatedIconExample extends StatefulWidget { const AnimatedIconExample({super.key});
@override State<AnimatedIconExample> createState() => _AnimatedIconExampleState();}
class _AnimatedIconExampleState extends State<AnimatedIconExample> with SingleTickerProviderStateMixin { late AnimationController controller; late Animation<double> animation;
@override void initState() { super.initState(); controller = AnimationController( vsync: this, duration: const Duration(seconds: 2), ) ..forward() ..repeat(reverse: true); animation = Tween<double>(begin: 0.0, end: 1.0).animate(controller); }
@override void dispose() { controller.dispose(); super.dispose(); }
@override Widget build(BuildContext context) { return Scaffold( body: GridView( gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 4, ), children: iconsList.entries.map((MapEntry<String, AnimatedIconData> entry) { return Card( child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ AnimatedIcon( icon: entry.value, progress: animation, size: 72.0, semanticLabel: entry.key, ), const SizedBox(height: 8.0), Text(entry.key), ], ), ), ); }).toList(), ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [MaterialApp].
void main() { runApp(const MaterialAppExample());}
enum AnimationStyles { defaultStyle, custom, none }const List<(AnimationStyles, String)> animationStyleSegments = <(AnimationStyles, String)>[ (AnimationStyles.defaultStyle, 'Default'), (AnimationStyles.custom, 'Custom'), (AnimationStyles.none, 'None'),];
class MaterialAppExample extends StatefulWidget { const MaterialAppExample({super.key});
@override State<MaterialAppExample> createState() => _MaterialAppExampleState();}
class _MaterialAppExampleState extends State<MaterialAppExample> { Set<AnimationStyles> _animationStyleSelection = <AnimationStyles>{AnimationStyles.defaultStyle}; AnimationStyle? _animationStyle; bool isDarkTheme = false;
@override Widget build(BuildContext context) { return MaterialApp( themeAnimationStyle: _animationStyle, themeMode: isDarkTheme ? ThemeMode.dark : ThemeMode.light, theme: ThemeData(colorSchemeSeed: Colors.green), darkTheme: ThemeData( colorSchemeSeed: Colors.green, brightness: Brightness.dark, ), home: Scaffold( body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ SegmentedButton<AnimationStyles>( selected: _animationStyleSelection, onSelectionChanged: (Set<AnimationStyles> styles) { setState(() { _animationStyleSelection = styles; switch (styles.first) { case AnimationStyles.defaultStyle: _animationStyle = null; case AnimationStyles.custom: _animationStyle = AnimationStyle( curve: Easing.emphasizedAccelerate, duration: const Duration(seconds: 1), ); case AnimationStyles.none: _animationStyle = AnimationStyle.noAnimation; } }); }, segments: animationStyleSegments .map<ButtonSegment<AnimationStyles>>(((AnimationStyles, String) shirt) { return ButtonSegment<AnimationStyles>(value: shirt.$1, label: Text(shirt.$2)); }) .toList(), ), const SizedBox(height: 10), OutlinedButton.icon( onPressed: () { setState(() { isDarkTheme = !isDarkTheme; }); }, icon: Icon(isDarkTheme ? Icons.wb_sunny : Icons.nightlight_round), label: const Text('Switch Theme Mode'), ), ], ), ), ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [AppBar].
void main() => runApp(const AppBarApp());
class AppBarApp extends StatelessWidget { const AppBarApp({super.key});
@override Widget build(BuildContext context) { return const MaterialApp( home: AppBarExample(), ); }}
class AppBarExample extends StatelessWidget { const AppBarExample({super.key});
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('AppBar Demo'), actions: <Widget>[ IconButton( icon: const Icon(Icons.add_alert), tooltip: 'Show Snackbar', onPressed: () { ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('This is a snackbar'))); }, ), IconButton( icon: const Icon(Icons.navigate_next), tooltip: 'Go to the next page', onPressed: () { Navigator.push(context, MaterialPageRoute<void>( builder: (BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Next page'), ), body: const Center( child: Text( 'This is the next page', style: TextStyle(fontSize: 24), ), ), ); }, )); }, ), ], ), body: const Center( child: Text( 'This is the home page', style: TextStyle(fontSize: 24), ), ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
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());
class AppBarApp extends StatelessWidget { const AppBarApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData( colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true, ), home: const AppBarExample(), ); }}
class AppBarExample extends StatefulWidget { const AppBarExample({super.key});
@override State<AppBarExample> createState() => _AppBarExampleState();}
class _AppBarExampleState extends State<AppBarExample> { bool shadowColor = false; double? scrolledUnderElevation;
@override Widget build(BuildContext context) { final ColorScheme colorScheme = Theme.of(context).colorScheme; final Color oddItemColor = colorScheme.primary.withOpacity(0.05); final Color evenItemColor = colorScheme.primary.withOpacity(0.15);
return Scaffold( appBar: AppBar( title: const Text('AppBar Demo'), scrolledUnderElevation: scrolledUnderElevation, shadowColor: shadowColor ? Theme.of(context).colorScheme.shadow : null, ), body: GridView.builder( itemCount: _items.length, padding: const EdgeInsets.all(8.0), gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 3, childAspectRatio: 2.0, mainAxisSpacing: 10.0, crossAxisSpacing: 10.0, ), itemBuilder: (BuildContext context, int index) { if (index == 0) { return Center( child: Text( 'Scroll to see the Appbar in effect.', style: Theme.of(context).textTheme.labelLarge, textAlign: TextAlign.center, ), ); } return Container( alignment: Alignment.center, // tileColor: _items[index].isOdd ? oddItemColor : evenItemColor, decoration: BoxDecoration( borderRadius: BorderRadius.circular(20.0), color: _items[index].isOdd ? oddItemColor : evenItemColor, ), child: Text('Item $index'), ); }, ), bottomNavigationBar: BottomAppBar( child: Padding( padding: const EdgeInsets.all(8), child: OverflowBar( overflowAlignment: OverflowBarAlignment.center, alignment: MainAxisAlignment.center, overflowSpacing: 5.0, children: <Widget>[ ElevatedButton.icon( onPressed: () { setState(() { shadowColor = !shadowColor; }); }, icon: Icon( shadowColor ? Icons.visibility_off : Icons.visibility, ), label: const Text('shadow color'), ), const SizedBox(width: 5), ElevatedButton( onPressed: () { if (scrolledUnderElevation == null) { setState(() { // Default elevation is 3.0, increment by 1.0. scrolledUnderElevation = 4.0; }); } else { setState(() { scrolledUnderElevation = scrolledUnderElevation! + 1.0; }); } }, child: Text( 'scrolledUnderElevation: ${scrolledUnderElevation ?? 'default'}', ), ), ], ), ), ), ); }}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [AppBar].
void main() => runApp(const AppBarApp());
class AppBarApp extends StatelessWidget { const AppBarApp({super.key});
@override Widget build(BuildContext context) { return const MaterialApp( home: AppBarExample(), ); }}
class AppBarExample extends StatelessWidget { const AppBarExample({super.key});
@override Widget build(BuildContext context) { final ButtonStyle style = TextButton.styleFrom( foregroundColor: Theme.of(context).colorScheme.onPrimary, ); return Scaffold( appBar: AppBar( actions: <Widget>[ TextButton( style: style, onPressed: () {}, child: const Text('Action 1'), ), TextButton( style: style, onPressed: () {}, child: const Text('Action 2'), ), ], ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [AppBar].
List<String> titles = <String>[ 'Cloud', 'Beach', 'Sunny',];
void main() => runApp(const AppBarApp());
class AppBarApp extends StatelessWidget { const AppBarApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData(colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true), home: const AppBarExample(), ); }}
class AppBarExample extends StatelessWidget { const AppBarExample({super.key});
@override Widget build(BuildContext context) { final ColorScheme colorScheme = Theme.of(context).colorScheme; final Color oddItemColor = colorScheme.primary.withOpacity(0.05); final Color evenItemColor = colorScheme.primary.withOpacity(0.15); const int tabsCount = 3;
return DefaultTabController( initialIndex: 1, length: tabsCount, child: Scaffold( appBar: AppBar( title: const Text('AppBar Sample'), // This check specifies which nested Scrollable's scroll notification // should be listened to. // // When `ThemeData.useMaterial3` is true and scroll view has // scrolled underneath the app bar, this updates the app bar // background color and elevation. // // This sets `notification.depth == 1` to listen to the scroll // notification from the nested `ListView.builder`. notificationPredicate: (ScrollNotification notification) { return notification.depth == 1; }, // The elevation value of the app bar when scroll view has // scrolled underneath the app bar. scrolledUnderElevation: 4.0, shadowColor: Theme.of(context).shadowColor, bottom: TabBar( tabs: <Widget>[ Tab( icon: const Icon(Icons.cloud_outlined), text: titles[0], ), Tab( icon: const Icon(Icons.beach_access_sharp), text: titles[1], ), Tab( icon: const Icon(Icons.brightness_5_sharp), text: titles[2], ), ], ), ), body: TabBarView( children: <Widget>[ ListView.builder( itemCount: 25, itemBuilder: (BuildContext context, int index) { return ListTile( tileColor: index.isOdd ? oddItemColor : evenItemColor, title: Text('${titles[0]} $index'), ); }, ), ListView.builder( itemCount: 25, itemBuilder: (BuildContext context, int index) { return ListTile( tileColor: index.isOdd ? oddItemColor : evenItemColor, title: Text('${titles[1]} $index'), ); }, ), ListView.builder( itemCount: 25, itemBuilder: (BuildContext context, int index) { return ListTile( tileColor: index.isOdd ? oddItemColor : evenItemColor, title: Text('${titles[2]} $index'), ); }, ), ], ), ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [AppBar.shape].
void main() => runApp(const AppBarExampleApp());
class AppBarExampleApp extends StatelessWidget { const AppBarExampleApp({super.key});
@override Widget build(BuildContext context) { return const MaterialApp( home: AppBarExample(), ); }}
class AppBarExample extends StatelessWidget { const AppBarExample({super.key});
@override Widget build(BuildContext context) { final ColorScheme colorScheme = Theme.of(context).colorScheme;
return Scaffold( appBar: AppBar( shape: const CustomAppBarShape(), backgroundColor: colorScheme.primaryContainer, title: const Text('AppBar Sample'), bottom: PreferredSize( preferredSize: const Size.fromHeight(64.0), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 16.0), child: TextField( decoration: InputDecoration( border: OutlineInputBorder( borderSide: BorderSide(color: colorScheme.primary), ), enabledBorder: OutlineInputBorder( borderSide: BorderSide(color: colorScheme.onPrimaryContainer), ), filled: true, hintText: 'Enter a search term', fillColor: colorScheme.surface, prefixIcon: Icon( Icons.search_rounded, color: colorScheme.primary ), suffixIcon: Icon( Icons.tune_rounded, color: colorScheme.primary ), ) ), ), ), ), body: ListView.builder( padding: const EdgeInsets.only(top: 45.0), itemCount: 20, itemBuilder: (BuildContext context, int index) { return ListTile( title: Text('Item $index'), ); }, ), ); }}
class CustomAppBarShape extends OutlinedBorder { // Implementing the constructor allows the CustomAppBarShape to be // properly compared when calling the `identical` method. const CustomAppBarShape({ super.side });
Path _getPath(Rect rect) { final Path path = Path(); final Size size = Size(rect.width, rect.height * 1.5) ;
final double p0 = size.height * 0.75; path.lineTo(0.0, p0);
final Offset controlPoint = Offset(size.width * 0.4, size.height); final Offset endPoint = Offset(size.width, size.height / 2); path.quadraticBezierTo(controlPoint.dx, controlPoint.dy, endPoint.dx, endPoint.dy);
path.lineTo(size.width, 0.0); path.close();
return path; }
@override Path getOuterPath(Rect rect, {TextDirection? textDirection}) { return _getPath(rect.inflate(side.width)); }
@override Path getInnerPath(Rect rect, {TextDirection? textDirection}) { return _getPath(rect); }
@override void paint(Canvas canvas, Rect rect, {TextDirection? textDirection}) { if (rect.isEmpty) { return; } canvas.drawPath( getOuterPath(rect, textDirection: textDirection), side.toPaint(), ); }
@override ShapeBorder scale(double t) { return CustomAppBarShape(side: side.scale(t)); }
@override OutlinedBorder copyWith({BorderSide? side}) { return CustomAppBarShape(side: side ?? this.side); }
// The lerpFrom method is necessary for the CustomAppBarShape to be // properly animated when changing the AppBar shape and when // the AppBar is rebuilt. @override ShapeBorder? lerpFrom(ShapeBorder? a, double t) { if (a is CustomAppBarShape) { return CustomAppBarShape(side: BorderSide.lerp(a.side, side, t)); } return super.lerpFrom(a, t); }
// The lerpTo method is necessary for the CustomAppBarShape to be // properly animated when changing the AppBar shape and when // the AppBar is rebuilt. @override ShapeBorder? lerpTo(ShapeBorder? b, double t) { if (b is CustomAppBarShape) { return CustomAppBarShape(side: BorderSide.lerp(b.side, side, t)); } return super.lerpTo(b, t); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [SliverAppBar].
void main() => runApp(const AppBarApp());
class AppBarApp extends StatelessWidget { const AppBarApp({super.key});
@override Widget build(BuildContext context) { return const MaterialApp( home: SliverAppBarExample(), ); }}
class SliverAppBarExample extends StatefulWidget { const SliverAppBarExample({super.key});
@override State<SliverAppBarExample> createState() => _SliverAppBarExampleState();}
class _SliverAppBarExampleState extends State<SliverAppBarExample> { bool _pinned = true; bool _snap = false; bool _floating = false;
// [SliverAppBar]s are typically used in [CustomScrollView.slivers], which in// turn can be placed in a [Scaffold.body]. @override Widget build(BuildContext context) { return Scaffold( body: CustomScrollView( slivers: <Widget>[ SliverAppBar( pinned: _pinned, snap: _snap, floating: _floating, expandedHeight: 160.0, flexibleSpace: const FlexibleSpaceBar( title: Text('SliverAppBar'), background: FlutterLogo(), ), ), const SliverToBoxAdapter( child: SizedBox( height: 20, child: Center( child: Text('Scroll to see the SliverAppBar in effect.'), ), ), ), SliverList( delegate: SliverChildBuilderDelegate( (BuildContext context, int index) { return Container( color: index.isOdd ? Colors.white : Colors.black12, height: 100.0, child: Center( child: Text('$index', textScaler: const TextScaler.linear(5)), ), ); }, childCount: 20, ), ), ], ), bottomNavigationBar: BottomAppBar( child: Padding( padding: const EdgeInsets.all(8), child: OverflowBar( overflowAlignment: OverflowBarAlignment.center, children: <Widget>[ Row( mainAxisSize: MainAxisSize.min, children: <Widget>[ const Text('pinned'), Switch( onChanged: (bool val) { setState(() { _pinned = val; }); }, value: _pinned, ), ], ), Row( mainAxisSize: MainAxisSize.min, children: <Widget>[ const Text('snap'), Switch( onChanged: (bool val) { setState(() { _snap = val; // Snapping only applies when the app bar is floating. _floating = _floating || _snap; }); }, value: _snap, ), ], ), Row( mainAxisSize: MainAxisSize.min, children: <Widget>[ const Text('floating'), Switch( onChanged: (bool val) { setState(() { _floating = val; _snap = _snap && _floating; }); }, value: _floating, ), ], ), ], ), ), ), ); }}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [SliverAppBar.medium].
void main() { runApp(const AppBarMediumApp());}
class AppBarMediumApp extends StatelessWidget { const AppBarMediumApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData( useMaterial3: true, colorSchemeSeed: const Color(0xff6750A4), ), home: Material( child: CustomScrollView( slivers: <Widget>[ SliverAppBar.medium( leading: IconButton(icon: const Icon(Icons.menu), onPressed: () {}), title: const Text('Medium App Bar'), actions: <Widget>[ IconButton(icon: const Icon(Icons.more_vert), onPressed: () {}), ], ), // Just some content big enough to have something to scroll. SliverToBoxAdapter( child: Card( child: SizedBox( height: 1200, child: Padding( padding: const EdgeInsets.fromLTRB(8, 100, 8, 100), child: Text( 'Here be scrolling content...', style: Theme.of(context).textTheme.headlineSmall, ), ), ), ), ), ], ), ), ); }}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [SliverAppBar.large].
void main() { runApp(const AppBarLargeApp());}
class AppBarLargeApp extends StatelessWidget { const AppBarLargeApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData( useMaterial3: true, colorSchemeSeed: const Color(0xff6750A4), ), home: Material( child: CustomScrollView( slivers: <Widget>[ SliverAppBar.large( leading: IconButton(icon: const Icon(Icons.menu), onPressed: () {}), title: const Text('Large App Bar'), actions: <Widget>[ IconButton(icon: const Icon(Icons.more_vert), onPressed: () {}), ], ), // Just some content big enough to have something to scroll. SliverToBoxAdapter( child: Card( child: SizedBox( height: 1200, child: Padding( padding: const EdgeInsets.fromLTRB(8, 100, 8, 100), child: Text( 'Here be scrolling content...', style: Theme.of(context).textTheme.headlineSmall, ), ), ), ), ), ], ), ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [SliverAppBar].
void main() { runApp(const StretchableSliverAppBar());}
class StretchableSliverAppBar extends StatefulWidget { const StretchableSliverAppBar({super.key});
@override State<StretchableSliverAppBar> createState() => _StretchableSliverAppBarState();}
class _StretchableSliverAppBarState extends State<StretchableSliverAppBar> { bool _stretch = true; @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: CustomScrollView( physics: const BouncingScrollPhysics(), slivers: <Widget>[ SliverAppBar( stretch: _stretch, onStretchTrigger: () async { // Triggers when stretching }, // [stretchTriggerOffset] describes the amount of overscroll that must occur // to trigger [onStretchTrigger] // // Setting [stretchTriggerOffset] to a value of 300.0 will trigger // [onStretchTrigger] when the user has overscrolled by 300.0 pixels. stretchTriggerOffset: 300.0, expandedHeight: 200.0, flexibleSpace: const FlexibleSpaceBar( title: Text('SliverAppBar'), background: FlutterLogo(), ), ), SliverList( delegate: SliverChildBuilderDelegate( (BuildContext context, int index) { return Container( color: index.isOdd ? Colors.white : Colors.black12, height: 100.0, child: Center( child: Text('$index', textScaler: const TextScaler.linear(5.0)), ), ); }, childCount: 20, ), ), ], ), bottomNavigationBar: BottomAppBar( child: Padding( padding: const EdgeInsets.all(8), child: OverflowBar( overflowAlignment: OverflowBarAlignment.center, alignment: MainAxisAlignment.center, children: <Widget>[ Row( mainAxisSize: MainAxisSize.min, children: <Widget>[ const Text('stretch'), Switch( onChanged: (bool val) { setState(() { _stretch = val; }); }, value: _stretch, ), ], ), ], ), ), ), )); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [Autocomplete].
void main() => runApp(const AutocompleteExampleApp());
class AutocompleteExampleApp extends StatelessWidget { const AutocompleteExampleApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: const Text('Autocomplete Basic'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text('Type below to autocomplete the following possible results: ${AutocompleteBasicExample._kOptions}.'), const AutocompleteBasicExample(), ], ), ), ), ); }}
class AutocompleteBasicExample extends StatelessWidget { const AutocompleteBasicExample({super.key});
static const List<String> _kOptions = <String>[ 'aardvark', 'bobcat', 'chameleon', ];
@override Widget build(BuildContext context) { return Autocomplete<String>( optionsBuilder: (TextEditingValue textEditingValue) { if (textEditingValue.text == '') { return const Iterable<String>.empty(); } return _kOptions.where((String option) { return option.contains(textEditingValue.text.toLowerCase()); }); }, onSelected: (String selection) { debugPrint('You just selected $selection'); }, ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [Autocomplete].
void main() => runApp(const AutocompleteExampleApp());
class AutocompleteExampleApp extends StatelessWidget { const AutocompleteExampleApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: const Text('Autocomplete Basic User'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text('Type below to autocomplete the following possible results: ${AutocompleteBasicUserExample._userOptions}.'), const AutocompleteBasicUserExample(), ], ), ), ), ); }}
@immutableclass User { const User({ required this.email, required this.name, });
final String email; final String name;
@override String toString() { return '$name, $email'; }
@override bool operator ==(Object other) { if (other.runtimeType != runtimeType) { return false; } return other is User && other.name == name && other.email == email; }
@override int get hashCode => Object.hash(email, name);}
class AutocompleteBasicUserExample extends StatelessWidget { const AutocompleteBasicUserExample({super.key});
static const List<User> _userOptions = <User>[ User(name: 'Alice', email: 'alice@example.com'), User(name: 'Bob', email: 'bob@example.com'), User(name: 'Charlie', email: 'charlie123@gmail.com'), ];
static String _displayStringForOption(User option) => option.name;
@override Widget build(BuildContext context) { return Autocomplete<User>( displayStringForOption: _displayStringForOption, optionsBuilder: (TextEditingValue textEditingValue) { if (textEditingValue.text == '') { return const Iterable<User>.empty(); } return _userOptions.where((User option) { return option.toString().contains(textEditingValue.text.toLowerCase()); }); }, onSelected: (User selection) { debugPrint('You just selected ${_displayStringForOption(selection)}'); }, ); }}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [Autocomplete] that shows how to fetch the options/// from a remote API.
const Duration fakeAPIDuration = Duration(seconds: 1);
void main() => runApp(const AutocompleteExampleApp());
class AutocompleteExampleApp extends StatelessWidget { const AutocompleteExampleApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: const Text('Autocomplete - async'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text('Type below to autocomplete the following possible results: ${_FakeAPI._kOptions}.'), const _AsyncAutocomplete(), ], ), ), ), ); }}
class _AsyncAutocomplete extends StatefulWidget { const _AsyncAutocomplete();
@override State<_AsyncAutocomplete > createState() => _AsyncAutocompleteState();}
class _AsyncAutocompleteState extends State<_AsyncAutocomplete > { // The query currently being searched for. If null, there is no pending // request. String? _searchingWithQuery;
// The most recent options received from the API. late Iterable<String> _lastOptions = <String>[];
@override Widget build(BuildContext context) { return Autocomplete<String>( optionsBuilder: (TextEditingValue textEditingValue) async { _searchingWithQuery = textEditingValue.text; final Iterable<String> options = await _FakeAPI.search(_searchingWithQuery!);
// If another search happened after this one, throw away these options. // Use the previous options intead and wait for the newer request to // finish. if (_searchingWithQuery != textEditingValue.text) { return _lastOptions; }
_lastOptions = options; return options; }, onSelected: (String selection) { debugPrint('You just selected $selection'); }, ); }}
// Mimics a remote API.class _FakeAPI { static const List<String> _kOptions = <String>[ 'aardvark', 'bobcat', 'chameleon', ];
// Searches the options, but injects a fake "network" delay. static Future<Iterable<String>> search(String query) async { await Future<void>.delayed(fakeAPIDuration); // Fake 1 second delay. if (query == '') { return const Iterable<String>.empty(); } return _kOptions.where((String option) { return option.contains(query.toLowerCase()); }); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'dart:async';
import 'package:flutter/material.dart';
/// Flutter code sample for [Autocomplete] that demonstrates fetching the/// options asynchronously and debouncing the network calls.
const Duration fakeAPIDuration = Duration(seconds: 1);const Duration debounceDuration = Duration(milliseconds: 500);
void main() => runApp(const AutocompleteExampleApp());
class AutocompleteExampleApp extends StatelessWidget { const AutocompleteExampleApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: const Text('Autocomplete - async and debouncing'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text('Type below to autocomplete the following possible results: ${_FakeAPI._kOptions}.'), const _AsyncAutocomplete(), ], ), ), ), ); }}
class _AsyncAutocomplete extends StatefulWidget { const _AsyncAutocomplete();
@override State<_AsyncAutocomplete > createState() => _AsyncAutocompleteState();}
class _AsyncAutocompleteState extends State<_AsyncAutocomplete > { // The query currently being searched for. If null, there is no pending // request. String? _currentQuery;
// The most recent options received from the API. late Iterable<String> _lastOptions = <String>[];
late final _Debounceable<Iterable<String>?, String> _debouncedSearch;
// Calls the "remote" API to search with the given query. Returns null when // the call has been made obsolete. Future<Iterable<String>?> _search(String query) async { _currentQuery = query;
// In a real application, there should be some error handling here. final Iterable<String> options = await _FakeAPI.search(_currentQuery!);
// If another search happened after this one, throw away these options. if (_currentQuery != query) { return null; } _currentQuery = null;
return options; }
@override void initState() { super.initState(); _debouncedSearch = _debounce<Iterable<String>?, String>(_search); }
@override Widget build(BuildContext context) { return Autocomplete<String>( optionsBuilder: (TextEditingValue textEditingValue) async { final Iterable<String>? options = await _debouncedSearch(textEditingValue.text); if (options == null) { return _lastOptions; } _lastOptions = options; return options; }, onSelected: (String selection) { debugPrint('You just selected $selection'); }, ); }}
// Mimics a remote API.class _FakeAPI { static const List<String> _kOptions = <String>[ 'aardvark', 'bobcat', 'chameleon', ];
// Searches the options, but injects a fake "network" delay. static Future<Iterable<String>> search(String query) async { await Future<void>.delayed(fakeAPIDuration); // Fake 1 second delay. if (query == '') { return const Iterable<String>.empty(); } return _kOptions.where((String option) { return option.contains(query.toLowerCase()); }); }}
typedef _Debounceable<S, T> = Future<S?> Function(T parameter);
/// Returns a new function that is a debounced version of the given function.////// This means that the original function will be called only after no calls/// have been made for the given Duration._Debounceable<S, T> _debounce<S, T>(_Debounceable<S?, T> function) { _DebounceTimer? debounceTimer;
return (T parameter) async { if (debounceTimer != null && !debounceTimer!.isCompleted) { debounceTimer!.cancel(); } debounceTimer = _DebounceTimer(); try { await debounceTimer!.future; } catch (error) { if (error is _CancelException) { return null; } rethrow; } return function(parameter); };}
// A wrapper around Timer used for debouncing.class _DebounceTimer { _DebounceTimer( ) { _timer = Timer(debounceDuration, _onComplete); }
late final Timer _timer; final Completer<void> _completer = Completer<void>();
void _onComplete() { _completer.complete(); }
Future<void> get future => _completer.future;
bool get isCompleted => _completer.isCompleted;
void cancel() { _timer.cancel(); _completer.completeError(const _CancelException()); }}
// An exception indicating that the timer was canceled.class _CancelException implements Exception { const _CancelException();}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'dart:async';
import 'package:flutter/material.dart';
/// Flutter code sample for [Autocomplete] that demonstrates fetching the/// options asynchronously and debouncing the network calls, including handling/// network errors.
void main() => runApp(const AutocompleteExampleApp());
const Duration fakeAPIDuration = Duration(seconds: 1);const Duration debounceDuration = Duration(milliseconds: 500);
class AutocompleteExampleApp extends StatelessWidget { const AutocompleteExampleApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: const Text('Autocomplete - async, debouncing, and network errors'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text('Type below to autocomplete the following possible results: ${_FakeAPI._kOptions}.'), const SizedBox(height: 32.0), const _AsyncAutocomplete(), ], ), ), ), ); }}
class _AsyncAutocomplete extends StatefulWidget { const _AsyncAutocomplete();
@override State<_AsyncAutocomplete > createState() => _AsyncAutocompleteState();}
class _AsyncAutocompleteState extends State<_AsyncAutocomplete > { // The query currently being searched for. If null, there is no pending // request. String? _currentQuery;
// The most recent options received from the API. late Iterable<String> _lastOptions = <String>[];
late final _Debounceable<Iterable<String>?, String> _debouncedSearch;
// Whether to consider the fake network to be offline. bool _networkEnabled = true;
// A network error was received on the most recent query. bool _networkError = false;
// Calls the "remote" API to search with the given query. Returns null when // the call has been made obsolete. Future<Iterable<String>?> _search(String query) async { _currentQuery = query;
late final Iterable<String> options; try { options = await _FakeAPI.search(_currentQuery!, _networkEnabled); } catch (error) { if (error is _NetworkException) { setState(() { _networkError = true; }); return <String>[]; } rethrow; }
// If another search happened after this one, throw away these options. if (_currentQuery != query) { return null; } _currentQuery = null;
return options; }
@override void initState() { super.initState(); _debouncedSearch = _debounce<Iterable<String>?, String>(_search); }
@override Widget build(BuildContext context) { return Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text( _networkEnabled ? 'Network is on, toggle to induce network errors.' : 'Network is off, toggle to allow requests to go through.', ), Switch( value: _networkEnabled, onChanged: (bool? value) { setState(() { _networkEnabled = !_networkEnabled; }); }, ), const SizedBox( height: 32.0, ), Autocomplete<String>( fieldViewBuilder: (BuildContext context, TextEditingController controller, FocusNode focusNode, VoidCallback onFieldSubmitted) { return TextFormField( decoration: InputDecoration( errorText: _networkError ? 'Network error, please try again.' : null, ), controller: controller, focusNode: focusNode, onFieldSubmitted: (String value) { onFieldSubmitted(); }, ); }, optionsBuilder: (TextEditingValue textEditingValue) async { setState(() { _networkError = false; }); final Iterable<String>? options = await _debouncedSearch(textEditingValue.text); if (options == null) { return _lastOptions; } _lastOptions = options; return options; }, onSelected: (String selection) { debugPrint('You just selected $selection'); }, ), ], ); }}
// Mimics a remote API.class _FakeAPI { static const List<String> _kOptions = <String>[ 'aardvark', 'bobcat', 'chameleon', ];
// Searches the options, but injects a fake "network" delay. static Future<Iterable<String>> search(String query, bool networkEnabled) async { await Future<void>.delayed(fakeAPIDuration); // Fake 1 second delay. if (!networkEnabled) { throw const _NetworkException(); } if (query == '') { return const Iterable<String>.empty(); } return _kOptions.where((String option) { return option.contains(query.toLowerCase()); }); }}
typedef _Debounceable<S, T> = Future<S?> Function(T parameter);
/// Returns a new function that is a debounced version of the given function.////// This means that the original function will be called only after no calls/// have been made for the given Duration._Debounceable<S, T> _debounce<S, T>(_Debounceable<S?, T> function) { _DebounceTimer? debounceTimer;
return (T parameter) async { if (debounceTimer != null && !debounceTimer!.isCompleted) { debounceTimer!.cancel(); } debounceTimer = _DebounceTimer(); try { await debounceTimer!.future; } catch (error) { if (error is _CancelException) { return null; } rethrow; } return function(parameter); };}
// A wrapper around Timer used for debouncing.class _DebounceTimer { _DebounceTimer( ) { _timer = Timer(debounceDuration, _onComplete); }
late final Timer _timer; final Completer<void> _completer = Completer<void>();
void _onComplete() { _completer.complete(); }
Future<void> get future => _completer.future;
bool get isCompleted => _completer.isCompleted;
void cancel() { _timer.cancel(); _completer.completeError(const _CancelException()); }}
// An exception indicating that the timer was canceled.class _CancelException implements Exception { const _CancelException();}
// An exception indicating that a network request has failed.class _NetworkException implements Exception { const _NetworkException();}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [Badge].
void main() => runApp(const BadgeExampleApp());
class BadgeExampleApp extends StatelessWidget { const BadgeExampleApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: const Text('Badge Sample')), body: const BadgeExample(), ), ); }}
class BadgeExample extends StatelessWidget { const BadgeExample({super.key});
@override Widget build(BuildContext context) { return Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ IconButton( icon: const Badge( label: Text('Your label'), backgroundColor: Colors.blueAccent, child: Icon(Icons.receipt), ), onPressed: () {}, ), const SizedBox(height: 20), IconButton( icon: Badge.count( count: 9999, child: const Icon(Icons.notifications), ), onPressed: () {}, ), ], ), ); }}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [MaterialBanner].
void main() => runApp(const MaterialBannerExampleApp());
class MaterialBannerExampleApp extends StatelessWidget { const MaterialBannerExampleApp({super.key});
@override Widget build(BuildContext context) { return const MaterialApp( home: MaterialBannerExample(), ); }}
class MaterialBannerExample extends StatelessWidget { const MaterialBannerExample({super.key});
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('The MaterialBanner is below'), ), body: const MaterialBanner( padding: EdgeInsets.all(20), content: Text('Hello, I am a Material Banner'), leading: Icon(Icons.agriculture_outlined), backgroundColor: Color(0xFFE0E0E0), actions: <Widget>[ TextButton( onPressed: null, child: Text('OPEN'), ), TextButton( onPressed: null, child: Text('DISMISS'), ), ], ), ); }}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [MaterialBanner].
void main() => runApp(const MaterialBannerExampleApp());
class MaterialBannerExampleApp extends StatelessWidget { const MaterialBannerExampleApp({super.key});
@override Widget build(BuildContext context) { return const MaterialApp( home: MaterialBannerExample(), ); }}
class MaterialBannerExample extends StatelessWidget { const MaterialBannerExample({super.key});
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('The MaterialBanner is below'), ), body: Center( child: ElevatedButton( child: const Text('Show MaterialBanner'), onPressed: () => ScaffoldMessenger.of(context).showMaterialBanner( const MaterialBanner( padding: EdgeInsets.all(20), content: Text('Hello, I am a Material Banner'), leading: Icon(Icons.agriculture_outlined), backgroundColor: Colors.green, actions: <Widget>[ TextButton( onPressed: null, child: Text('DISMISS'), ), ], ), ), ), ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [BottomAppBar].
void main() { runApp(const BottomAppBarDemo());}
class BottomAppBarDemo extends StatefulWidget { const BottomAppBarDemo({super.key});
@override State createState() => _BottomAppBarDemoState();}
class _BottomAppBarDemoState extends State<BottomAppBarDemo> { bool _showFab = true; bool _showNotch = true; FloatingActionButtonLocation _fabLocation = FloatingActionButtonLocation.endDocked;
void _onShowNotchChanged(bool value) { setState(() { _showNotch = value; }); }
void _onShowFabChanged(bool value) { setState(() { _showFab = value; }); }
void _onFabLocationChanged(FloatingActionButtonLocation? value) { setState(() { _fabLocation = value ?? FloatingActionButtonLocation.endDocked; }); }
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( automaticallyImplyLeading: false, title: const Text('Bottom App Bar Demo'), ), body: ListView( padding: const EdgeInsets.only(bottom: 88), children: <Widget>[ SwitchListTile( title: const Text( 'Floating Action Button', ), value: _showFab, onChanged: _onShowFabChanged, ), SwitchListTile( title: const Text('Notch'), value: _showNotch, onChanged: _onShowNotchChanged, ), const Padding( padding: EdgeInsets.all(16), child: Text('Floating action button position'), ), RadioListTile<FloatingActionButtonLocation>( title: const Text('Docked - End'), value: FloatingActionButtonLocation.endDocked, groupValue: _fabLocation, onChanged: _onFabLocationChanged, ), RadioListTile<FloatingActionButtonLocation>( title: const Text('Docked - Center'), value: FloatingActionButtonLocation.centerDocked, groupValue: _fabLocation, onChanged: _onFabLocationChanged, ), RadioListTile<FloatingActionButtonLocation>( title: const Text('Floating - End'), value: FloatingActionButtonLocation.endFloat, groupValue: _fabLocation, onChanged: _onFabLocationChanged, ), RadioListTile<FloatingActionButtonLocation>( title: const Text('Floating - Center'), value: FloatingActionButtonLocation.centerFloat, groupValue: _fabLocation, onChanged: _onFabLocationChanged, ), ], ), floatingActionButton: _showFab ? FloatingActionButton( onPressed: () {}, tooltip: 'Create', child: const Icon(Icons.add), ) : null, floatingActionButtonLocation: _fabLocation, bottomNavigationBar: _DemoBottomAppBar( fabLocation: _fabLocation, shape: _showNotch ? const CircularNotchedRectangle() : null, ), ), ); }}
class _DemoBottomAppBar extends StatelessWidget { const _DemoBottomAppBar({ this.fabLocation = FloatingActionButtonLocation.endDocked, this.shape = const CircularNotchedRectangle(), });
final FloatingActionButtonLocation fabLocation; final NotchedShape? shape;
static final List<FloatingActionButtonLocation> centerLocations = <FloatingActionButtonLocation>[ FloatingActionButtonLocation.centerDocked, FloatingActionButtonLocation.centerFloat, ];
@override Widget build(BuildContext context) { return BottomAppBar( shape: shape, color: Colors.blue, child: IconTheme( data: IconThemeData(color: Theme.of(context).colorScheme.onPrimary), child: Row( children: <Widget>[ IconButton( tooltip: 'Open navigation menu', icon: const Icon(Icons.menu), onPressed: () {}, ), if (centerLocations.contains(fabLocation)) const Spacer(), IconButton( tooltip: 'Search', icon: const Icon(Icons.search), onPressed: () {}, ), IconButton( tooltip: 'Favorite', icon: const Icon(Icons.favorite), onPressed: () {}, ), ], ), ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';import 'package:flutter/rendering.dart';
/// Flutter code sample for [BottomAppBar] with Material 3.
void main() { runApp(const BottomAppBarDemo());}
class BottomAppBarDemo extends StatefulWidget { const BottomAppBarDemo({super.key});
@override State createState() => _BottomAppBarDemoState();}
class _BottomAppBarDemoState extends State<BottomAppBarDemo> { static const List<Color> colors = <Color>[ Colors.yellow, Colors.orange, Colors.pink, Colors.purple, Colors.cyan, ];
static final List<Widget> items = List<Widget>.generate( colors.length, (int index) => Container(color: colors[index], height: 150.0), ).reversed.toList();
late ScrollController _controller; bool _showFab = true; bool _isElevated = true; bool _isVisible = true;
FloatingActionButtonLocation get _fabLocation => _isVisible ? FloatingActionButtonLocation.endContained : FloatingActionButtonLocation.endFloat;
void _listen() { final ScrollDirection direction = _controller.position.userScrollDirection; if (direction == ScrollDirection.forward) { _show(); } else if (direction == ScrollDirection.reverse) { _hide(); } }
void _show() { if (!_isVisible) { setState(() => _isVisible = true); } }
void _hide() { if (_isVisible) { setState(() => _isVisible = false); } }
void _onShowFabChanged(bool value) { setState(() { _showFab = value; }); }
void _onElevatedChanged(bool value) { setState(() { _isElevated = value; }); }
void _addNewItem() { setState(() { items.insert( 0, Container(color: colors[items.length % 5], height: 150.0), ); }); }
@override void initState() { super.initState(); _controller = ScrollController(); _controller.addListener(_listen); }
@override void dispose() { _controller.removeListener(_listen); _controller.dispose(); super.dispose(); }
@override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData(useMaterial3: true), home: Scaffold( appBar: AppBar( title: const Text('Bottom App Bar Demo'), ), body: Column( children: <Widget>[ SwitchListTile( title: const Text('Floating Action Button'), value: _showFab, onChanged: _onShowFabChanged, ), SwitchListTile( title: const Text('Bottom App Bar Elevation'), value: _isElevated, onChanged: _onElevatedChanged, ), Expanded( child: ListView( controller: _controller, children: items.toList(), ), ), ], ), floatingActionButton: _showFab ? FloatingActionButton( onPressed: _addNewItem, tooltip: 'Add New Item', elevation: _isVisible ? 0.0 : null, child: const Icon(Icons.add), ) : null, floatingActionButtonLocation: _fabLocation, bottomNavigationBar: _DemoBottomAppBar(isElevated: _isElevated, isVisible: _isVisible), ), ); }}
class _DemoBottomAppBar extends StatelessWidget { const _DemoBottomAppBar({ required this.isElevated, required this.isVisible, });
final bool isElevated; final bool isVisible;
@override Widget build(BuildContext context) { return AnimatedContainer( duration: const Duration(milliseconds: 200), height: isVisible ? 80.0 : 0, child: BottomAppBar( elevation: isElevated ? null : 0.0, child: Row( children: <Widget>[ IconButton( tooltip: 'Open popup menu', icon: const Icon(Icons.more_vert), onPressed: () { final SnackBar snackBar = SnackBar( content: const Text('Yay! A SnackBar!'), action: SnackBarAction( label: 'Undo', onPressed: () {}, ), );
// Find the ScaffoldMessenger in the widget tree // and use it to show a SnackBar. ScaffoldMessenger.of(context).showSnackBar(snackBar); }, ), IconButton( tooltip: 'Search', icon: const Icon(Icons.search), onPressed: () {}, ), IconButton( tooltip: 'Favorite', icon: const Icon(Icons.favorite), onPressed: () {}, ), ], ), ), ); }}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [BottomNavigationBar].
void main() => runApp(const BottomNavigationBarExampleApp());
class BottomNavigationBarExampleApp extends StatelessWidget { const BottomNavigationBarExampleApp({super.key});
@override Widget build(BuildContext context) { return const MaterialApp( home: BottomNavigationBarExample(), ); }}
class BottomNavigationBarExample extends StatefulWidget { const BottomNavigationBarExample({super.key});
@override State<BottomNavigationBarExample> createState() => _BottomNavigationBarExampleState();}
class _BottomNavigationBarExampleState extends State<BottomNavigationBarExample> { int _selectedIndex = 0; static const TextStyle optionStyle = TextStyle(fontSize: 30, fontWeight: FontWeight.bold); static const List<Widget> _widgetOptions = <Widget>[ Text( 'Index 0: Home', style: optionStyle, ), Text( 'Index 1: Business', style: optionStyle, ), Text( 'Index 2: School', style: optionStyle, ), ];
void _onItemTapped(int index) { setState(() { _selectedIndex = index; }); }
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('BottomNavigationBar Sample'), ), body: Center( child: _widgetOptions.elementAt(_selectedIndex), ), bottomNavigationBar: BottomNavigationBar( items: const <BottomNavigationBarItem>[ BottomNavigationBarItem( icon: Icon(Icons.home), label: 'Home', ), BottomNavigationBarItem( icon: Icon(Icons.business), label: 'Business', ), BottomNavigationBarItem( icon: Icon(Icons.school), label: 'School', ), ], currentIndex: _selectedIndex, selectedItemColor: Colors.amber[800], onTap: _onItemTapped, ), ); }}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [BottomNavigationBar].
void main() => runApp(const BottomNavigationBarExampleApp());
class BottomNavigationBarExampleApp extends StatelessWidget { const BottomNavigationBarExampleApp({super.key});
@override Widget build(BuildContext context) { return const MaterialApp( home: BottomNavigationBarExample(), ); }}
class BottomNavigationBarExample extends StatefulWidget { const BottomNavigationBarExample({super.key});
@override State<BottomNavigationBarExample> createState() => _BottomNavigationBarExampleState();}
class _BottomNavigationBarExampleState extends State<BottomNavigationBarExample> { int _selectedIndex = 0; static const TextStyle optionStyle = TextStyle(fontSize: 30, fontWeight: FontWeight.bold); static const List<Widget> _widgetOptions = <Widget>[ Text( 'Index 0: Home', style: optionStyle, ), Text( 'Index 1: Business', style: optionStyle, ), Text( 'Index 2: School', style: optionStyle, ), Text( 'Index 3: Settings', style: optionStyle, ), ];
void _onItemTapped(int index) { setState(() { _selectedIndex = index; }); }
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('BottomNavigationBar Sample'), ), body: Center( child: _widgetOptions.elementAt(_selectedIndex), ), bottomNavigationBar: BottomNavigationBar( items: const <BottomNavigationBarItem>[ BottomNavigationBarItem( icon: Icon(Icons.home), label: 'Home', backgroundColor: Colors.red, ), BottomNavigationBarItem( icon: Icon(Icons.business), label: 'Business', backgroundColor: Colors.green, ), BottomNavigationBarItem( icon: Icon(Icons.school), label: 'School', backgroundColor: Colors.purple, ), BottomNavigationBarItem( icon: Icon(Icons.settings), label: 'Settings', backgroundColor: Colors.pink, ), ], currentIndex: _selectedIndex, selectedItemColor: Colors.amber[800], onTap: _onItemTapped, ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [BottomNavigationBar].
void main() => runApp(const BottomNavigationBarExampleApp());
class BottomNavigationBarExampleApp extends StatelessWidget { const BottomNavigationBarExampleApp({super.key});
@override Widget build(BuildContext context) { return const MaterialApp( home: BottomNavigationBarExample(), ); }}
class BottomNavigationBarExample extends StatefulWidget { const BottomNavigationBarExample({super.key});
@override State<BottomNavigationBarExample> createState() => _BottomNavigationBarExampleState();}
class _BottomNavigationBarExampleState extends State<BottomNavigationBarExample> { int _selectedIndex = 0; final ScrollController _homeController = ScrollController();
Widget _listViewBody() { return ListView.separated( controller: _homeController, itemBuilder: (BuildContext context, int index) { return Center( child: Text( 'Item $index', ), ); }, separatorBuilder: (BuildContext context, int index) => const Divider( thickness: 1, ), itemCount: 50); }
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('BottomNavigationBar Sample'), ), body: _listViewBody(), bottomNavigationBar: BottomNavigationBar( items: const <BottomNavigationBarItem>[ BottomNavigationBarItem( icon: Icon(Icons.home), label: 'Home', ), BottomNavigationBarItem( icon: Icon(Icons.open_in_new_rounded), label: 'Open Dialog', ), ], currentIndex: _selectedIndex, selectedItemColor: Colors.amber[800], onTap: (int index) { switch (index) { case 0: // only scroll to top when current index is selected. if (_selectedIndex == index) { _homeController.animateTo( 0.0, duration: const Duration(milliseconds: 500), curve: Curves.easeOut, ); } case 1: showModal(context); } setState( () { _selectedIndex = index; }, ); }, ), ); }
void showModal(BuildContext context) { showDialog<void>( context: context, builder: (BuildContext context) => AlertDialog( content: const Text('Example Dialog'), actions: <TextButton>[ TextButton( onPressed: () { Navigator.pop(context); }, child: const Text('Close'), ) ], ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [showBottomSheet].
void main() => runApp(const BottomSheetExampleApp());
class BottomSheetExampleApp extends StatelessWidget { const BottomSheetExampleApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: const Text('Bottom Sheet Sample')), body: const BottomSheetExample(), ), ); }}
enum AnimationStyles { defaultStyle, custom, none }const List<(AnimationStyles, String)> animationStyleSegments = <(AnimationStyles, String)>[ (AnimationStyles.defaultStyle, 'Default'), (AnimationStyles.custom, 'Custom'), (AnimationStyles.none, 'None'),];
class BottomSheetExample extends StatefulWidget { const BottomSheetExample({super.key});
@override State<BottomSheetExample> createState() => _BottomSheetExampleState();}
class _BottomSheetExampleState extends State<BottomSheetExample> { Set<AnimationStyles> _animationStyleSelection = <AnimationStyles>{AnimationStyles.defaultStyle}; AnimationStyle? _animationStyle;
@override Widget build(BuildContext context) { return Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ SegmentedButton<AnimationStyles>( selected: _animationStyleSelection, onSelectionChanged: (Set<AnimationStyles> styles) { setState(() { _animationStyle = switch (styles.first) { AnimationStyles.defaultStyle => null, AnimationStyles.custom => AnimationStyle( duration: const Duration(seconds: 3), reverseDuration: const Duration(seconds: 1), ), AnimationStyles.none => AnimationStyle.noAnimation, }; _animationStyleSelection = styles; }); }, segments: animationStyleSegments .map<ButtonSegment<AnimationStyles>>(((AnimationStyles, String) shirt) { return ButtonSegment<AnimationStyles>(value: shirt.$1, label: Text(shirt.$2)); }) .toList(), ), const SizedBox(height: 10), ElevatedButton( child: const Text('showBottomSheet'), onPressed: () { showBottomSheet( context: context, sheetAnimationStyle: _animationStyle, builder: (BuildContext context) { return SizedBox.expand( child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: <Widget>[ const Text('Bottom sheet'), ElevatedButton( child: const Text('Close'), onPressed: () => Navigator.pop(context), ), ], ), ), ); }, ); }, ), ], ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [showModalBottomSheet].
void main() => runApp(const BottomSheetApp());
class BottomSheetApp extends StatelessWidget { const BottomSheetApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: const Text('Bottom Sheet Sample')), body: const BottomSheetExample(), ), ); }}
class BottomSheetExample extends StatelessWidget { const BottomSheetExample({super.key});
@override Widget build(BuildContext context) { return Center( child: ElevatedButton( child: const Text('showModalBottomSheet'), onPressed: () { showModalBottomSheet<void>( context: context, builder: (BuildContext context) { return Container( height: 200, color: Colors.amber, child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: <Widget>[ const Text('Modal BottomSheet'), ElevatedButton( child: const Text('Close BottomSheet'), onPressed: () => Navigator.pop(context), ), ], ), ), ); }, ); }, ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [showModalBottomSheet].
void main() => runApp(const BottomSheetApp());
class BottomSheetApp extends StatelessWidget { const BottomSheetApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData( colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true, ), home: Scaffold( appBar: AppBar(title: const Text('Bottom Sheet Sample')), body: const BottomSheetExample(), ), ); }}
class BottomSheetExample extends StatelessWidget { const BottomSheetExample({super.key});
@override Widget build(BuildContext context) { return Center( child: ElevatedButton( child: const Text('showModalBottomSheet'), onPressed: () { showModalBottomSheet<void>( context: context, builder: (BuildContext context) { return SizedBox( height: 200, child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: <Widget>[ const Text('Modal BottomSheet'), ElevatedButton( child: const Text('Close BottomSheet'), onPressed: () => Navigator.pop(context), ), ], ), ), ); }, ); }, ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [showModalBottomSheet].
void main() => runApp(const ModalBottomSheetApp());
class ModalBottomSheetApp extends StatelessWidget { const ModalBottomSheetApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: const Text('Modal Bottom Sheet Sample')), body: const ModalBottomSheetExample(), ), ); }}
enum AnimationStyles { defaultStyle, custom, none }const List<(AnimationStyles, String)> animationStyleSegments = <(AnimationStyles, String)>[ (AnimationStyles.defaultStyle, 'Default'), (AnimationStyles.custom, 'Custom'), (AnimationStyles.none, 'None'),];
class ModalBottomSheetExample extends StatefulWidget { const ModalBottomSheetExample({super.key});
@override State<ModalBottomSheetExample> createState() => _ModalBottomSheetExampleState();}
class _ModalBottomSheetExampleState extends State<ModalBottomSheetExample> { Set<AnimationStyles> _animationStyleSelection = <AnimationStyles>{AnimationStyles.defaultStyle}; AnimationStyle? _animationStyle;
@override Widget build(BuildContext context) { return Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ SegmentedButton<AnimationStyles>( selected: _animationStyleSelection, onSelectionChanged: (Set<AnimationStyles> styles) { setState(() { _animationStyle = switch (styles.first) { AnimationStyles.defaultStyle => null, AnimationStyles.custom => AnimationStyle( duration: const Duration(seconds: 3), reverseDuration: const Duration(seconds: 1), ), AnimationStyles.none => AnimationStyle.noAnimation, }; _animationStyleSelection = styles; }); }, segments: animationStyleSegments .map<ButtonSegment<AnimationStyles>>(((AnimationStyles, String) shirt) { return ButtonSegment<AnimationStyles>(value: shirt.$1, label: Text(shirt.$2)); }) .toList(), ), const SizedBox(height: 10), ElevatedButton( child: const Text('showModalBottomSheet'), onPressed: () { showModalBottomSheet<void>( context: context, sheetAnimationStyle: _animationStyle, builder: (BuildContext context) { return SizedBox.expand( child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: <Widget>[ const Text('Modal bottom sheet'), ElevatedButton( child: const Text('Close'), onPressed: () => Navigator.pop(context), ), ], ), ), ); }, ); }, ), ], ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [ElevatedButton].
void main() { runApp(const ButtonApp());}
class ButtonApp extends StatelessWidget { const ButtonApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData(colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true), title: 'Button Types', home: const Scaffold( body: ButtonTypesExample(), ), ); }}
class ButtonTypesExample extends StatelessWidget { const ButtonTypesExample({super.key});
@override Widget build(BuildContext context) { return const Padding( padding: EdgeInsets.all(4.0), child: Row( children: <Widget>[ Spacer(), ButtonTypesGroup(enabled: true), ButtonTypesGroup(enabled: false), Spacer(), ], ), ); }}
class ButtonTypesGroup extends StatelessWidget { const ButtonTypesGroup({super.key, required this.enabled});
final bool enabled;
@override Widget build(BuildContext context) { final VoidCallback? onPressed = enabled ? () {} : null; return Padding( padding: const EdgeInsets.all(4.0), child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: <Widget>[ ElevatedButton(onPressed: onPressed, child: const Text('Elevated')), FilledButton(onPressed: onPressed, child: const Text('Filled')), FilledButton.tonal(onPressed: onPressed, child: const Text('Filled Tonal')), OutlinedButton(onPressed: onPressed, child: const Text('Outlined')), TextButton(onPressed: onPressed, child: const Text('Text')), ], ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for using [ButtonStyleButton.iconAlignment] parameter.
void main() { runApp(const ButtonStyleButtonIconAlignmentApp());}
class ButtonStyleButtonIconAlignmentApp extends StatelessWidget { const ButtonStyleButtonIconAlignmentApp({super.key});
@override Widget build(BuildContext context) { return const MaterialApp( home: Scaffold( body: ButtonStyleButtonIconAlignmentExample(), ), ); }}
class ButtonStyleButtonIconAlignmentExample extends StatefulWidget { const ButtonStyleButtonIconAlignmentExample({super.key});
@override State<ButtonStyleButtonIconAlignmentExample> createState() => _ButtonStyleButtonIconAlignmentExampleState();}
class _ButtonStyleButtonIconAlignmentExampleState extends State<ButtonStyleButtonIconAlignmentExample> { TextDirection _textDirection = TextDirection.ltr; IconAlignment _iconAlignment = IconAlignment.start;
@override Widget build(BuildContext context) { return SafeArea( child: Directionality( key: const Key('Directionality'), textDirection: _textDirection, child: Center( child: Column( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ const Spacer(), OverflowBar( spacing: 10, overflowSpacing: 20, alignment: MainAxisAlignment.center, overflowAlignment: OverflowBarAlignment.center, children: <Widget>[ ElevatedButton.icon( onPressed: () {}, icon: const Icon(Icons.sunny), label: const Text('ElevatedButton'), iconAlignment: _iconAlignment, ), FilledButton.icon( onPressed: () {}, icon: const Icon(Icons.beach_access), label: const Text('FilledButton'), iconAlignment: _iconAlignment, ), FilledButton.tonalIcon( onPressed: () {}, icon: const Icon(Icons.cloud), label: const Text('FilledButton Tonal'), iconAlignment: _iconAlignment, ), OutlinedButton.icon( onPressed: () {}, icon: const Icon(Icons.light), label: const Text('OutlinedButton'), iconAlignment: _iconAlignment, ), TextButton.icon( onPressed: () {}, icon: const Icon(Icons.flight_takeoff), label: const Text('TextButton'), iconAlignment: _iconAlignment, ), ], ), const Spacer(), OverflowBar( alignment: MainAxisAlignment.spaceEvenly, overflowAlignment: OverflowBarAlignment.center, spacing: 10, overflowSpacing: 10, children: <Widget>[ Column( children: <Widget>[ const Text('Icon alignment'), const SizedBox(height: 10), SegmentedButton<IconAlignment>( onSelectionChanged: (Set<IconAlignment> value) { setState(() { _iconAlignment = value.first; }); }, selected: <IconAlignment>{ _iconAlignment }, segments: IconAlignment.values.map((IconAlignment iconAlignment) { return ButtonSegment<IconAlignment>( value: iconAlignment, label: Text(iconAlignment.name), ); }).toList(), ), ], ), Column( children: <Widget>[ const Text('Text direction'), const SizedBox(height: 10), SegmentedButton<TextDirection>( onSelectionChanged: (Set<TextDirection> value) { setState(() { _textDirection = value.first; }); }, selected: <TextDirection>{ _textDirection }, segments: const <ButtonSegment<TextDirection>>[ ButtonSegment<TextDirection>( value: TextDirection.ltr, label: Text('LTR'), ), ButtonSegment<TextDirection>( value: TextDirection.rtl, label: Text('RTL'), ), ], ), ], ), ], ), const Spacer(), ], ), ), ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [Card].
void main() => runApp(const CardExampleApp());
class CardExampleApp extends StatelessWidget { const CardExampleApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: const Text('Card Sample')), body: const CardExample(), ), ); }}
class CardExample extends StatelessWidget { const CardExample({super.key});
@override Widget build(BuildContext context) { return Center( child: Card( child: Column( mainAxisSize: MainAxisSize.min, children: <Widget>[ const ListTile( leading: Icon(Icons.album), title: Text('The Enchanted Nightingale'), subtitle: Text('Music by Julie Gable. Lyrics by Sidney Stein.'), ), Row( mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[ TextButton( child: const Text('BUY TICKETS'), onPressed: () {/* ... */}, ), const SizedBox(width: 8), TextButton( child: const Text('LISTEN'), onPressed: () {/* ... */}, ), const SizedBox(width: 8), ], ), ], ), ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [Card].
void main() => runApp(const CardExampleApp());
class CardExampleApp extends StatelessWidget { const CardExampleApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: const Text('Card Sample')), body: const CardExample(), ), ); }}
class CardExample extends StatelessWidget { const CardExample({super.key});
@override Widget build(BuildContext context) { return Center( child: Card( // clipBehavior is necessary because, without it, the InkWell's animation // will extend beyond the rounded edges of the [Card] (see https://github.com/flutter/flutter/issues/109776) // This comes with a small performance cost, and you should not set [clipBehavior] // unless you need it. clipBehavior: Clip.hardEdge, child: InkWell( splashColor: Colors.blue.withAlpha(30), onTap: () { debugPrint('Card tapped.'); }, child: const SizedBox( width: 300, height: 100, child: Text('A card that can be tapped'), ), ), ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [Card].
void main() { runApp(const CardExamplesApp());}
class CardExamplesApp extends StatelessWidget { const CardExamplesApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: const Text('Card Examples')), body: const Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Card(child: _SampleCard(cardName: 'Elevated Card')), Card.filled(child: _SampleCard(cardName: 'Filled Card')), Card.outlined(child: _SampleCard(cardName: 'Outlined Card')), ], ), ), ), ); }}
class _SampleCard extends StatelessWidget { const _SampleCard({required this.cardName}); final String cardName;
@override Widget build(BuildContext context) { return SizedBox( width: 300, height: 100, child: Center(child: Text(cardName)), ); }}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [Carousel].
void main() => runApp(const CarouselExampleApp());
class CarouselExampleApp extends StatelessWidget { const CarouselExampleApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( appBar: AppBar( title: const Text('Carousel Sample'), ), body: const CarouselExample(), ), ); }}
class CarouselExample extends StatefulWidget { const CarouselExample({super.key});
@override State<CarouselExample> createState() => _CarouselExampleState();}
class _CarouselExampleState extends State<CarouselExample> { @override Widget build(BuildContext context) { return Center( child: ConstrainedBox( constraints: const BoxConstraints(maxHeight: 200), child: CarouselView( itemExtent: 330, shrinkExtent: 200, children: List<Widget>.generate(20, (int index) { return UncontainedLayoutCard(index: index, label: 'Item $index'); }), ), ), ); }}
class UncontainedLayoutCard extends StatelessWidget { const UncontainedLayoutCard({ super.key, required this.index, required this.label, });
final int index; final String label;
@override Widget build(BuildContext context) { return ColoredBox( color: Colors.primaries[index % Colors.primaries.length].withOpacity(0.5), child: Center( child: Text( label, style: const TextStyle(color: Colors.white, fontSize: 20), overflow: TextOverflow.clip, softWrap: false, ), ), ); }}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [Checkbox].
void main() => runApp(const CheckboxExampleApp());
class CheckboxExampleApp extends StatelessWidget { const CheckboxExampleApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: const Text('Checkbox Sample')), body: const Center( child: CheckboxExample(), ), ), ); }}
class CheckboxExample extends StatefulWidget { const CheckboxExample({super.key});
@override State<CheckboxExample> createState() => _CheckboxExampleState();}
class _CheckboxExampleState extends State<CheckboxExample> { bool isChecked = false;
@override Widget build(BuildContext context) { Color getColor(Set<MaterialState> states) { const Set<MaterialState> interactiveStates = <MaterialState>{ MaterialState.pressed, MaterialState.hovered, MaterialState.focused, }; if (states.any(interactiveStates.contains)) { return Colors.blue; } return Colors.red; }
return Checkbox( checkColor: Colors.white, fillColor: MaterialStateProperty.resolveWith(getColor), value: isChecked, onChanged: (bool? value) { setState(() { isChecked = value!; }); }, ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for M3 [Checkbox] with error state.
void main() => runApp(const CheckboxExampleApp());
class CheckboxExampleApp extends StatelessWidget { const CheckboxExampleApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData(useMaterial3: true, colorSchemeSeed: const Color(0xff6750a4)), title: 'Checkbox Sample', home: Scaffold( appBar: AppBar(title: const Text('Checkbox Sample')), body: const Center( child: CheckboxExample(), ), ), ); }}
class CheckboxExample extends StatefulWidget { const CheckboxExample({super.key});
@override State<CheckboxExample> createState() => _CheckboxExampleState();}
class _CheckboxExampleState extends State<CheckboxExample> { bool? isChecked = true;
@override Widget build(BuildContext context) { return Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Checkbox( tristate: true, value: isChecked, onChanged: (bool? value) { setState(() { isChecked = value; }); }, ), Checkbox( isError: true, tristate: true, value: isChecked, onChanged: (bool? value) { setState(() { isChecked = value; }); }, ), Checkbox( isError: true, tristate: true, value: isChecked, onChanged: null, ), ], ); }}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
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 { const CheckboxListTileApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData(useMaterial3: true), home: const CheckboxListTileExample(), ); }}
class CheckboxListTileExample extends StatefulWidget { const CheckboxListTileExample({super.key});
@override State<CheckboxListTileExample> createState() => _CheckboxListTileExampleState();}
class _CheckboxListTileExampleState extends State<CheckboxListTileExample> { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('CheckboxListTile Sample')), body: Center( child: CheckboxListTile( title: const Text('Animate Slowly'), value: timeDilation != 1.0, onChanged: (bool? value) { setState(() { timeDilation = value! ? 10.0 : 1.0; }); }, secondary: const Icon(Icons.hourglass_empty), ), ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [CheckboxListTile].
void main() => runApp(const CheckboxListTileApp());
class CheckboxListTileApp extends StatelessWidget { const CheckboxListTileApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData(useMaterial3: true), home: const CheckboxListTileExample(), ); }}
class CheckboxListTileExample extends StatefulWidget { const CheckboxListTileExample({super.key});
@override State<CheckboxListTileExample> createState() => _CheckboxListTileExampleState();}
class _CheckboxListTileExampleState extends State<CheckboxListTileExample> { bool checkboxValue1 = true; bool checkboxValue2 = true; bool checkboxValue3 = true;
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('CheckboxListTile Sample')), body: Column( children: <Widget>[ CheckboxListTile( value: checkboxValue1, onChanged: (bool? value) { setState(() { checkboxValue1 = value!; }); }, title: const Text('Headline'), subtitle: const Text('Supporting text'), ), const Divider(height: 0), CheckboxListTile( value: checkboxValue2, onChanged: (bool? value) { setState(() { checkboxValue2 = value!; }); }, 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.'), ), const Divider(height: 0), CheckboxListTile( value: checkboxValue3, onChanged: (bool? value) { setState(() { checkboxValue3 = value!; }); }, 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."), isThreeLine: true, ), const Divider(height: 0), ], ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
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 { const LabeledCheckboxApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData(useMaterial3: true), home: const LabeledCheckboxExample(), ); }}
class LinkedLabelCheckbox extends StatelessWidget { const LinkedLabelCheckbox({ super.key, required this.label, required this.padding, required this.value, required this.onChanged, });
final String label; final EdgeInsets padding; final bool value; final ValueChanged<bool> onChanged;
@override Widget build(BuildContext context) { return Padding( padding: padding, child: Row( children: <Widget>[ Expanded( child: RichText( text: TextSpan( text: label, style: const TextStyle( color: Colors.blueAccent, decoration: TextDecoration.underline, ), recognizer: TapGestureRecognizer() ..onTap = () { debugPrint('Label has been tapped.'); }, ), ), ), Checkbox( value: value, onChanged: (bool? newValue) { onChanged(newValue!); }, ), ], ), ); }}
class LabeledCheckboxExample extends StatefulWidget { const LabeledCheckboxExample({super.key});
@override State<LabeledCheckboxExample> createState() => _LabeledCheckboxExampleState();}
class _LabeledCheckboxExampleState extends State<LabeledCheckboxExample> { bool _isSelected = false;
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Custom Labeled Checkbox Sample')), body: Center( child: LinkedLabelCheckbox( label: 'Linked, tappable label text', padding: const EdgeInsets.symmetric(horizontal: 20.0), value: _isSelected, onChanged: (bool newValue) { setState(() { _isSelected = newValue; }); }, ), ), ); }}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for custom labeled checkbox.
void main() => runApp(const LabeledCheckboxApp());
class LabeledCheckboxApp extends StatelessWidget { const LabeledCheckboxApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData(useMaterial3: true), home: const LabeledCheckboxExample(), ); }}
class LabeledCheckbox extends StatelessWidget { const LabeledCheckbox({ super.key, required this.label, required this.padding, required this.value, required this.onChanged, });
final String label; final EdgeInsets padding; final bool value; final ValueChanged<bool> onChanged;
@override Widget build(BuildContext context) { return InkWell( onTap: () { onChanged(!value); }, child: Padding( padding: padding, child: Row( children: <Widget>[ Expanded(child: Text(label)), Checkbox( value: value, onChanged: (bool? newValue) { onChanged(newValue!); }, ), ], ), ), ); }}
class LabeledCheckboxExample extends StatefulWidget { const LabeledCheckboxExample({super.key});
@override State<LabeledCheckboxExample> createState() => _LabeledCheckboxExampleState();}
class _LabeledCheckboxExampleState extends State<LabeledCheckboxExample> { bool _isSelected = false;
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Custom Labeled Checkbox Sample')), body: Center( child: LabeledCheckbox( label: 'This is the label text', padding: const EdgeInsets.symmetric(horizontal: 20.0), value: _isSelected, onChanged: (bool newValue) { setState(() { _isSelected = newValue; }); }, ), ), ); }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [ChipAttributes.avatarBoxConstraints].
void main() => runApp(const AvatarBoxConstraintsApp());
class AvatarBoxConstraintsApp extends StatelessWidget { const AvatarBoxConstraintsApp({super.key});
@override Widget build(BuildContext context) { return const MaterialApp( home: Scaffold( body: Center( child: AvatarBoxConstraintsExample(), ), ), ); }}
class AvatarBoxConstraintsExample extends StatelessWidget { const AvatarBoxConstraintsExample({super.key});
@override Widget build(BuildContext context) { return const Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ RawChip( avatarBoxConstraints: BoxConstraints.tightForFinite(), avatar: Icon(Icons.star), label: SizedBox( width: 150, child: Text( 'One line text.', maxLines: 3, overflow: TextOverflow.ellipsis, ), ), ), SizedBox(height: 10), RawChip( avatarBoxConstraints: BoxConstraints.tightForFinite(), avatar: Icon(Icons.star), label: SizedBox( width: 150, child: Text( 'This text will wrap into two lines.', maxLines: 3, overflow: TextOverflow.ellipsis, ), ), ), SizedBox(height: 10), RawChip( avatarBoxConstraints: BoxConstraints.tightForFinite(), avatar: Icon(Icons.star), label: SizedBox( width: 150, child: Text( 'This is a very long text that will wrap into three lines.', maxLines: 3, overflow: TextOverflow.ellipsis, ), ), ), ], ); }}novelforge-project/docs/project_enhancement_completion_report.pdf+2-2
novelforge-project/flutter/examples/api/android/build.gradleAdded+33
novelforge-project/flutter/examples/api/android/gradle.propertiesAdded+3
novelforge-project/flutter/examples/api/android/settings.gradleAdded+15
novelforge-project/flutter/examples/api/ios/PodfileAdded+41
novelforge-project/flutter/examples/api/lib/material/about/about_list_tile.0.dartAdded+81
novelforge-project/flutter/examples/api/lib/material/action_buttons/action_icon_theme.0.dartAdded+121
novelforge-project/flutter/examples/api/lib/material/action_chip/action_chip.0.dartAdded+52
novelforge-project/flutter/examples/api/lib/material/animated_icon/animated_icon.0.dartAdded+72
novelforge-project/flutter/examples/api/lib/material/animated_icon/animated_icons_data.0.dartAdded+105
novelforge-project/flutter/examples/api/lib/material/app/app.0.dartAdded+87
novelforge-project/flutter/examples/api/lib/material/app_bar/app_bar.0.dartAdded+69
novelforge-project/flutter/examples/api/lib/material/app_bar/app_bar.1.dartAdded+124
novelforge-project/flutter/examples/api/lib/material/app_bar/app_bar.2.dartAdded+47
novelforge-project/flutter/examples/api/lib/material/app_bar/app_bar.3.dartAdded+112
novelforge-project/flutter/examples/api/lib/material/app_bar/app_bar.4.dartAdded+149
novelforge-project/flutter/examples/api/lib/material/app_bar/sliver_app_bar.1.dartAdded+132
novelforge-project/flutter/examples/api/lib/material/app_bar/sliver_app_bar.2.dartAdded+53
novelforge-project/flutter/examples/api/lib/material/app_bar/sliver_app_bar.3.dartAdded+53
novelforge-project/flutter/examples/api/lib/material/app_bar/sliver_app_bar.4.dartAdded+90
novelforge-project/flutter/examples/api/lib/material/autocomplete/autocomplete.0.dartAdded+60
novelforge-project/flutter/examples/api/lib/material/autocomplete/autocomplete.1.dartAdded+90
novelforge-project/flutter/examples/api/lib/material/autocomplete/autocomplete.2.dartAdded+95
novelforge-project/flutter/examples/api/lib/material/autocomplete/autocomplete.3.dartAdded+172
novelforge-project/flutter/examples/api/lib/material/autocomplete/autocomplete.4.dartAdded+234
novelforge-project/flutter/examples/api/lib/material/badge/badge.0.dartAdded+54
novelforge-project/flutter/examples/api/lib/material/banner/material_banner.0.dartAdded+49
novelforge-project/flutter/examples/api/lib/material/banner/material_banner.1.dartAdded+52
novelforge-project/flutter/examples/api/lib/material/bottom_app_bar/bottom_app_bar.1.dartAdded+157
novelforge-project/flutter/examples/api/lib/material/bottom_app_bar/bottom_app_bar.2.dartAdded+192
novelforge-project/flutter/examples/api/lib/material/bottom_navigation_bar/bottom_navigation_bar.0.dartAdded+83
novelforge-project/flutter/examples/api/lib/material/bottom_navigation_bar/bottom_navigation_bar.1.dartAdded+95
novelforge-project/flutter/examples/api/lib/material/bottom_navigation_bar/bottom_navigation_bar.2.dartAdded+109
novelforge-project/flutter/examples/api/lib/material/bottom_sheet/show_bottom_sheet.0.dartAdded+101
novelforge-project/flutter/examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.0.dartAdded+60
novelforge-project/flutter/examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.1.dartAdded+63
novelforge-project/flutter/examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.2.dartAdded+101
novelforge-project/flutter/examples/api/lib/material/button_style/button_style.0.dartAdded+69
novelforge-project/flutter/examples/api/lib/material/button_style_button/button_style_button.icon_alignment.0.dartAdded+147
novelforge-project/flutter/examples/api/lib/material/card/card.0.dartAdded+60
novelforge-project/flutter/examples/api/lib/material/card/card.1.dartAdded+51
novelforge-project/flutter/examples/api/lib/material/card/card.2.dartAdded+48
novelforge-project/flutter/examples/api/lib/material/carousel/carousel.0.dartAdded+77
novelforge-project/flutter/examples/api/lib/material/checkbox/checkbox.0.dartAdded+62
novelforge-project/flutter/examples/api/lib/material/checkbox/checkbox.1.dartAdded+72
novelforge-project/flutter/examples/api/lib/material/checkbox_list_tile/checkbox_list_tile.0.dartAdded+50
novelforge-project/flutter/examples/api/lib/material/checkbox_list_tile/checkbox_list_tile.1.dartAdded+81
novelforge-project/flutter/examples/api/lib/material/checkbox_list_tile/custom_labeled_checkbox.0.dartAdded+100
novelforge-project/flutter/examples/api/lib/material/checkbox_list_tile/custom_labeled_checkbox.1.dartAdded+89
novelforge-project/flutter/examples/api/lib/material/chip/chip_attributes.avatar_box_constraints.0.dartAdded+75