|
1 | 1 | import 'package:fluent_ui/fluent_ui.dart' as fluent; |
2 | | -import 'package:fluent_ui/fluent_ui.dart'; |
3 | 2 | import 'package:flutter/widgets.dart'; |
4 | 3 | import 'package:flutter_search_bar/main.dart'; |
5 | 4 | import 'package:flutter_search_bar/platform_search.dart'; |
6 | 5 |
|
| 6 | +final _kPlatformNames = [...platforms.map((element) => element.name)]; // map cuz AutoSuggestBox works with Strings |
| 7 | + |
| 8 | +final _autoSuggestBoxKey = GlobalKey(); // use the key to keep the state of the AutoSuggestBox |
| 9 | + |
7 | 10 | class WindowsSearchDelegate extends AbstractPlatformSearchDelegate { |
8 | 11 | final List<PlatformItem> Function(String text) search; |
| 12 | + |
9 | 13 | WindowsSearchDelegate(this.search); |
10 | 14 |
|
11 | | - Widget buildResults(BuildContext context) { |
12 | | - return ListView.builder( |
13 | | - itemCount: 10, |
14 | | - itemBuilder: (context, index) { |
15 | | - return Row( |
16 | | - children: [ |
17 | | - Padding( |
18 | | - padding: const EdgeInsets.all(8.0), |
19 | | - child: Text('Item $index'), |
20 | | - ), |
21 | | - ], |
22 | | - ); |
23 | | - }, |
24 | | - ); |
25 | | - } |
| 15 | + @override |
| 16 | + Widget buildResults(BuildContext context) => throw UnimplementedError(); |
26 | 17 |
|
27 | 18 | @override |
28 | | - Widget buildSuggestions(BuildContext context) { |
29 | | - return ListView.builder( |
30 | | - itemCount: 10, |
31 | | - itemBuilder: (context, index) { |
32 | | - return Row( |
33 | | - children: [ |
34 | | - Padding( |
35 | | - padding: const EdgeInsets.all(8.0), |
36 | | - child: Text('Item $index'), |
37 | | - ), |
38 | | - ], |
39 | | - ); |
40 | | - }, |
41 | | - ); |
42 | | - } |
| 19 | + Widget buildSuggestions(BuildContext context) => throw UnimplementedError(); |
43 | 20 |
|
44 | 21 | @override |
45 | 22 | Widget buildScaffold(Widget? body, BuildContext context) { |
46 | | - const BorderSide _kDefaultRoundedBorderSide = BorderSide( |
47 | | - style: BorderStyle.solid, |
48 | | - width: 0.8, |
49 | | - ); |
50 | | - return fluent.Scaffold( |
51 | | - left: NavigationPanel( |
52 | | - currentIndex: 2, |
53 | | - menu: NavigationPanelMenuItem( |
54 | | - icon: IconButton( |
55 | | - icon: fluent.Icon(Icons.menu), |
56 | | - onPressed: () {}, |
57 | | - ), |
58 | | - ), |
59 | | - items: [ |
60 | | - NavigationPanelSectionHeader( |
61 | | - header: fluent.AutoSuggestBox<PlatformItem>( |
62 | | - onSelected: (PlatformItem item) => print(item.name), |
63 | | - controller: queryTextController, |
64 | | - sorter: (String text, List items) => search.call(text), |
65 | | - items: platforms, |
66 | | - noResultsFound: (context) => ListTile( |
67 | | - title: DefaultTextStyle( |
68 | | - style: TextStyle( |
69 | | - fontWeight: FontWeight.normal, color: Colors.black), |
70 | | - child: Text('No results found'), |
71 | | - ), |
72 | | - ), |
73 | | - itemBuilder: (context, item) { |
74 | | - return PlatformItemWidget( |
75 | | - item, |
76 | | - small: true, |
77 | | - ); |
78 | | - }, |
79 | | - textBoxBuilder: (context, controller, fn, key) => TextBox( |
80 | | - key: key, |
81 | | - controller: controller, |
82 | | - focusNode: fn, |
83 | | - suffixMode: OverlayVisibilityMode.always, |
84 | | - suffix: fluent.Row( |
85 | | - children: [ |
86 | | - controller.text.isNotEmpty |
87 | | - ? IconButton( |
88 | | - icon: fluent.Icon(Icons.close), |
89 | | - onPressed: () { |
90 | | - controller.clear(); |
91 | | - fn.unfocus(); |
92 | | - }, |
93 | | - ) |
94 | | - : fluent.SizedBox.shrink(), |
95 | | - IconButton( |
96 | | - icon: fluent.Icon(Icons.search), |
97 | | - onPressed: () {}, |
98 | | - ), |
99 | | - ], |
100 | | - ), |
101 | | - placeholder: searchFieldLabel, |
102 | | - decoration: BoxDecoration( |
103 | | - color: Colors.white, |
104 | | - border: Border( |
105 | | - top: _kDefaultRoundedBorderSide, |
106 | | - bottom: _kDefaultRoundedBorderSide, |
107 | | - left: _kDefaultRoundedBorderSide, |
108 | | - right: _kDefaultRoundedBorderSide, |
109 | | - ), |
110 | | - borderRadius: fn.hasFocus |
111 | | - ? BorderRadius.vertical(top: Radius.circular(3.0)) |
112 | | - : BorderRadius.all(Radius.circular(3.0)), |
113 | | - ), |
| 23 | + return fluent.ScaffoldPage( |
| 24 | + content: Padding( |
| 25 | + padding: EdgeInsets.symmetric(horizontal: 16, vertical: 32), |
| 26 | + child: Column( |
| 27 | + children: [ |
| 28 | + fluent.AutoSuggestBox<String>( |
| 29 | + key: _autoSuggestBoxKey, |
| 30 | + placeholder: 'Search', |
| 31 | + onSelected: (item) => print(item), |
| 32 | + controller: queryTextController, |
| 33 | + items: _kPlatformNames, |
114 | 34 | ), |
115 | | - )), |
116 | | - ], |
| 35 | + Spacer(), |
| 36 | + ], |
| 37 | + ), |
117 | 38 | ), |
118 | | - body: Container(), |
119 | 39 | ); |
120 | 40 | } |
121 | 41 | } |
0 commit comments