Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:leopardseriais/Dialogs/Leopard.Dialogs.dart';
- import 'package:leopardseriais/routes/configurationapp/configuration.local.storage.controller.dart';
- class FormularioConfiguracaoAPP extends StatefulWidget {
- FormularioConfiguracaoAPP({Key key}) : super(key: key);
- @override
- FormularioConfiguracaoAPPState createState() =>
- FormularioConfiguracaoAPPState();
- }
- class FormularioConfiguracaoAPPState extends State<FormularioConfiguracaoAPP> {
- final _formKey = GlobalKey<FormState>();
- Storagecontroller storageappcontroller = new Storagecontroller();
- var ipserverin = TextEditingController();
- var portin = TextEditingController();
- var passwordin = TextEditingController();
- BuildContext scaffoldContext;
- @override
- void initState() {
- _getThingsOnStartup().then((value) {
- verificastorage();
- });
- super.initState();
- }
- // Carregamento da view Configurações APP, Delay de 1s
- // O SIstemairá verificar no Storage se existe um Storage criado se não tiver
- // a aplicão irá criar um Storage com valores iniciais.
- Future verificastorage() async {
- return storageappcontroller
- .hasvalue<bool>()
- .catchError((e) => {
- LeopardDialogs(context).show(
- 'Ops!', 'Não existem valores criados no storage', 'Entendi')
- })
- .then((value) => {
- if (!value)
- {
- storageappcontroller.getPropStorage(
- doValues: (value) => {
- ipserverin.text = value.ipservidor,
- portin.text = value.porta,
- passwordin.text = value.password
- })
- }
- });
- }
- @override
- Widget build(BuildContext context) {
- const int FMaxLegth = 40;
- return MaterialApp(
- key: _formKey,
- home: new Scaffold(
- appBar: AppBar(
- title: Text('Configurações do sistema'),
- ),
- body: Padding(
- padding: const EdgeInsets.all(60.0),
- child: Column(
- children: <Widget>[
- TextFormField(
- maxLength: FMaxLegth,
- decoration: InputDecoration(labelText: 'IP do servidor'),
- controller: ipserverin,
- autovalidateMode: AutovalidateMode.onUserInteraction,
- validator: (String arg) {
- if (arg.isEmpty) {
- return 'Ip do servidor não pode ser vazio';
- }
- return null;
- },
- ),
- Padding(
- padding: const EdgeInsets.only(top: 5.0),
- child: TextFormField(
- maxLength: FMaxLegth,
- decoration: InputDecoration(labelText: 'Porta'),
- keyboardType: TextInputType.number,
- controller: portin,
- autovalidateMode: AutovalidateMode.onUserInteraction,
- validator: (String arg) {
- if (arg.isEmpty) {
- return 'Porta não pode ser vazia';
- }
- return null;
- }),
- ),
- Padding(
- padding: const EdgeInsets.only(top: 5.0),
- child: TextFormField(
- obscureText: true,
- obscuringCharacter: "*",
- textAlign: TextAlign.center,
- controller: passwordin,
- autovalidateMode: AutovalidateMode.onUserInteraction,
- validator: (String arg) {
- if (arg.isEmpty) {
- return 'Password não pode ser vazio';
- }
- return null;
- },
- decoration: InputDecoration(
- labelText: 'Senha',
- hintText: "Enter password",
- icon: Icon(Icons.lock),
- ),
- ),
- ),
- Padding(
- padding: const EdgeInsets.only(top: 5.0),
- child: RaisedButton(
- child: Text(
- 'Atualizar dados',
- textAlign: TextAlign.center,
- ),
- onPressed: () {
- storageappcontroller.setPropStorage(ipserverin.text,
- portin.text, passwordin.text, _formKey.currentContext);
- },
- ),
- ),
- ],
- ),
- ),
- ),
- );
- }
- Future _getThingsOnStartup() async {
- await Future.delayed(Duration(seconds: 1));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement