WaleedSyr

timeline.dart

Jun 8th, 2020
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 9.09 KB | None | 0 0
  1. class Timeline extends StatefulWidget {
  2.   PageController pageController;
  3.   Timeline({Key key, this.pageController}) : super(key: key);
  4.  
  5.   @override
  6.   _HomeState createState() => _HomeState();
  7. }
  8.  
  9. class _HomeState extends State<Timeline>
  10.     with AutomaticKeepAliveClientMixin<Timeline> {
  11.   // final AsyncMemoizer _memoizer = AsyncMemoizer();
  12.   bool get wantKeepAlive => true; //flutter lib method
  13.   bool isAuthorized = false;
  14.   final LocalStorageService storageService = locator<LocalStorageService>();
  15.   final logger = locator<CustomLoggerService>();
  16.  
  17.   final BrandRepository _brandRepository = BrandRepository();
  18.   // final CategoryRepository _categoryRepository = CategoryRepository();
  19.  
  20.   @override
  21.   void initState() {
  22.     super.initState();
  23.   }
  24.  
  25.  
  26.   bool themeSwitch = false;
  27.   dynamic themeColors() {
  28.     if (themeSwitch) return Colors.black;
  29.     return Colors.greenAccent;
  30.   }
  31.  
  32.   @override
  33.   Widget build(BuildContext context) {
  34.    
  35.     super.build(context);
  36.  
  37.     return DefaultTabController(
  38.       length: 4,
  39.       child: Scaffold(
  40.         backgroundColor: Colors.white,
  41.         appBar: _builAppBarWithTabs(),
  42.         body: Center(
  43.           child: ConstrainedBox(
  44.             constraints: BoxConstraints(maxWidth: 1200),
  45.             child: ListView(
  46.               scrollDirection: Axis.vertical,
  47.               children: <Widget>[
  48.                 Padding(
  49.                   padding: const EdgeInsets.only(bottom: 150),
  50.                   child: Container(
  51.                     height: 800,
  52.                     child: CustomScrollView(
  53.                       scrollDirection: Axis.vertical,
  54.                       slivers: <Widget>[
  55.                         SliverToBoxAdapter(
  56.                           child: MasonryGrid(
  57.                             column: getResponsiveColumnNumber(context, 1, 2, 6),
  58.                             children: <Widget>[
  59.                               // First Bloc
  60.                               BlocProvider(
  61.                                 create: (context) {
  62.                                   BrandBloc(repository: _brandRepository);
  63.                                 },
  64.                                 child: Container(
  65.                                   width: 200,
  66.                                   alignment: Alignment.center,
  67.                                   height: 80,
  68.                                   child: BrandScreen(
  69.                                     brandBloc: context.bloc(),
  70.                                   ),
  71.                                 ),
  72.                               ),
  73.                               CategoryScreen(
  74.                                 // Second Bloc
  75.                                 categoryBloc: CategoryBloc(
  76.                                   repository: context.repository(),
  77.                                 ),
  78.                               ),
  79.                               Container(
  80.                                 width: 200,
  81.                                 alignment: Alignment.center,
  82.                                 height: 330,
  83.                                 child: _buildFeaturedItemsList(),
  84.                               ),
  85.                               Placeholder(
  86.                                 strokeWidth: 0,
  87.                                 color: Colors.white,
  88.                               )
  89.                             ],
  90.                           ),
  91.                         ),
  92.                       ],
  93.                     ),
  94.                   ),
  95.                 ),
  96.  
  97.                
  98.               ],
  99.             ),
  100.           ),
  101.         ),
  102.       ),
  103.     );
  104.   }
  105.  
  106.   Widget _buildFeaturedItemsList() {
  107.     return ListView.separated(
  108.       primary: true,
  109.       addAutomaticKeepAlives: true,
  110.       // addSemanticIndexes: true,
  111.       // addRepaintBoundaries: true,
  112.       shrinkWrap: true,
  113.       padding: EdgeInsets.only(left: 15, right: 15, bottom: 0),
  114.       scrollDirection: Axis.horizontal,
  115.       itemCount: 10,
  116.       itemBuilder: (context, index) {
  117.         return ProductsListItem(
  118.           name: "3 David Klin",
  119.           currentPrice: 249,
  120.           originalPrice: 499,
  121.           discount: 50,
  122.           imageUrl:
  123.               "https://images-na.ssl-images-amazon.com/images/I/71O0zS0DT0L._UX342_.jpg",
  124.           productRate: 3,
  125.         );
  126.       },
  127.       separatorBuilder: (context, index) => const SizedBox(width: 2),
  128.     );
  129.   }
  130.  
  131.   AppBar _builAppBarWithTabs() {
  132.     return AppBar(
  133.       actionsIconTheme: IconThemeData(
  134.         color: Colors.black,
  135.       ),
  136.       elevation: 0,
  137.       backgroundColor: Colors.white,
  138.       actions: <Widget>[
  139.         Badge(
  140.           showBadge: false,
  141.           position: BadgePosition.topRight(),
  142.           badgeContent: Text('3'),
  143.           child: IconButton(
  144.             icon: FaIcon(FontAwesomeIcons.bell),
  145.             onPressed: () {
  146.               Navigator.of(context).push(
  147.                 PageRouteBuilder(
  148.                   opaque: false, // set to false
  149.                   pageBuilder: (_, __, ___) {
  150.                     return Scaffold(
  151.                       backgroundColor: Color.fromRGBO(255, 255, 255, 0.9),
  152.                       body: Container(
  153.                         decoration: BoxDecoration(
  154.                           border: Border.all(
  155.                               width: 40,
  156.                               color: Colors
  157.                                   .transparent), //color is transparent so that it does not blend with the actual color specified
  158.                           borderRadius: const BorderRadius.all(
  159.                               const Radius.circular(30.0)),
  160.                           // color: Color.fromRGBO(255, 0, 0,
  161.                           //     0.5) // Specifies the background color and the opacity
  162.                         ),
  163.                         child: CustomListView(
  164.                           separatorBuilder: (context, index) => Divider(
  165.                             thickness: 3,
  166.                             height: 10,
  167.                           ),
  168.                           loadingBuilder: CustomListLoading.defaultBuilder,
  169.                           itemBuilder: (context, index, item) {
  170.                             return ListTile(
  171.                               title: Text(item['title']),
  172.                               subtitle: Text(item['body']),
  173.                             );
  174.                           },
  175.                           adapter: NetworkListAdapter(
  176.                             url: 'https://jsonplaceholder.typicode.com/posts',
  177.                             limitParam: '_limit',
  178.                             offsetParam: '_start',
  179.                           ),
  180.                           empty: Text(
  181.                             'No Notifications !\n Buy something!',
  182.                             style: subtitleStyle,
  183.                           ),
  184.                           header: Center(
  185.                             child: Text(
  186.                               'Notifications',
  187.                               style: subtitleStyle,
  188.                             ),
  189.                           ),
  190.  
  191.                           // Item provider adapter (default: null)
  192.                           // adapter: ListAdapter (
  193.  
  194.                           //   fetchItems: (int offset, int limit) {
  195.                           //     return ListItems([
  196.                           //       ListTile(),
  197.                           //      ]);
  198.                           //   },
  199.                           // ),
  200.  
  201.                           // Callback function to build widget if exception occurs during fetching items
  202.                           errorBuilder: (BuildContext context, _,
  203.                               CustomListViewState state) {
  204.                             return Column(
  205.                               children: <Widget>[
  206.                                 Text('details.error.toString()'),
  207.                                 RaisedButton(
  208.                                   onPressed: () => state.loadMore(),
  209.                                   child: Text('Retry'),
  210.                                 ),
  211.                               ],
  212.                             );
  213.                           },
  214.                         ),
  215.                       ),
  216.                     );
  217.                   },
  218.                 ),
  219.               );
  220.             },
  221.           ),
  222.         ),
  223.         IconButton(
  224.             icon: FaIcon(FontAwesomeIcons.search),
  225.             onPressed: () {
  226.               widget.pageController.animateToPage(1,
  227.                   duration: Duration(milliseconds: 500),
  228.                   curve: Curves.easeInOut);
  229.             }),
  230.       ],
  231.       bottom: TabBar(
  232.         labelPadding: EdgeInsets.symmetric(horizontal: 20),
  233.         indicatorColor: kDarkColor,
  234.         labelColor: kDarkColor,
  235.         indicatorWeight: 2,
  236.         unselectedLabelColor: Colors.black,
  237.         isScrollable: true,
  238.         tabs: [
  239.           Tab(child: Text('Timeline.mostPopularTab'.tr())),
  240.           Tab(child: Text('Timeline.menTab'.tr())),
  241.           Tab(child: Text('Timeline.womenTab'.tr())),
  242.           Tab(child: Text('Timeline.kidsTab'.tr())),
  243.         ],
  244.       ),
  245.       title: logoImage,
  246.     );
  247.   }
  248. }
Add Comment
Please, Sign In to add comment