Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:PhotoReport/blocs/categoria_bloc.dart';
- import 'package:PhotoReport/helpers/categoria_helper.dart';
- import 'package:PhotoReport/helpers/obra_helper.dart';
- import 'package:PhotoReport/validators/categoria_validatores.dart';
- import 'package:flutter/material.dart';
- class AddCategoriaPage extends StatefulWidget {
- final String action;
- final Obra obra;
- final Categoria categoria;
- AddCategoriaPage(this.action, {this.obra, this.categoria});
- @override
- _AddCategoriaPageState createState() => _AddCategoriaPageState();
- }
- class _AddCategoriaPageState extends State<AddCategoriaPage>
- with CategoriaValidator {
- final _nomeCtrl = TextEditingController();
- Obra _obra;
- bool _load = false;
- Categoria _editedCategoria;
- final _formKey = GlobalKey<FormState>();
- @override
- void initState() {
- super.initState();
- _obra = widget.obra;
- if (widget.categoria == null) {
- _editedCategoria = Categoria();
- _editedCategoria.obraId = _obra.id;
- } else {
- _editedCategoria = widget.categoria;
- _editedCategoria.obraId = _obra.id;
- _nomeCtrl.text = _editedCategoria.nome;
- }
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text(
- widget.action == 'add' ? 'Criar Categoria' : 'Editar Categoria'),
- ),
- body: _load
- ? Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: <Widget>[
- Center(
- child: CircularProgressIndicator(),
- ),
- Text("Carregando...")
- ],
- )
- : Form(
- key: _formKey,
- child: ListView(
- padding: EdgeInsets.all(10.0),
- children: <Widget>[
- TextFormField(
- controller: _nomeCtrl,
- textCapitalization: TextCapitalization.words,
- decoration:
- InputDecoration(labelText: "Nome", filled: true),
- validator: validateNome,
- onChanged: (value) {
- setState(() {
- _editedCategoria.nome = value;
- });
- },
- ),
- const SizedBox(height: 12.0),
- SizedBox(
- height: 44.0,
- child: RaisedButton(
- color: Colors.blue,
- textColor: Colors.white,
- child: Center(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Text(
- widget.action == 'add' ? "CADASTRAR" : "ALTERAR",
- style: TextStyle(fontSize: 18.0),
- )
- ],
- ),
- ),
- onPressed: () {
- if (widget.action == 'add') {
- setState(() {
- categoriaBloc.salvar(_editedCategoria);
- Navigator.of(context).pop(true);
- });
- } else {
- setState(() {
- categoriaBloc.alterar(_editedCategoria);
- Navigator.of(context).pop(true);
- });
- }
- },
- ),
- )
- ],
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement