Advertisement
Guest User

drawer.dart

a guest
Nov 1st, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 4.00 KB | None | 0 0
  1. import 'package:coocafe_tecnico_app/pages/home_page.dart';
  2. import 'package:coocafe_tecnico_app/pages/lista-produtor-page.dart';
  3. import 'package:coocafe_tecnico_app/pages/login_page.dart';
  4. import 'package:coocafe_tecnico_app/pages/notificacoes-page.dart';
  5. import 'package:coocafe_tecnico_app/services/sync.service.dart';
  6. import 'package:coocafe_tecnico_app/widgets/drawer_tile.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:shared_preferences/shared_preferences.dart';
  9. import 'package:date_format/date_format.dart';
  10.  
  11. class DrawerPage extends StatelessWidget {
  12.   final PageController pageCtrl;
  13.   SyncService sync = SyncService();
  14.  
  15.   DrawerPage({this.pageCtrl});
  16.  
  17.   @override
  18.   Widget build(BuildContext context) {
  19.     return Drawer(
  20.         child: new ListView(
  21.           children: <Widget> [
  22.             Container(
  23.               height: 80.0,
  24.               child: DrawerHeader(
  25.                 child: new Text('Menu', style: TextStyle(fontSize: 20.0, color: Colors.white, fontWeight: FontWeight.bold),),
  26.                 decoration: BoxDecoration(color: Colors.blueGrey),
  27.               ),
  28.             ),
  29.  
  30.             DrawerTile(Icons.home, "Início", pageCtrl, 0),
  31.             DrawerTile(Icons.people, "Produtores", pageCtrl, 1),
  32.             DrawerTile(Icons.notifications, "Notificações", pageCtrl, 2),
  33.  
  34.             ListTile(
  35.               leading: Icon(Icons.refresh, color: Colors.white,),
  36.               title: Text("Sincronizar", style: TextStyle(color: Colors.white),),
  37.               onTap: (){
  38.                 showDialog(
  39.                   context: context,
  40.                   builder: (BuildContext context) {
  41.                     return AlertDialog(
  42.                       title: Text("Sincronizar Dados"),
  43.                       content: Text("Deseja sincronizar os dados com o servidor?"),
  44.                       actions: <Widget>[
  45.                         FlatButton(
  46.                           child: Text("Não"),
  47.                           onPressed: () {
  48.                             Navigator.of(context).pop();
  49.                             Navigator.of(context).pop();
  50.                           },
  51.                         ),
  52.                         FlatButton(
  53.                           child: Text("Sim"),
  54.                           onPressed: () async {
  55.                             Navigator.of(context).pop();
  56.                             Navigator.of(context).pop();
  57.  
  58.                             SharedPreferences prefs = await SharedPreferences.getInstance();
  59.  
  60.                             sync.getListaSafra(context);
  61.                             sync.getListaCultura(context);
  62.                             sync.getListaFilial(context);
  63.                             sync.getListaTipoTitulo(context);
  64.                             sync.getListaNotificacoesTecnico(context);
  65.                             sync.getListaProdutor(context);
  66.                             String _dataRefresh = "Atualizado em " + formatDate(
  67.                                 DateTime.now(), [dd, '/', mm, '/', yyyy]) + " às " +
  68.                                 formatDate(DateTime.now(), [HH, ':', nn, ':', ss]);
  69.  
  70.                             prefs.setString("TextoAtualizacao", _dataRefresh);
  71.                           },
  72.                         )
  73.                       ],
  74.                     );
  75.                   }
  76.                 );
  77.               },
  78.             ),
  79.  
  80.             ListTile(
  81.               leading: Icon(Icons.exit_to_app, color: Colors.white,),
  82.               title: Text("Sair", style: TextStyle(color: Colors.white),),
  83.               onTap: () async {
  84.                 SharedPreferences prefs = await SharedPreferences.getInstance();
  85.                 await prefs.setString('user', '');
  86.                 await prefs.setString('pass', '');
  87.                 await prefs.setString('key', '');
  88.                 await prefs.setString('TextoAtualizacao', '');
  89.  
  90.                 Navigator.pushReplacementNamed(context, LoginPage.tag);
  91.               },
  92.             ),
  93.           ],
  94.         )
  95.     );
  96.   }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement