forked from firka/flutter
adds interactive example (#59251)
This commit is contained in:
@@ -85,6 +85,59 @@ import 'constants.dart';
|
||||
/// }
|
||||
/// ```
|
||||
/// {@end-tool}
|
||||
///
|
||||
/// {@tool dartpad --template=stateless_widget_material}
|
||||
///
|
||||
/// This example shows how to listen to page updates in [TabBar] and [TabBarView]
|
||||
/// when using [DefaultTabController].
|
||||
///
|
||||
/// ```dart preamble
|
||||
/// final List<Tab> tabs = <Tab>[
|
||||
/// Tab(text: 'Zeroth'),
|
||||
/// Tab(text: 'First'),
|
||||
/// Tab(text: 'Second'),
|
||||
/// ];
|
||||
/// ```
|
||||
///
|
||||
/// ```dart
|
||||
/// Widget build(BuildContext context) {
|
||||
/// return DefaultTabController(
|
||||
/// length: tabs.length,
|
||||
/// // The Builder widget is used to have a different BuildContext to access
|
||||
/// // closest DefaultTabController.
|
||||
/// child: Builder(
|
||||
/// builder: (BuildContext context) {
|
||||
/// final TabController tabController = DefaultTabController.of(context);
|
||||
/// tabController.addListener(() {
|
||||
/// if (!tabController.indexIsChanging) {
|
||||
/// // Your code goes here.
|
||||
/// // To get index of current tab use tabController.index
|
||||
/// }
|
||||
/// });
|
||||
/// return Scaffold(
|
||||
/// appBar: AppBar(
|
||||
/// bottom: TabBar(
|
||||
/// tabs: tabs,
|
||||
/// ),
|
||||
/// ),
|
||||
/// body: TabBarView(
|
||||
/// children: tabs.map((Tab tab){
|
||||
/// return Center(
|
||||
/// child: Text(
|
||||
/// tab.text + ' Tab',
|
||||
/// style: Theme.of(context).textTheme.headline5,
|
||||
/// ),
|
||||
/// );
|
||||
/// }).toList(),
|
||||
/// ),
|
||||
/// );
|
||||
/// }
|
||||
/// ),
|
||||
/// );
|
||||
/// }
|
||||
/// ```
|
||||
/// {@end-tool}
|
||||
///
|
||||
class TabController extends ChangeNotifier {
|
||||
/// Creates an object that manages the state required by [TabBar] and a
|
||||
/// [TabBarView].
|
||||
|
||||
Reference in New Issue
Block a user