Advertisement
danielbrito1987

home-page

Mar 30th, 2020
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.89 KB | None | 0 0
  1. import 'dart:io';
  2.  
  3. import 'package:PhotoReport/blocs/obra_bloc.dart';
  4. import 'package:PhotoReport/widgets/CustomShowDialog.dart';
  5. import 'package:PhotoReport/widgets/Drawer.dart';
  6. import 'package:flutter/material.dart';
  7.  
  8. import 'buildings_page.dart';
  9. import 'configuracoes_page.dart';
  10. import 'politicas_privacidade.dart';
  11. import 'termos_uso.dart';
  12.  
  13. class HomePage extends StatefulWidget {
  14.   final String origem;
  15.  
  16.   HomePage(this.origem);
  17.  
  18.   @override
  19.   _HomePageState createState() => _HomePageState();
  20. }
  21.  
  22. class _HomePageState extends State<HomePage> {
  23.   PageController _pageCtrl = PageController();
  24.   ObrasBloc _bloc = ObrasBloc();
  25.   String title = "Obras";
  26.   final _scaffoldKey = GlobalKey<ScaffoldState>();
  27.  
  28.   @override
  29.   void initState() {
  30.     super.initState();
  31.   }
  32.  
  33.   void onChangedIndex(int index) {
  34.     switch (index) {
  35.       case 0:
  36.         setState(() {
  37.           title = "Obras";
  38.         });
  39.         break;
  40.       case 1:
  41.         setState(() {
  42.           title = "Configurações";
  43.         });
  44.         break;
  45.       case 2:
  46.         setState(() {
  47.           title = "Políticas de Privacidade";
  48.         });
  49.         break;
  50.       case 3:
  51.         setState(() {
  52.           title = "Termos de Uso";
  53.         });
  54.         break;
  55.       default:
  56.     }
  57.   }
  58.  
  59.   @override
  60.   Widget build(BuildContext context) {
  61.     return WillPopScope(
  62.         child: PageView(
  63.           controller: _pageCtrl,
  64.           onPageChanged: onChangedIndex,
  65.           physics: NeverScrollableScrollPhysics(),
  66.           children: <Widget>[
  67.             Scaffold(
  68.               appBar: AppBar(
  69.                 title: Text(title),
  70.               ),
  71.               drawer: DrawerPage(
  72.                 pageCtrl: _pageCtrl,
  73.               ),
  74.               body: BuildingsPage(
  75.                 _pageCtrl,
  76.                 widget.origem,
  77.                 lista: _bloc.listaObras,
  78.               ),
  79.             ),
  80.             Scaffold(
  81.                 appBar: AppBar(
  82.                   title: Text(title),
  83.                 ),
  84.                 drawer: DrawerPage(
  85.                   pageCtrl: _pageCtrl,
  86.                 ),
  87.                 body: ConfiguracoesPage(_pageCtrl)),
  88.             Scaffold(
  89.                 appBar: AppBar(
  90.                   title: Text(title),
  91.                 ),
  92.                 drawer: DrawerPage(
  93.                   pageCtrl: _pageCtrl,
  94.                 ),
  95.                 body: PolicitasPrivacidadePage(_pageCtrl)),
  96.             Scaffold(
  97.                 appBar: AppBar(
  98.                   title: Text(title),
  99.                 ),
  100.                 drawer: DrawerPage(
  101.                   pageCtrl: _pageCtrl,
  102.                 ),
  103.                 body: TermosUsoPage(_pageCtrl))
  104.           ],
  105.         ),
  106.         onWillPop: () {
  107.           if (_pageCtrl.page != 0)
  108.             _pageCtrl.jumpToPage(0);
  109.           else {
  110.             showDialog(
  111.                 context: context,
  112.                 barrierDismissible: false,
  113.                 builder: (BuildContext context) {
  114.                   return WillPopScope(
  115.                     onWillPop: () => Future(() => false),
  116.                     child: CustomAlertDialog(
  117.                       title: Text("Atenção!"),
  118.                       content:
  119.                           Text("Tem certeza que deseja fechar o aplicativo?"),
  120.                       actions: <Widget>[
  121.                         FlatButton(
  122.                           child: Text("Sim"),
  123.                           onPressed: () {
  124.                             exit(0);
  125.                           },
  126.                         ),
  127.                         FlatButton(
  128.                           child: Text("Não"),
  129.                           onPressed: () {
  130.                             Navigator.of(context).pop();
  131.                           },
  132.                         ),
  133.                       ],
  134.                     ),
  135.                   );
  136.                 });
  137.           }
  138.         });
  139.   }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement