Advertisement
Guest User

Untitled

a guest
Sep 6th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.94 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() => runApp(MyApp());
  4.  
  5. class MyApp extends StatelessWidget {
  6.   @override
  7.   Widget build(BuildContext context) {
  8.     return MaterialApp(
  9.       title: 'Flutter Demo',
  10.       theme: ThemeData(
  11.         primarySwatch: Colors.blue,
  12.       ),
  13.       home: TabsDemo(),
  14.     );
  15.   }
  16. }
  17.  
  18. class TabsDemo extends StatefulWidget {
  19.   @override
  20.   _TabsDemoState createState() => _TabsDemoState();
  21. }
  22.  
  23. class _TabsDemoState extends State<TabsDemo>
  24.     with SingleTickerProviderStateMixin {
  25.   TabController _tabController;
  26.  
  27.   @override
  28.   void initState() {
  29.     super.initState();
  30.     _tabController = TabController(length: 3, vsync: this, initialIndex: 0);
  31.     _tabController.addListener(_handleTabIndex);
  32.   }
  33.  
  34.   @override
  35.   void dispose() {
  36.     _tabController.removeListener(_handleTabIndex);
  37.     _tabController.dispose();
  38.     super.dispose();
  39.   }
  40.  
  41.   void _handleTabIndex() {
  42.     setState(() {});
  43.   }
  44.  
  45.   @override
  46.   Widget build(BuildContext context) {
  47.     return SafeArea(
  48.       top: false,
  49.       child: Scaffold(
  50.         appBar: AppBar(
  51.           title: Center(
  52.             child: Container(
  53.               child: Text('DEMO'),
  54.             ),
  55.           ),
  56.         ), //   floatingActionButton: _buildFloatingActionButton(context),
  57.         body: TabBarView(controller: _tabController, children: [
  58.           Center(
  59.             child: Container(
  60.               child: Text('Tab 1'),
  61.             ),
  62.           ),
  63.           Center(
  64.             child: Container(
  65.               child: Text('Tab 2'),
  66.             ),
  67.           ),
  68.           Center(
  69.             child: Container(
  70.               child: Text('Tab 3'),
  71.             ),
  72.           ),
  73.         ]),
  74.         bottomNavigationBar: TabBar(
  75.           controller: _tabController,
  76.           tabs: [
  77.             Tab(
  78.               text: "Tab1",
  79.             ),
  80.             Tab(
  81.               text: "Tab2",
  82.             ),
  83.             Tab(
  84.               text: "Tab3",
  85.             ),
  86.           ],
  87.           labelColor: Colors.black,
  88.           unselectedLabelColor: Colors.blue,
  89.           indicatorSize: TabBarIndicatorSize.label,
  90.           indicatorPadding: EdgeInsets.all(5.0),
  91.           indicatorColor: Colors.red,
  92.         ),
  93.         floatingActionButton: _floatingButtons(),
  94.       ),
  95.     );
  96.   }
  97.  
  98.   Widget _floatingButtons() {
  99.     if (_tabController.index == 0) {
  100.       return FloatingActionButton(
  101.           shape: StadiumBorder(),
  102.           onPressed: (){},
  103.           backgroundColor: Colors.redAccent,
  104.           child: Icon(
  105.             Icons.message,
  106.             size: 20.0,
  107.           ));
  108.     } else if (_tabController.index == 1) {
  109.       return null; //absence de FAB pour ce tab
  110.     } else {
  111.       return FloatingActionButton(
  112.         shape: StadiumBorder(),
  113.         onPressed: (){}
  114.         backgroundColor: Colors.redAccent,
  115.         child: Icon(
  116.           Icons.edit,
  117.           size: 20.0,
  118.         ),
  119.       );
  120.     }
  121.   }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement