Advertisement
filhotecmail

Flutter-Tost

Dec 26th, 2020
1,267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 4.82 KB | None | 0 0
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:leopardseriais/Dialogs/Leopard.Dialogs.dart';
  4. import 'package:leopardseriais/routes/configurationapp/configuration.local.storage.controller.dart';
  5.  
  6. class FormularioConfiguracaoAPP extends StatefulWidget {
  7.   FormularioConfiguracaoAPP({Key key}) : super(key: key);
  8.   @override
  9.   FormularioConfiguracaoAPPState createState() =>
  10.       FormularioConfiguracaoAPPState();
  11. }
  12.  
  13. class FormularioConfiguracaoAPPState extends State<FormularioConfiguracaoAPP> {
  14.   final _formKey = GlobalKey<FormState>();
  15.   Storagecontroller storageappcontroller = new Storagecontroller();
  16.   var ipserverin = TextEditingController();
  17.   var portin = TextEditingController();
  18.   var passwordin = TextEditingController();
  19.  
  20.   BuildContext scaffoldContext;
  21.  
  22.   @override
  23.   void initState() {
  24.     _getThingsOnStartup().then((value) {
  25.       verificastorage();
  26.     });
  27.     super.initState();
  28.   }
  29.  
  30.   // Carregamento da view Configurações APP, Delay de 1s
  31.   // O SIstemairá verificar no Storage se existe um Storage criado se não tiver
  32.   // a aplicão irá criar um Storage com valores iniciais.
  33.   Future verificastorage() async {
  34.     return storageappcontroller
  35.         .hasvalue<bool>()
  36.         .catchError((e) => {
  37.               LeopardDialogs(context).show(
  38.                   'Ops!', 'Não existem valores criados no storage', 'Entendi')
  39.             })
  40.         .then((value) => {
  41.               if (!value)
  42.                 {
  43.                   storageappcontroller.getPropStorage(
  44.                       doValues: (value) => {
  45.                             ipserverin.text = value.ipservidor,
  46.                             portin.text = value.porta,
  47.                             passwordin.text = value.password
  48.                           })
  49.                 }
  50.             });
  51.   }
  52.  
  53.   @override
  54.   Widget build(BuildContext context) {
  55.     const int FMaxLegth = 40;
  56.     return MaterialApp(
  57.       key: _formKey,
  58.       home: new Scaffold(
  59.         appBar: AppBar(
  60.           title: Text('Configurações do sistema'),
  61.         ),
  62.         body: Padding(
  63.           padding: const EdgeInsets.all(60.0),
  64.           child: Column(
  65.             children: <Widget>[
  66.               TextFormField(
  67.                 maxLength: FMaxLegth,
  68.                 decoration: InputDecoration(labelText: 'IP do servidor'),
  69.                 controller: ipserverin,
  70.                 autovalidateMode: AutovalidateMode.onUserInteraction,
  71.                 validator: (String arg) {
  72.                   if (arg.isEmpty) {
  73.                     return 'Ip do servidor não pode ser vazio';
  74.                   }
  75.                   return null;
  76.                 },
  77.               ),
  78.               Padding(
  79.                 padding: const EdgeInsets.only(top: 5.0),
  80.                 child: TextFormField(
  81.                     maxLength: FMaxLegth,
  82.                     decoration: InputDecoration(labelText: 'Porta'),
  83.                     keyboardType: TextInputType.number,
  84.                     controller: portin,
  85.                     autovalidateMode: AutovalidateMode.onUserInteraction,
  86.                     validator: (String arg) {
  87.                       if (arg.isEmpty) {
  88.                         return 'Porta não pode ser vazia';
  89.                       }
  90.                       return null;
  91.                     }),
  92.               ),
  93.               Padding(
  94.                 padding: const EdgeInsets.only(top: 5.0),
  95.                 child: TextFormField(
  96.                   obscureText: true,
  97.                   obscuringCharacter: "*",
  98.                   textAlign: TextAlign.center,
  99.                   controller: passwordin,
  100.                   autovalidateMode: AutovalidateMode.onUserInteraction,
  101.                   validator: (String arg) {
  102.                     if (arg.isEmpty) {
  103.                       return 'Password não pode ser vazio';
  104.                     }
  105.                     return null;
  106.                   },
  107.                   decoration: InputDecoration(
  108.                     labelText: 'Senha',
  109.                     hintText: "Enter password",
  110.                     icon: Icon(Icons.lock),
  111.                   ),
  112.                 ),
  113.               ),
  114.               Padding(
  115.                 padding: const EdgeInsets.only(top: 5.0),
  116.                 child: RaisedButton(
  117.                   child: Text(
  118.                     'Atualizar dados',
  119.                     textAlign: TextAlign.center,
  120.                   ),
  121.                   onPressed: () {
  122.                     storageappcontroller.setPropStorage(ipserverin.text,
  123.                         portin.text, passwordin.text, _formKey.currentContext);
  124.                   },
  125.                 ),
  126.               ),
  127.             ],
  128.           ),
  129.         ),
  130.       ),
  131.     );
  132.   }
  133.  
  134.   Future _getThingsOnStartup() async {
  135.     await Future.delayed(Duration(seconds: 1));
  136.   }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement