Skip to content

Commit

Permalink
feat: restructure suggestions box
Browse files Browse the repository at this point in the history
  • Loading branch information
clragon authored and sjmcdowall committed Nov 25, 2023
1 parent 221a369 commit 2b3a84c
Show file tree
Hide file tree
Showing 25 changed files with 1,783 additions and 1,294 deletions.
94 changes: 56 additions & 38 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,59 +17,76 @@ class MyApp extends StatefulWidget {

class _MyAppState extends State<MyApp> {
bool isCupertino = !kIsWeb && Platform.isIOS;
bool darkMode = false;

@override
Widget build(BuildContext context) {
if (!isCupertino) {
return MaterialApp(
title: 'flutter_typeahead demo',
scrollBehavior: const MaterialScrollBehavior().copyWith(
dragDevices: {PointerDeviceKind.mouse, PointerDeviceKind.touch}),
scrollBehavior: const MaterialScrollBehavior().copyWith(dragDevices: {
PointerDeviceKind.mouse,
PointerDeviceKind.touch,
}),
theme: darkMode ? ThemeData.dark() : ThemeData.light(),
home: DefaultTabController(
length: 4,
child: Scaffold(
appBar: AppBar(
leading: IconButton(
icon: const Icon(Icons.phone_iphone),
onPressed: () => setState(() => isCupertino = true),
),
title: const Text('Examples'),
bottom: const TabBar(
isScrollable: true,
tabs: [
Tab(text: 'Navigation'),
Tab(text: 'Form'),
Tab(text: 'Scroll'),
Tab(text: 'Alternative Layout')
],
),
appBar: AppBar(
leading: IconButton(
icon: const Icon(Icons.phone_iphone),
onPressed: () => setState(() => isCupertino = true),
),
body: GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: const TabBarView(
children: [
NavigationExample(),
FormExample(),
ScrollExample(),
LayoutExample(),
],
title: const Text('Examples'),
actions: [
IconButton(
icon: darkMode
? const Icon(Icons.light_mode)
: const Icon(Icons.dark_mode),
onPressed: () => setState(() => darkMode = !darkMode),
),
)),
],
bottom: const TabBar(
isScrollable: true,
tabs: [
Tab(text: 'Navigation'),
Tab(text: 'Form'),
Tab(text: 'Scroll'),
Tab(text: 'Alternative Layout')
],
),
),
body: GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: const TabBarView(
children: [
NavigationExample(),
FormExample(),
ScrollExample(),
LayoutExample(),
],
),
),
),
),
);
} else {
return CupertinoApp(
title: 'Cupertino demo',
theme: const CupertinoThemeData(
brightness: Brightness.light,
theme: CupertinoThemeData(
brightness: darkMode ? Brightness.dark : Brightness.light,
),
home: Scaffold(
appBar: CupertinoNavigationBar(
leading: IconButton(
icon: const Icon(Icons.android),
onPressed: () => setState(() {
isCupertino = false;
}),
icon: const Icon(CupertinoIcons.device_phone_portrait),
onPressed: () => setState(() => isCupertino = false),
),
trailing: IconButton(
icon: darkMode
? const Icon(CupertinoIcons.sun_max)
: const Icon(CupertinoIcons.moon),
onPressed: () => setState(() => darkMode = !darkMode),
),
middle: const Text('Cupertino demo'),
),
Expand Down Expand Up @@ -110,7 +127,7 @@ class NavigationExample extends StatelessWidget {
title: Text(suggestion['name']!),
subtitle: Text(suggestion['price']!),
),
itemSeparatorBuilder: (context, index) => const Divider(height: 1),
itemSeparatorBuilder: (context, index) => const Divider(),
onSuggestionSelected: (suggestion) {
Navigator.of(context).push<void>(
MaterialPageRoute(
Expand Down Expand Up @@ -143,7 +160,7 @@ class _FormExampleState extends State<FormExample> {

String? _selectedCity;

SuggestionsBox suggestionBoxController = SuggestionsBox();
SuggestionsBoxController suggestionBoxController = SuggestionsBoxController();

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -174,7 +191,7 @@ class _FormExampleState extends State<FormExample> {
suggestionsBox,
onSuggestionSelected: (suggestion) =>
_typeAheadController.text = suggestion,
suggestionsBox: suggestionBoxController,
suggestionsBoxController: suggestionBoxController,
validator: (value) =>
value!.isEmpty ? 'Please select a city' : null,
onSaved: (value) => _selectedCity = value,
Expand Down Expand Up @@ -421,7 +438,8 @@ class CupertinoFormExample extends StatefulWidget {
class _FavoriteCitiesPage extends State<CupertinoFormExample> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
final TextEditingController _typeAheadController = TextEditingController();
final SuggestionsBox _suggestionsBoxController = SuggestionsBox();
final SuggestionsBoxController _suggestionsBoxController =
SuggestionsBoxController();
String favoriteCity = 'Unavailable';

@override
Expand All @@ -440,7 +458,7 @@ class _FavoriteCitiesPage extends State<CupertinoFormExample> {
const Text('What is your favorite city?'),
const SizedBox(height: 10),
CupertinoTypeAheadFormField(
suggestionsBox: _suggestionsBoxController,
suggestionsBoxController: _suggestionsBoxController,
suggestionsBoxDecoration: CupertinoSuggestionsBoxDecoration(
borderRadius: BorderRadius.circular(8),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/flutter_typeahead.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
library flutter_typeahead;

export 'package:flutter_typeahead/src/typedef.dart';
export 'package:flutter_typeahead/src/common/suggestions_box/suggestions_box_controller.dart';
export 'package:flutter_typeahead/src/material/field/typeahead_field.dart';
export 'package:flutter_typeahead/src/material/field/text_field_configuration.dart';
export 'package:flutter_typeahead/src/material/field/typeahead_form_field.dart';
export 'package:flutter_typeahead/src/material/suggestions_box/suggestions_box_decoration.dart';
export 'package:flutter_typeahead/src/material/suggestions_box/suggestions_list.dart';
export 'package:flutter_typeahead/src/common/suggestions_box/suggestions_box.dart';
export 'package:flutter_typeahead/src/cupertino/field/cupertino_typeahead_field.dart';
export 'package:flutter_typeahead/src/cupertino/field/cupertino_text_field_configuration.dart';
export 'package:flutter_typeahead/src/cupertino/field/cupertino_typeahead_form_field.dart';
Expand Down
Loading

0 comments on commit 2b3a84c

Please sign in to comment.