123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import 'package:flutter/material.dart';
- import 'package:provider/provider.dart';
- import '../../models/models.dart';
- import '../../viewmodels/variable_view_model.dart';
- import '../../themes/themes.dart';
- import '../../widgets/widgets.dart';
- class VariableForm extends StatefulWidget {
- final Variable variable;
- const VariableForm({Key? key, required this.variable}) : super(key: key);
- @override
- _VariableFormState createState() => _VariableFormState();
- }
- class _VariableFormState extends State<VariableForm> {
- final _nombre = TextEditingController();
- final _clave = TextEditingController();
- final _descripcion = TextEditingController();
- bool _activo = true;
- @override
- void initState() {
- super.initState();
- _nombre.text = widget.variable.nombre ?? "";
- _clave.text = widget.variable.clave ?? "";
- _descripcion.text = widget.variable.descripcion ?? "";
- _activo = widget.variable.activo ?? true;
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text(
- widget.variable.id == null ? 'Nueva Variable' : 'Editar Variable',
- style: TextStyle(color: AppTheme.secondary),
- ),
- iconTheme: IconThemeData(color: AppTheme.secondary),
- ),
- body: SingleChildScrollView(
- padding: EdgeInsets.all(8),
- child: Column(
- children: [
- tarjeta(
- Padding(
- padding: const EdgeInsets.all(8),
- child: Column(
- children: [
- AppTextField(
- maxLength: 100,
- etiqueta: 'Nombre',
- controller: _nombre,
- hintText: 'Nombre de la variable',
- ),
- AppTextField(
- maxLength: 100,
- etiqueta: 'Clave',
- controller: _clave,
- hintText: 'Clave de la variable',
- ),
- AppTextField(
- maxLength: 200,
- etiqueta: 'Descripción',
- controller: _descripcion,
- hintText: 'Descripción de la variable',
- ),
- SwitchListTile(
- activeColor: AppTheme.primary,
- title: const Text(
- "Activo",
- style: TextStyle(
- fontWeight: FontWeight.bold, fontSize: 18),
- ),
- value: _activo,
- onChanged: (bool value) {
- setState(() {
- _activo = value;
- });
- },
- ),
- ],
- ),
- ),
- ),
- SizedBox(height: 15),
- boton("Guardar", () async {
- Provider.of<VariableViewModel>(context, listen: false)
- .setIsLoading(true);
- widget.variable.nombre = _nombre.text;
- widget.variable.clave = _clave.text;
- widget.variable.descripcion = _descripcion.text;
- widget.variable.activo = _activo;
- await Provider.of<VariableViewModel>(context, listen: false)
- .updateVariable(widget.variable);
- Provider.of<VariableViewModel>(context, listen: false)
- .setIsLoading(false);
- if (context.mounted) {
- Navigator.pop(context);
- }
- })
- ],
- ),
- ),
- );
- }
- @override
- void dispose() {
- _nombre.dispose();
- _clave.dispose();
- _descripcion.dispose();
- super.dispose();
- }
- }
|