diff --git a/lib/windows_search_delegate.dart b/lib/windows_search_delegate.dart index 48a092f..7921329 100644 --- a/lib/windows_search_delegate.dart +++ b/lib/windows_search_delegate.dart @@ -1,121 +1,41 @@ import 'package:fluent_ui/fluent_ui.dart' as fluent; -import 'package:fluent_ui/fluent_ui.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_search_bar/main.dart'; import 'package:flutter_search_bar/platform_search.dart'; +final _kPlatformNames = [...platforms.map((element) => element.name)]; // map cuz AutoSuggestBox works with Strings + +final _autoSuggestBoxKey = GlobalKey(); // use the key to keep the state of the AutoSuggestBox + class WindowsSearchDelegate extends AbstractPlatformSearchDelegate { final List Function(String text) search; + WindowsSearchDelegate(this.search); - Widget buildResults(BuildContext context) { - return ListView.builder( - itemCount: 10, - itemBuilder: (context, index) { - return Row( - children: [ - Padding( - padding: const EdgeInsets.all(8.0), - child: Text('Item $index'), - ), - ], - ); - }, - ); - } + @override + Widget buildResults(BuildContext context) => throw UnimplementedError(); @override - Widget buildSuggestions(BuildContext context) { - return ListView.builder( - itemCount: 10, - itemBuilder: (context, index) { - return Row( - children: [ - Padding( - padding: const EdgeInsets.all(8.0), - child: Text('Item $index'), - ), - ], - ); - }, - ); - } + Widget buildSuggestions(BuildContext context) => throw UnimplementedError(); @override Widget buildScaffold(Widget? body, BuildContext context) { - const BorderSide _kDefaultRoundedBorderSide = BorderSide( - style: BorderStyle.solid, - width: 0.8, - ); - return fluent.Scaffold( - left: NavigationPanel( - currentIndex: 2, - menu: NavigationPanelMenuItem( - icon: IconButton( - icon: fluent.Icon(Icons.menu), - onPressed: () {}, - ), - ), - items: [ - NavigationPanelSectionHeader( - header: fluent.AutoSuggestBox( - onSelected: (PlatformItem item) => print(item.name), - controller: queryTextController, - sorter: (String text, List items) => search.call(text), - items: platforms, - noResultsFound: (context) => ListTile( - title: DefaultTextStyle( - style: TextStyle( - fontWeight: FontWeight.normal, color: Colors.black), - child: Text('No results found'), - ), - ), - itemBuilder: (context, item) { - return PlatformItemWidget( - item, - small: true, - ); - }, - textBoxBuilder: (context, controller, fn, key) => TextBox( - key: key, - controller: controller, - focusNode: fn, - suffixMode: OverlayVisibilityMode.always, - suffix: fluent.Row( - children: [ - controller.text.isNotEmpty - ? IconButton( - icon: fluent.Icon(Icons.close), - onPressed: () { - controller.clear(); - fn.unfocus(); - }, - ) - : fluent.SizedBox.shrink(), - IconButton( - icon: fluent.Icon(Icons.search), - onPressed: () {}, - ), - ], - ), - placeholder: searchFieldLabel, - decoration: BoxDecoration( - color: Colors.white, - border: Border( - top: _kDefaultRoundedBorderSide, - bottom: _kDefaultRoundedBorderSide, - left: _kDefaultRoundedBorderSide, - right: _kDefaultRoundedBorderSide, - ), - borderRadius: fn.hasFocus - ? BorderRadius.vertical(top: Radius.circular(3.0)) - : BorderRadius.all(Radius.circular(3.0)), - ), + return fluent.ScaffoldPage( + content: Padding( + padding: EdgeInsets.symmetric(horizontal: 16, vertical: 32), + child: Column( + children: [ + fluent.AutoSuggestBox( + key: _autoSuggestBoxKey, + placeholder: 'Search', + onSelected: (item) => print(item), + controller: queryTextController, + items: _kPlatformNames, ), - )), - ], + Spacer(), + ], + ), ), - body: Container(), ); } } diff --git a/pubspec.lock b/pubspec.lock index 081e224..2741754 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.8.2" boolean_selector: dependency: transitive description: @@ -21,14 +21,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -63,7 +63,7 @@ packages: name: fluent_ui url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "3.6.0" flutter: dependency: "direct main" description: flutter @@ -87,14 +87,14 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10" + version: "0.12.11" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" path: dependency: transitive description: @@ -102,6 +102,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0" + recase: + dependency: transitive + description: + name: recase + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.0" + scroll_pos: + dependency: transitive + description: + name: scroll_pos + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.0" sky_engine: dependency: transitive description: flutter @@ -113,7 +127,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -148,7 +162,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.4.3" typed_data: dependency: transitive description: @@ -162,7 +176,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" sdks: - dart: ">=2.12.0 <3.0.0" - flutter: ">=1.17.0" + dart: ">=2.15.0 <3.0.0" + flutter: ">=2.8.0" diff --git a/pubspec.yaml b/pubspec.yaml index 3efa30b..d73bcb2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -18,10 +18,11 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.14.4 <3.0.0" + flutter: ">=2.8.0" dependencies: - fluent_ui: ^1.8.1 + fluent_ui: ^3.6.0 flutter: sdk: flutter