Skip to content

Commit

Permalink
fix: upgrade fluent_ui usage to 3.6.0 because on Flutter >= 2.8 old f…
Browse files Browse the repository at this point in the history
…luent_ui 1.8.1 didn't work anymore
  • Loading branch information
Maxeem committed Jan 20, 2022
1 parent 1d6a8e5 commit 8821665
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 115 deletions.
124 changes: 22 additions & 102 deletions lib/windows_search_delegate.dart
Original file line number Diff line number Diff line change
@@ -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<PlatformItem> 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<PlatformItem>(
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<String>(
key: _autoSuggestBoxKey,
placeholder: 'Search',
onSelected: (item) => print(item),
controller: queryTextController,
items: _kPlatformNames,
),
)),
],
Spacer(),
],
),
),
body: Container(),
);
}
}
36 changes: 25 additions & 11 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -87,21 +87,35 @@ 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:
name: path
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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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"
5 changes: 3 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8821665

Please sign in to comment.