Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes #618

Merged
merged 5 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
- Ensure the body state in `NavigationView` is properly preserved ([#607](https://github.com/bdlukaa/fluent_ui/pull/607))
- **BREAKING** Renamed `ExpanderState.open` to `ExpanderState.isExpanded`
- The same identifier is no longer used for every `Expander` ([#596](https://github.com/bdlukaa/fluent_ui/issues/596))
- Ensure the TabView scroll controller has clients before using it ([#615](https://github.com/bdlukaa/fluent_ui/issues/615))
- TabView now waits a time to resize after closed ([#617](https://github.com/bdlukaa/fluent_ui/issues/617))
- `ToggleButton` border width is uniform ([#610](https://github.com/bdlukaa/fluent_ui/issues/610))

## 4.0.3+1

Expand Down
73 changes: 26 additions & 47 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,10 @@ class _MyHomePageState extends State<MyHomePage> with WindowListener {

final viewKey = GlobalKey();

final key = GlobalKey();
final searchKey = GlobalKey();
final searchFocusNode = FocusNode();
final searchController = TextEditingController();
void resetSearch() => searchController.clear();
String get searchValue => searchController.text;

final List<NavigationPaneItem> originalItems = [
PaneItem(
icon: const Icon(FluentIcons.home),
Expand Down Expand Up @@ -369,28 +368,10 @@ class _MyHomePageState extends State<MyHomePage> with WindowListener {
),
// TODO: mobile widgets, Scrollbar, BottomNavigationBar, RatingBar
];
late List<NavigationPaneItem> items = originalItems;

@override
void initState() {
windowManager.addListener(this);
searchController.addListener(() {
setState(() {
if (searchValue.isEmpty) {
items = originalItems;
} else {
items = [...originalItems, ...footerItems]
.whereType<PaneItem>()
.where((item) {
assert(item.title is Text);
final text = (item.title as Text).data!;
return text.toLowerCase().contains(searchValue.toLowerCase());
})
.toList()
.cast<NavigationPaneItem>();
}
});
});
super.initState();
}

Expand Down Expand Up @@ -443,28 +424,8 @@ class _MyHomePageState extends State<MyHomePage> with WindowListener {
]),
),
pane: NavigationPane(
selected: () {
// if not searching, return the current index
if (searchValue.isEmpty) return index;

final indexOnScreen = items.indexOf(
[...originalItems, ...footerItems]
.whereType<PaneItem>()
.elementAt(index),
);
if (indexOnScreen.isNegative) return null;
return indexOnScreen;
}(),
selected: index,
onChanged: (i) {
// If searching, the values will have different indexes
if (searchValue.isNotEmpty) {
final equivalentIndex = [...originalItems, ...footerItems]
.whereType<PaneItem>()
.toList()
.indexOf(items[i] as PaneItem);
i = equivalentIndex;
}
resetSearch();
setState(() => index = i);
},
header: SizedBox(
Expand Down Expand Up @@ -500,15 +461,33 @@ class _MyHomePageState extends State<MyHomePage> with WindowListener {
return const StickyNavigationIndicator();
}
}(),
items: items,
autoSuggestBox: TextBox(
key: key,
items: originalItems,
autoSuggestBox: AutoSuggestBox(
key: searchKey,
focusNode: searchFocusNode,
controller: searchController,
items: originalItems.whereType<PaneItem>().map((item) {
assert(item.title is Text);
final text = (item.title as Text).data!;

return AutoSuggestBoxItem(
label: text,
value: text,
onSelected: () async {
final itemIndex = NavigationPane(
items: originalItems,
).effectiveIndexOf(item);

setState(() => index = itemIndex);
await Future.delayed(const Duration(milliseconds: 17));
searchController.clear();
},
);
}).toList(),
placeholder: 'Search',
focusNode: searchFocusNode,
),
autoSuggestBoxReplacement: const Icon(FluentIcons.search),
footerItems: searchValue.isNotEmpty ? [] : footerItems,
footerItems: footerItems,
),
onOpenSearch: () {
searchFocusNode.requestFocus();
Expand Down
2 changes: 1 addition & 1 deletion lib/src/controls/inputs/toggle_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class ToggleButtonThemeData with Diagnosticable {
shape: ButtonState.all(RoundedRectangleBorder(
side: const BorderSide(
color: Colors.transparent,
width: 1,
width: 0.33,
),
borderRadius: BorderRadius.circular(4.0),
)),
Expand Down
Loading