Open berkeresvan opened 5 months ago
import 'package:flutter/material.dart';
void main() { runApp(MyApp()); }
class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: MyTabbedPage(), ); } }
class MyTabbedPage extends StatefulWidget { @override _MyTabbedPageState createState() => _MyTabbedPageState(); }
class _MyTabbedPageState extends State with SingleTickerProviderStateMixin { late TabController _tabController;
@override void initState() { super.initState(); _tabController = TabController(length: 3, vsync: this); }
@override void dispose() { _tabController.dispose(); super.dispose(); }
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('TabBar and TabBarView Example'), ), body: Column( children: [ TabBar( controller: _tabController, tabs: [ Tab(text: 'Tab 1'), Tab(text: 'Tab 2'), Tab(text: 'Tab 3'), ], ), Expanded( child: TabBarView( controller: _tabController, children: [ _buildTabContent('Content of Tab 1'), _buildTabContent('Content of Tab 2'), _buildTabContent('Content of Tab 3'), ], ), ), ], ), ); }
Widget _buildTabContent(String content) { return Center( child: Text( content, style: TextStyle(fontSize: 20.0), ), ); } }
import 'package:flutter/material.dart';
void main() { runApp(MyApp()); }
class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: MyTabbedPage(), ); } }
class MyTabbedPage extends StatefulWidget { @override _MyTabbedPageState createState() => _MyTabbedPageState(); }
class _MyTabbedPageState extends State
with SingleTickerProviderStateMixin {
late TabController _tabController;
@override void initState() { super.initState(); _tabController = TabController(length: 3, vsync: this); }
@override void dispose() { _tabController.dispose(); super.dispose(); }
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('TabBar and TabBarView Example'), ), body: Column( children: [ TabBar( controller: _tabController, tabs: [ Tab(text: 'Tab 1'), Tab(text: 'Tab 2'), Tab(text: 'Tab 3'), ], ), Expanded( child: TabBarView( controller: _tabController, children: [ _buildTabContent('Content of Tab 1'), _buildTabContent('Content of Tab 2'), _buildTabContent('Content of Tab 3'), ], ), ), ], ), ); }
Widget _buildTabContent(String content) { return Center( child: Text( content, style: TextStyle(fontSize: 20.0), ), ); } }