Advertisement
teaowl

Dashboard

Apr 5th, 2019
662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.52 KB | None | 0 0
  1.  
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_bloc/flutter_bloc.dart';
  4. import 'package:fluttertoast/fluttertoast.dart';
  5. import 'package:options_x_ray_informer/BLOCs/DashBLOC.dart';
  6. import 'package:options_x_ray_informer/BLOCs/events/UIRequests.dart';
  7. import 'package:options_x_ray_informer/BLOCs/states/ViewDataStates.dart';
  8. import 'package:options_x_ray_informer/model/network/Connection.dart';
  9. import 'package:options_x_ray_informer/view/Details.dart';
  10. import 'package:options_x_ray_informer/view/Widgets/DashboardCardWidget.dart';
  11.  
  12. class Dashboard extends StatefulWidget{
  13.  
  14.   @override
  15.   _DashboardState createState() => _DashboardState();
  16. }
  17.  
  18. class _DashboardState extends State<Dashboard> {
  19.   final DashBLOC _bloc = new DashBLOC(Connection.instance);
  20.   _DashboardState(){
  21.     _bloc.dispatch(new UpdateRequest());
  22.   }
  23.  
  24.   @override
  25.   Widget build(BuildContext context) {
  26.     double pyxelRatio = MediaQuery.of(context).devicePixelRatio;
  27.     double width = MediaQuery.of(context).size.width * pyxelRatio;
  28.  
  29.     return BlocProvider(
  30.       bloc: _bloc,
  31.         child: BlocBuilder<Request, DataState>(
  32.         bloc: _bloc,
  33.         builder: (context, state) {
  34.           if (state is EmptyDataState) {
  35.             print("Uninit");
  36.             return Center(
  37.               child: CircularProgressIndicator(),
  38.             );
  39.           }
  40.           if (state is ErrorDataState) {
  41.             print("Error");
  42.             return Center(
  43.               child: Text('Something went wrong..'),
  44.             );
  45.           }
  46.           if (state is LoadedDataState) {
  47.             print("empty: ${state.contracts.isEmpty}");
  48.             if (state.contracts.isEmpty) {
  49.               return Center(
  50.                 child: Text('Nothing here!'),
  51.               );
  52.             } else{
  53.               print("items count: ${state.contracts.length}");              
  54.               print("-------");
  55.               for(int i = 0; i < state.contracts.length; i++){
  56.                 if(state.contracts[i].isFavorite)print("fut:${state.contracts[i].name} id:${state.contracts[i].id}");
  57.               }
  58.               print("--------");  
  59.  
  60.               List<Widget> testList = new List<Widget>();
  61.               for(int i = 0; i < state.contracts.length; i++){
  62.                 if(state.contracts[i].isFavorite) testList.add(
  63.                   InkResponse(
  64.                   enableFeedback: true,
  65.                   onLongPress: (){
  66.                     showShortToast();
  67.                     DashBLOC dashBloc = BlocProvider.of<DashBLOC>(context);
  68.                     dashBloc.dispatch(new UnfavRequest(state.contracts[i].id));
  69.                   },
  70.                   onTap: onTap,
  71.                   child:DashboardCardWidget(state.contracts[i])
  72.                   )
  73.               );
  74.               }
  75.               return GridView.count(
  76.                   crossAxisCount: width >= 900 ? 2 : 1,
  77.                   padding: const EdgeInsets.all(2.0),
  78.                   children: testList
  79.               );
  80.             }
  81.           }
  82.       })
  83.     );
  84.   }
  85.  
  86.   void onTap(){
  87.     Navigator.push(context, new MaterialPageRoute(
  88.       builder: (context) =>
  89.           DetailsScreen())
  90.     );
  91.   }
  92.  
  93.   void showShortToast() {
  94.   Fluttertoast.showToast(
  95.         gravity: ToastGravity.BOTTOM,
  96.         fontSize: 14,
  97.         msg: "Fav removed",
  98.         toastLength: Toast.LENGTH_SHORT,
  99.         backgroundColor: Colors.black12,
  100.         timeInSecForIos: 1);
  101.   }
  102.  
  103.   @override
  104.   void dispose() {
  105.     _bloc.dispose();
  106.     super.dispose();
  107.   }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement