SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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(home: ScrollableTabsDemo());
  9.   }
  10. }
  11.  
  12. class _Page {
  13.   const _Page({this.icon, this.text});
  14.   final IconData icon;
  15.   final String text;
  16. }
  17.  
  18. const List<_Page> _allPages = <_Page>[
  19.   _Page(text: 'tab 1'),
  20.   _Page(text: 'tab 2'),
  21.   _Page(text: 'tab 3'),
  22. ];
  23.  
  24. class ScrollableTabsDemo extends StatefulWidget {
  25.   static const String routeName = '/material/scrollable-tabs';
  26.  
  27.   @override
  28.   ScrollableTabsDemoState createState() => ScrollableTabsDemoState();
  29. }
  30.  
  31. class ScrollableTabsDemoState extends State<ScrollableTabsDemo>
  32.     with SingleTickerProviderStateMixin {
  33.   TabController _controller;
  34.  
  35.   @override
  36.   void initState() {
  37.     super.initState();
  38.     _controller = TabController(vsync: this, length: _allPages.length);
  39.   }
  40.  
  41.   @override
  42.   void dispose() {
  43.     _controller.dispose();
  44.     super.dispose();
  45.   }
  46.  
  47.   @override
  48.   Widget build(BuildContext context) {
  49.     final Color iconColor = Theme.of(context).accentColor;
  50.     return Scaffold(
  51.       appBar: AppBar(
  52.         title: const Text('Scrollable tabs'),
  53.         bottom: TabBar(
  54.           controller: _controller,
  55.           isScrollable: true,
  56.           tabs: _allPages.map<Tab>((_Page page) {
  57.             return Tab(text: page.text);
  58.           }).toList(),
  59.         ),
  60.       ),
  61.       body: TabBarView(
  62.         controller: _controller,
  63.         children: _allPages.map<Widget>((_Page page) {
  64.           return SafeArea(
  65.             top: false,
  66.             bottom: false,
  67.             child: LayoutBuilder(builder: (context, constraints) {
  68.               return FutureBuilder<int>(
  69.                   future: getPageCount(),
  70.                   builder: (BuildContext context, AsyncSnapshot<int> snapshot) {
  71.                     switch (snapshot.connectionState) {
  72.                       case ConnectionState.none:
  73.                         print("none ${snapshot.data}");
  74.                         return Text('none');
  75.                       case ConnectionState.active:
  76.                         print("active ${snapshot.data}");
  77.                         return Text('active');
  78.                       case ConnectionState.waiting:
  79.                         print("waiting ${snapshot.data}");
  80.                         return Center(child: CircularProgressIndicator());
  81.                       case ConnectionState.done:
  82.                         print("done ${snapshot.data}");
  83.                         return buildPageView(snapshot.data);
  84.                     }
  85.                   });
  86.             }),
  87.           );
  88.         }).toList(),
  89.       ),
  90.     );
  91.   }
  92.  
  93.   Future<int> getPageCount() => Future.delayed(Duration(seconds: 3), () => 5);
  94.  
  95.   Widget buildPageView(int pageCount) {
  96.     return PageView.builder(
  97.       itemBuilder: (context, position) {
  98.         return Container(child: Center(child: Text(position.toString())));
  99.       },
  100.       itemCount: pageCount,
  101.     );
  102.   }
  103. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top