Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- void main() => runApp(MyApp());
- class MyApp extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'Flutter Demo',
- theme: ThemeData(
- primarySwatch: Colors.blue,
- ),
- home: TabsDemo(),
- );
- }
- }
- class TabsDemo extends StatefulWidget {
- @override
- _TabsDemoState createState() => _TabsDemoState();
- }
- class _TabsDemoState extends State<TabsDemo>
- with SingleTickerProviderStateMixin {
- TabController _tabController;
- @override
- void initState() {
- super.initState();
- _tabController = TabController(length: 3, vsync: this, initialIndex: 0);
- _tabController.addListener(_handleTabIndex);
- }
- @override
- void dispose() {
- _tabController.removeListener(_handleTabIndex);
- _tabController.dispose();
- super.dispose();
- }
- void _handleTabIndex() {
- setState(() {});
- }
- @override
- Widget build(BuildContext context) {
- return SafeArea(
- top: false,
- child: Scaffold(
- appBar: AppBar(
- title: Center(
- child: Container(
- child: Text('DEMO'),
- ),
- ),
- ), // floatingActionButton: _buildFloatingActionButton(context),
- body: TabBarView(controller: _tabController, children: [
- Center(
- child: Container(
- child: Text('Tab 1'),
- ),
- ),
- Center(
- child: Container(
- child: Text('Tab 2'),
- ),
- ),
- Center(
- child: Container(
- child: Text('Tab 3'),
- ),
- ),
- ]),
- bottomNavigationBar: TabBar(
- controller: _tabController,
- tabs: [
- Tab(
- text: "Tab1",
- ),
- Tab(
- text: "Tab2",
- ),
- Tab(
- text: "Tab3",
- ),
- ],
- labelColor: Colors.black,
- unselectedLabelColor: Colors.blue,
- indicatorSize: TabBarIndicatorSize.label,
- indicatorPadding: EdgeInsets.all(5.0),
- indicatorColor: Colors.red,
- ),
- floatingActionButton: _floatingButtons(),
- ),
- );
- }
- Widget _floatingButtons() {
- if (_tabController.index == 0) {
- return FloatingActionButton(
- shape: StadiumBorder(),
- onPressed: (){},
- backgroundColor: Colors.redAccent,
- child: Icon(
- Icons.message,
- size: 20.0,
- ));
- } else if (_tabController.index == 1) {
- return null; //absence de FAB pour ce tab
- } else {
- return FloatingActionButton(
- shape: StadiumBorder(),
- onPressed: (){}
- backgroundColor: Colors.redAccent,
- child: Icon(
- Icons.edit,
- size: 20.0,
- ),
- );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement