Skip to content

Commit

Permalink
Fix tabs not switching
Browse files Browse the repository at this point in the history
  • Loading branch information
Pante committed Sep 24, 2024
1 parent 9c71f1e commit df33117
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 2 deletions.
8 changes: 8 additions & 0 deletions forui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.5.1

###

* Fix `FTabs` not showing correct tab entry when switching tabs.
[Issue #203](https://github.com/forus-labs/forui/issues/203).


## 0.5.0

The minimum Flutter version has been increased from `3.19.0` to `3.24.0`.
Expand Down
5 changes: 4 additions & 1 deletion forui/lib/src/widgets/tabs/tabs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ class _FTabsState extends State<FTabs> with SingleTickerProviderStateMixin {
dividerColor: Colors.transparent,
labelStyle: style.selectedLabel,
unselectedLabelStyle: style.unselectedLabel,
onTap: (index) => widget.onPress?.call(index),
onTap: (index) {
setState(() {});
widget.onPress?.call(index);
},
),
),
SizedBox(height: style.spacing),
Expand Down
2 changes: 1 addition & 1 deletion forui/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: forui
description: Forui is a UI library for Flutter that provides a set of minimalistic widgets heavily inspired by Shadcn/ui.
version: 0.5.0
version: 0.5.1
homepage: https://forui.dev/
documentation: https://forui.dev/docs
repository: https://github.com/forus-labs/forui/tree/main/forui
Expand Down
74 changes: 74 additions & 0 deletions forui/test/src/widgets/tabs/tabs_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,79 @@ void main() {

expect(tester.takeException(), null);
});

testWidgets('tap on current entry', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: TestScaffold(
data: FThemes.zinc.light,
child: FTabs(
tabs: const [
FTabEntry(label: Text('foo'), content: Text('foo content')),
FTabEntry(label: Text('bar'), content: Text('bar content')),
],
),
),
),
);

expect(find.text('foo content'), findsOneWidget);
expect(find.text('bar content'), findsNothing);

await tester.tap(find.text('foo'));
await tester.pumpAndSettle();

expect(find.text('foo content'), findsOneWidget);
expect(find.text('bar content'), findsNothing);
});

testWidgets('using internal controller and tapping on tab switches tab entry', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: TestScaffold(
data: FThemes.zinc.light,
child: FTabs(
tabs: const [
FTabEntry(label: Text('foo'), content: Text('foo content')),
FTabEntry(label: Text('bar'), content: Text('bar content')),
],
),
),
),
);

expect(find.text('bar content'), findsNothing);

await tester.tap(find.text('bar'));
await tester.pumpAndSettle();

expect(find.text('bar content'), findsOneWidget);
});

testWidgets('using external controller and tapping on tab switches tab entry', (tester) async {
final controller = FTabController(length: 2, vsync: tester);

await tester.pumpWidget(
MaterialApp(
home: TestScaffold(
data: FThemes.zinc.light,
child: FTabs(
controller: controller,
tabs: const [
FTabEntry(label: Text('foo'), content: Text('foo content')),
FTabEntry(label: Text('bar'), content: Text('bar content')),
],
),
),
),
);

expect(find.text('bar content'), findsNothing);

await tester.tap(find.text('bar'));
await tester.pumpAndSettle();

expect(find.text('bar content'), findsOneWidget);
});
});
}

0 comments on commit df33117

Please sign in to comment.