Skip to content

Instantly share code, notes, and snippets.

@drkdelaney
Created February 13, 2025 22:56
Show Gist options
  • Save drkdelaney/b1b50c8c22d248f84bfa4bf012b036b4 to your computer and use it in GitHub Desktop.
Save drkdelaney/b1b50c8c22d248f84bfa4bf012b036b4 to your computer and use it in GitHub Desktop.
An example of using a tab controller to switch tabs.
import 'package:flutter/material.dart';
import 'package:forui/forui.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
builder:
(context, child) => FTheme(data: FThemes.green.light, child: child!),
home: const FTabExamplePage(),
);
}
}
class FTabExamplePage extends StatefulWidget {
const FTabExamplePage({super.key});
@override
State<FTabExamplePage> createState() => _FTabExamplePageState();
}
class _FTabExamplePageState extends State<FTabExamplePage>
with SingleTickerProviderStateMixin {
late final FTabController _tabController = FTabController(
length: 3,
vsync: this,
);
@override
Widget build(BuildContext context) {
return FScaffold(
header: FHeader.nested(
title: Text('FTabs Example'),
prefixActions: [FHeaderAction.back(onPress: () {})],
),
content: FTabs(
controller: _tabController,
tabs: [
FTabEntry(
label: Text('One'),
content: Column(
children: [
FCard(title: Text('One'), subtitle: Text('Content for one.')),
SizedBox(height: 16),
SizedBox(
width: 300,
child: FButton(
suffix: FIcon(FAssets.icons.chevronRight),
label: Text('Move to Two'),
onPress: () {
_tabController.animateTo(1);
},
),
),
],
),
),
FTabEntry(
label: Text('Two'),
content: Column(
children: [
FCard(title: Text('Two'), subtitle: Text('Content for two.')),
SizedBox(height: 16),
SizedBox(
width: 300,
child: FButton(
suffix: FIcon(FAssets.icons.chevronRight),
label: Text('Move to Three'),
onPress: () {
_tabController.animateTo(2);
},
),
),
],
),
),
FTabEntry(
label: Text('Three'),
content: Column(
children: [
FCard(
title: Text('Three'),
subtitle: Text('Content for Three.'),
),
SizedBox(height: 16),
SizedBox(
width: 300,
child: FButton(
suffix: FIcon(FAssets.icons.chevronLeft),
label: Text('Move to One'),
onPress: () {
_tabController.animateTo(0);
},
),
),
],
),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment