Advertisement
guilhermelirio

Agendar.page.dart

May 2nd, 2020
976
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 19.06 KB | None | 0 0
  1. import 'package:agendamento/controllers/agendar.controller.dart';
  2. import 'package:agendamento/styles/styles.dart';
  3. import 'package:agendamento/widgets/button.widget.dart';
  4. import 'package:agendamento/widgets/custom_radio_buttom.widget.dart';
  5. import 'package:flutter_mobx/flutter_mobx.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:date_picker_timeline/date_picker_timeline.dart';
  8. import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
  9. import 'package:get_it/get_it.dart';
  10. import 'package:progress_indicators/progress_indicators.dart';
  11.  
  12. class AgendarPage extends StatefulWidget {
  13.   @override
  14.   _AgendarPageState createState() => _AgendarPageState();
  15. }
  16.  
  17. class _AgendarPageState extends State<AgendarPage> {
  18.   AgendarController agendamento = GetIt.I.get<AgendarController>();
  19.  
  20.   @override
  21.   void initState() {
  22.     super.initState();
  23.   }
  24.  
  25.   DatePickerController _controller = DatePickerController();
  26.  
  27.   @override
  28.   Widget build(BuildContext context) {
  29.     agendamento.verificaHorarios(DateTime.now());
  30.     return Stack(
  31.       children: <Widget>[
  32.         Container(
  33.           padding: EdgeInsets.only(top: 5, bottom: 5),
  34.           color: Colors.white,
  35.           child: ListView(
  36.             children: <Widget>[
  37.               SizedBox(
  38.                 height: 125,
  39.               ),
  40.               Observer(
  41.                 builder: (_) {
  42.                   return Column(
  43.                     children: <Widget>[
  44.                       Card(
  45.                         elevation: 5,
  46.                         margin: EdgeInsets.only(top: 15, left: 4, right: 4),
  47.                         child: Container(
  48.                           padding: EdgeInsets.all(20),
  49.                           child: agendamento.feriado
  50.                               ? Container(
  51.                                   child: Center(
  52.                                     child: Text('Não atendemos nos feriados!',
  53.                                         style: AppTheme.erroMsg),
  54.                                   ),
  55.                                 )
  56.                               : agendamento.selectedDate.weekday == 7
  57.                                   ? Container(
  58.                                       child: Center(
  59.                                         child: Text(
  60.                                             'Não atendemos aos domingos!',
  61.                                             style: AppTheme.erroMsg),
  62.                                       ),
  63.                                     )
  64.                                   : agendamento.horarios.length == 0 &&
  65.                                           agendamento.isLoading
  66.                                       ? Center(
  67.                                           child: GlowingProgressIndicator(
  68.                                             child: Image.asset(
  69.                                                 'assets/images/icon.png',
  70.                                                 width: 50,
  71.                                                 height: 70),
  72.                                           ),
  73.                                         )
  74.                                       : agendamento.horarios.length == 0
  75.                                           ? Column(
  76.                                               children: <Widget>[
  77.                                                 Center(
  78.                                                   child: Text(
  79.                                                     'Não há mais horários disponíveis nessa data!',
  80.                                                     style: AppTheme.erroMsg,
  81.                                                     textAlign: TextAlign.center,
  82.                                                   ),
  83.                                                 )
  84.                                               ],
  85.                                             )
  86.                                           : agendamento.isLoading
  87.                                               ? Center(
  88.                                                   child:
  89.                                                       GlowingProgressIndicator(
  90.                                                     child: Image.asset(
  91.                                                         'assets/images/icon.png',
  92.                                                         width: 50,
  93.                                                         height: 70),
  94.                                                   ),
  95.                                                 )
  96.                                               : Observer(
  97.                                                   builder: (_) {
  98.                                                     return AnimationLimiter(
  99.                                                       child: Column(
  100.                                                         crossAxisAlignment:
  101.                                                             CrossAxisAlignment
  102.                                                                 .stretch,
  103.                                                         children:
  104.                                                             AnimationConfiguration
  105.                                                                 .toStaggeredList(
  106.                                                           duration:
  107.                                                               const Duration(
  108.                                                                   milliseconds:
  109.                                                                       700),
  110.                                                           childAnimationBuilder:
  111.                                                               (widget) =>
  112.                                                                   FlipAnimation(
  113.                                                             child: widget,
  114.                                                           ),
  115.                                                           children: <Widget>[
  116.                                                             Center(
  117.                                                               child: Text(
  118.                                                                 'Selecione um horário',
  119.                                                                 style: TextStyle(
  120.                                                                     fontSize:
  121.                                                                         18.0,
  122.                                                                     fontFamily:
  123.                                                                         'Poppins'),
  124.                                                               ),
  125.                                                             ),
  126.                                                             SizedBox(
  127.                                                               height: 10,
  128.                                                             ),
  129.                                                             GridView.builder(
  130.                                                               shrinkWrap: true,
  131.                                                               itemCount:
  132.                                                                   agendamento
  133.                                                                       .horarios
  134.                                                                       .length,
  135.                                                               gridDelegate:
  136.                                                                   SliverGridDelegateWithFixedCrossAxisCount(
  137.                                                                 crossAxisCount:
  138.                                                                     3,
  139.                                                                 childAspectRatio: MediaQuery.of(
  140.                                                                             context)
  141.                                                                         .size
  142.                                                                         .width /
  143.                                                                     (MediaQuery.of(context)
  144.                                                                             .size
  145.                                                                             .height /
  146.                                                                         4),
  147.                                                               ),
  148.                                                               itemBuilder:
  149.                                                                   (BuildContext
  150.                                                                           context,
  151.                                                                       int index) {
  152.                                                                 return Padding(
  153.                                                                   padding:
  154.                                                                       EdgeInsets
  155.                                                                           .all(
  156.                                                                               8),
  157.                                                                   child: Observer(
  158.                                                                       builder:
  159.                                                                           (_) {
  160.                                                                     return RaisedButton(
  161.                                                                       child:
  162.                                                                           new Text(
  163.                                                                         agendamento
  164.                                                                             .horarios[index],
  165.                                                                         style: TextStyle(
  166.                                                                             fontFamily:
  167.                                                                                 'Poppins'),
  168.                                                                       ),
  169.                                                                       textColor:
  170.                                                                           Colors
  171.                                                                               .white,
  172.                                                                       shape:
  173.                                                                           new RoundedRectangleBorder(
  174.                                                                         borderRadius:
  175.                                                                             new BorderRadius.circular(30.0),
  176.                                                                       ),
  177.                                                                       color: agendamento.currentSelectedLabel ==
  178.                                                                               agendamento.horarios[
  179.                                                                                   index]
  180.                                                                           ? Color.fromRGBO(
  181.                                                                               247,
  182.                                                                               87,
  183.                                                                               161,
  184.                                                                               1)
  185.                                                                           : Colors
  186.                                                                               .blue,
  187.                                                                       onPressed:
  188.                                                                           () {
  189.                                                                         agendamento.currentSelected =
  190.                                                                             index;
  191.                                                                         agendamento
  192.                                                                             .currentSelectedLabel = agendamento
  193.                                                                                 .horarios[
  194.                                                                             index];
  195.                                                                         agendamento
  196.                                                                             .selecionarHora(agendamento.horariosFull[index]);
  197.                                                                       },
  198.                                                                     );
  199.                                                                   }),
  200.                                                                 );
  201.                                                               },
  202.                                                             ),
  203.                                                             SizedBox(
  204.                                                               height: 15,
  205.                                                             ),
  206.                                                           ],
  207.                                                         ),
  208.                                                       ),
  209.                                                     );
  210.                                                   },
  211.                                                 ),
  212.                         ),
  213.                       ),
  214.                       agendamento.isLoading
  215.                           ? Container()
  216.                           : agendamento.selectedDate.weekday == 7 ||
  217.                                   agendamento.horarios.length == 0
  218.                               ? Container()
  219.                               : Card(
  220.                                   elevation: 5,
  221.                                   margin: EdgeInsets.only(
  222.                                       top: 10, left: 4, right: 4),
  223.                                   child: Container(
  224.                                     padding: EdgeInsets.all(20),
  225.                                     child: AnimationLimiter(
  226.                                       child: Column(
  227.                                         children: AnimationConfiguration
  228.                                             .toStaggeredList(
  229.                                           duration:
  230.                                               const Duration(milliseconds: 700),
  231.                                           childAnimationBuilder: (widget) =>
  232.                                               FlipAnimation(
  233.                                             child: widget,
  234.                                           ),
  235.                                           children: <Widget>[
  236.                                             Center(
  237.                                               child: Text(
  238.                                                 'Selecione um serviço',
  239.                                                 style: TextStyle(
  240.                                                     fontSize: 18.0,
  241.                                                     fontFamily: 'Poppins'),
  242.                                               ),
  243.                                             ),
  244.                                             SizedBox(
  245.                                               height: 10,
  246.                                             ),
  247.                                             CustomRadioButton(
  248.                                               height: 40,
  249.                                               enableShape: true,
  250.                                               buttonColor: Colors.white,
  251.                                               buttonLabels: [
  252.                                                 'Design sem henna (R\$ 25,00)',
  253.                                                 'Design com henna (R\$ 35,00)'
  254.                                               ],
  255.                                               buttonValues: [
  256.                                                 'Design sem henna',
  257.                                                 'Design com henna'
  258.                                               ],
  259.                                               radioButtonValue:
  260.                                                   agendamento.selecionarServico,
  261.                                               horizontal: true,
  262.                                               selectedColor: Colors.black,
  263.                                             ),
  264.                                             SizedBox(
  265.                                               height: 40,
  266.                                             ),
  267.                                             Observer(
  268.                                               builder: (_) => CriaBotao(
  269.                                                 texto: 'AGENDAR',
  270.                                                 horario:
  271.                                                     agendamento.horaSelecionada,
  272.                                                 servico: agendamento
  273.                                                     .servicoSelecionado,
  274.                                                 context: context,
  275.                                               ),
  276.                                             ),
  277.                                           ],
  278.                                         ),
  279.                                       ),
  280.                                     ),
  281.                                   ),
  282.                                 ),
  283.                       SizedBox(
  284.                         height: 20,
  285.                       ),
  286.                     ],
  287.                   );
  288.                 },
  289.               ),
  290.             ],
  291.           ),
  292.         ),
  293.         Card(
  294.           elevation: 5,
  295.           child: Container(
  296.             height: 120,
  297.             margin: EdgeInsets.all(8),
  298.             child: Column(
  299.               children: <Widget>[
  300.                 Row(
  301.                   mainAxisAlignment: MainAxisAlignment.center,
  302.                   children: <Widget>[
  303.                     Text(
  304.                       'Selecione a data',
  305.                       style: TextStyle(fontSize: 18.0, fontFamily: 'Poppins'),
  306.                     ),
  307.                   ],
  308.                 ),
  309.                 SizedBox(
  310.                   height: 8,
  311.                 ),
  312.                 DatePicker(
  313.                   DateTime.now(),
  314.                   width: 60,
  315.                   height: 80,
  316.                   controller: _controller,
  317.                   initialSelectedDate: DateTime.now(),
  318.                   selectionColor: Colors.black,
  319.                   selectedTextColor: Colors.white,
  320.                   daysCount: 10,
  321.                   locale: 'pt_BR',
  322.                   onDateChange: agendamento.verificaHorarios,
  323.                 ),
  324.               ],
  325.             ),
  326.           ),
  327.         ),
  328.       ],
  329.     );
  330.   }
  331. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement