forked from flutter/packages
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
459 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// 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 'use_cases.dart'; | ||
|
||
class AutoCompleteUseCase extends UseCase { | ||
|
||
@override | ||
String get name => 'AutoComplete'; | ||
|
||
@override | ||
String get route => '/auto-complete'; | ||
|
||
@override | ||
Widget build(BuildContext context) => const _MainWidget(); | ||
} | ||
|
||
class _MainWidget extends StatefulWidget { | ||
const _MainWidget(); | ||
|
||
@override | ||
State<_MainWidget> createState() => _MainWidgetState(); | ||
} | ||
|
||
class _MainWidgetState extends State<_MainWidget> { | ||
static const List<String> _kOptions = <String>[ | ||
'apple', | ||
'banana', | ||
'lemon', | ||
]; | ||
|
||
static Widget _fieldViewBuilder(BuildContext context, TextEditingController textEditingController, FocusNode focusNode, VoidCallback onFieldSubmitted) { | ||
return TextFormField( | ||
focusNode: focusNode, | ||
autofocus: true, | ||
controller: textEditingController, | ||
onFieldSubmitted: (String value) { | ||
onFieldSubmitted(); | ||
}, | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
backgroundColor: Theme.of(context).colorScheme.inversePrimary, | ||
title: const Text('AutoComplete'), | ||
), | ||
body: Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
Text( | ||
'Type below to autocomplete the following possible results: $_kOptions.'), | ||
Autocomplete<String>( | ||
optionsBuilder: (TextEditingValue textEditingValue) { | ||
if (textEditingValue.text == '') { | ||
return const Iterable<String>.empty(); | ||
} | ||
return _kOptions.where((String option) { | ||
return option.contains(textEditingValue.text.toLowerCase()); | ||
}); | ||
}, | ||
fieldViewBuilder: _fieldViewBuilder, | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// 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 'use_cases.dart'; | ||
|
||
class BadgeUseCase extends UseCase { | ||
|
||
@override | ||
String get name => 'Badge'; | ||
|
||
@override | ||
String get route => '/badge'; | ||
|
||
@override | ||
Widget build(BuildContext context) => const MainWidget(); | ||
} | ||
|
||
class MainWidget extends StatefulWidget { | ||
const MainWidget({super.key}); | ||
|
||
@override | ||
State<MainWidget> createState() => MainWidgetState(); | ||
} | ||
|
||
class MainWidgetState extends State<MainWidget> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
backgroundColor: Theme.of(context).colorScheme.inversePrimary, | ||
title: const Text('Badge'), | ||
), | ||
body: const Center( | ||
child: Badge( | ||
label: Text( | ||
'5', | ||
semanticsLabel: '5 new messages', | ||
style: TextStyle(color: Colors.white), | ||
), | ||
backgroundColor: Colors.green, | ||
child: Icon(Icons.mail, semanticLabel: 'Messages'), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// 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 'use_cases.dart'; | ||
|
||
class MaterialBannerUseCase extends UseCase { | ||
|
||
@override | ||
String get name => 'MaterialBanner'; | ||
|
||
@override | ||
String get route => '/material_banner'; | ||
|
||
@override | ||
Widget build(BuildContext context) => const MainWidget(); | ||
} | ||
|
||
class MainWidget extends StatefulWidget { | ||
const MainWidget({super.key}); | ||
|
||
@override | ||
State<MainWidget> createState() => MainWidgetState(); | ||
} | ||
|
||
class MainWidgetState extends State<MainWidget> { | ||
double currentSliderValue = 20; | ||
ScaffoldFeatureController<MaterialBanner, MaterialBannerClosedReason>? controller; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
VoidCallback? onPress; | ||
if (controller == null) { | ||
onPress = () { | ||
setState(() { | ||
controller = ScaffoldMessenger.of(context).showMaterialBanner( | ||
MaterialBanner( | ||
padding: const EdgeInsets.all(20), | ||
content: const Text('Hello, I am a Material Banner'), | ||
leading: const Icon(Icons.agriculture_outlined), | ||
backgroundColor: Colors.green, | ||
actions: <Widget>[ | ||
TextButton( | ||
onPressed: () { | ||
controller!.close(); | ||
setState(() { | ||
controller = null; | ||
}); | ||
}, | ||
child: const Text('DISMISS'), | ||
), | ||
], | ||
), | ||
); | ||
}); | ||
}; | ||
} | ||
return Scaffold( | ||
appBar: AppBar( | ||
backgroundColor: Theme.of(context).colorScheme.inversePrimary, | ||
title: const Text('MaterialBanner'), | ||
), | ||
body: Center( | ||
child: ElevatedButton( | ||
autofocus: true, | ||
onPressed: onPress, | ||
child: const Text('Show a MaterialBanner'), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// 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 'use_cases.dart'; | ||
|
||
class NavigationBarUseCase extends UseCase { | ||
|
||
@override | ||
String get name => 'NavigationBar'; | ||
|
||
@override | ||
String get route => '/navigation-bar'; | ||
|
||
@override | ||
Widget build(BuildContext context) => const MainWidget(); | ||
} | ||
|
||
class MainWidget extends StatefulWidget { | ||
const MainWidget({super.key}); | ||
|
||
@override | ||
State<MainWidget> createState() => MainWidgetState(); | ||
} | ||
|
||
class MainWidgetState extends State<MainWidget> { | ||
int currentPageIndex = 0; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
backgroundColor: Theme.of(context).colorScheme.inversePrimary, | ||
title: const Text('NavigationBar'), | ||
), | ||
bottomNavigationBar: NavigationBar( | ||
onDestinationSelected: (int index) { | ||
setState(() { | ||
currentPageIndex = index; | ||
}); | ||
}, | ||
indicatorColor: Colors.amber[800], | ||
selectedIndex: currentPageIndex, | ||
destinations: const <Widget>[ | ||
NavigationDestination( | ||
selectedIcon: Icon(Icons.home), | ||
icon: Icon(Icons.home_outlined), | ||
label: 'Home', | ||
), | ||
NavigationDestination( | ||
icon: Icon(Icons.business), | ||
label: 'Business', | ||
), | ||
NavigationDestination( | ||
selectedIcon: Icon(Icons.school), | ||
icon: Icon(Icons.school_outlined), | ||
label: 'School', | ||
), | ||
], | ||
), | ||
body: <Widget>[ | ||
Container( | ||
alignment: Alignment.center, | ||
child: const Text('Page 1'), | ||
), | ||
Container( | ||
alignment: Alignment.center, | ||
child: const Text('Page 2'), | ||
), | ||
Container( | ||
alignment: Alignment.center, | ||
child: const Text('Page 3'), | ||
), | ||
][currentPageIndex], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// 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 'use_cases.dart'; | ||
|
||
class TextButtonUseCase extends UseCase { | ||
|
||
@override | ||
String get name => 'TextButton'; | ||
|
||
@override | ||
String get route => '/text-button'; | ||
|
||
@override | ||
Widget build(BuildContext context) => const MainWidget(); | ||
} | ||
|
||
class MainWidget extends StatefulWidget { | ||
const MainWidget({super.key}); | ||
|
||
@override | ||
State<MainWidget> createState() => MainWidgetState(); | ||
} | ||
|
||
class MainWidgetState extends State<MainWidget> { | ||
double currentSliderValue = 20; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
backgroundColor: Theme.of(context).colorScheme.inversePrimary, | ||
title: const Text('TextButton'), | ||
), | ||
body: Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
TextButton( | ||
onPressed: () { }, | ||
child: const Text('Text button'), | ||
), | ||
const TextButton( | ||
onPressed: null, | ||
child: Text('Text button disabled'), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.