Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:bloc_pattern/bloc_pattern.dart';
- import 'package:flutter/material.dart';
- import 'package:mobile/blocs/settings-bloc.dart';
- import 'package:mobile/widgets/custom-drawer.dart';
- import 'package:mobile/widgets/input_field.dart';
- import '../config.dart';
- import 'home_screen.dart';
- class SetupScreen extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text("$APP_TITLE - Ajustes"),
- centerTitle: true,
- ),
- drawer: CustomDrawer(),
- body: SetupForm(),
- );
- }
- }
- class SetupForm extends StatefulWidget {
- @override
- _SetupFormState createState() => _SetupFormState();
- }
- class _SetupFormState extends State<SetupForm> {
- final _formKey = GlobalKey<FormState>();
- @override
- Widget build(BuildContext context) {
- final bloc = BlocProvider.of<SettingsBloc>(context);
- return SingleChildScrollView(
- child: Container(
- margin: EdgeInsets.all(32),
- child: Form(
- key: _formKey,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Container(
- width: 160,
- child: Image.asset("images/logo.png"),
- ), // Logo
- SizedBox(height: 32),
- StreamBuilder<SettingsState>(
- stream: bloc.outState,
- builder: (context, snapshot) {
- if (snapshot.data == SettingsState.SAVED) {
- bloc.inState.add(SettingsState.DONE);
- WidgetsBinding.instance.addPostFrameCallback(
- (_) => _showDialog(context, bloc));
- }
- if (snapshot.data != SettingsState.DONE) {
- return Container(
- alignment: Alignment.center,
- margin: EdgeInsets.only(top: 32),
- child: CircularProgressIndicator(),
- );
- }
- return Column(
- children: <Widget>[
- InputField(
- icon: Icons.local_gas_station,
- hint: "IP do Concentrador",
- obscure: false,
- keyboardType: TextInputType.number,
- inputFormat: CustomFormatters.FORMAT_IP_ADDRESS,
- stream: bloc.outEditIP,
- onChanged: bloc.changeIP,
- ),
- InputField(
- icon: Icons.exit_to_app,
- hint: "Porta de conexão(771, 1771, 857)",
- obscure: false,
- keyboardType: TextInputType.number,
- inputFormat: CustomFormatters.FORMAT_IP_PORT,
- stream: bloc.outEditPort,
- onChanged: bloc.changePort,
- ),
- SizedBox(height: 48),
- StreamBuilder<bool>(
- stream: bloc.outValidated,
- builder: (context, snapshot) {
- return SizedBox(
- height: 44,
- child: RaisedButton.icon(
- disabledColor: Colors.green.withAlpha(140),
- onPressed: snapshot.hasData
- ? () {
- bloc.store();
- }
- : null,
- icon: Icon(Icons.save, color: Colors.white),
- label: Text(
- "Gravar",
- style: TextStyle(
- fontSize: 18.0,
- color: Colors.white,
- ),
- ),
- color: Colors.green,
- ),
- );
- },
- ),
- ],
- );
- },
- ),
- ],
- ),
- ),
- ),
- );
- }
- void _showDialog(BuildContext context, SettingsBloc bloc) {
- Scaffold.of(context).showSnackBar(SnackBar(
- content: Text('Dados de conexão gravados com sucesso!'),
- duration: Duration(days: 1),
- backgroundColor: Colors.black87,
- action: SnackBarAction(
- textColor: Colors.yellow,
- label: 'Ok',
- onPressed: () async {
- bloc.inPage.add(0);
- await Navigator.of(context).push(
- MaterialPageRoute(builder: (context) => HomeScreen()),
- );
- },
- ),
- ));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment