Commit f5b6f189 by Nayeli Monserrat Velasco Lopez

Merge branch 'nayeli.velasco' into 'master'

UI formulario de categoria See merge request !8
parents 0dfe403a a2ea6099
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
class NewCategoryPage extends StatefulWidget {
const NewCategoryPage({Key? key}) : super(key: key);
@override
_NewCategoryPageState createState() => _NewCategoryPageState();
}
class _NewCategoryPageState extends State<NewCategoryPage> {
final _formKey = GlobalKey<FormState>();
final _claveController = TextEditingController();
final _nombreController = TextEditingController();
DateTime _selectedDate = DateTime.now();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Nueva Categoría'),
backgroundColor: Colors.blue,
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Form(
key: _formKey,
child: Column(
children: [
TextFormField(
controller: _claveController,
decoration: const InputDecoration(labelText: 'Clave'),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Por favor ingrese una clave';
}
return null;
},
),
TextFormField(
controller: _nombreController,
decoration: const InputDecoration(labelText: 'Nombre'),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Por favor ingrese un nombre';
}
return null;
},
),
const SizedBox(height: 16.0),
TextFormField(
readOnly: true,
decoration: InputDecoration(
labelText: 'Fecha de Creación',
hintText: DateFormat('yyyy-MM-dd').format(_selectedDate),
),
onTap: () async {
DateTime? pickedDate = await showDatePicker(
context: context,
initialDate: _selectedDate,
firstDate: DateTime(2000),
lastDate: DateTime(2101),
);
if (pickedDate != null && pickedDate != _selectedDate) {
setState(() {
_selectedDate = pickedDate;
});
}
},
),
const SizedBox(height: 16.0),
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
int fechaCreado = _selectedDate.millisecondsSinceEpoch;
print({
"clave": _claveController.text,
"fechaCreado": fechaCreado,
"nombre": _nombreController.text
});
Navigator.pop(context);
}
},
child: const Text('GUARDAR'),
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white, backgroundColor: Colors.blue,
),
),
],
),
),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:miapp_flutter/src/specific_widgets/menu.dart' ;
import 'package:miapp_flutter/src/specific_widgets/menu.dart';
import 'NewCategoryPage.dart';
import 'category/CategoryListWidget.dart';
void main() => runApp(const DrawerApp());
......@@ -28,12 +28,10 @@ class _HomePageState extends State<HomePage> {
String selectedPage = '';
void _handleNewCategory() {
// Define la acción que debe ocurrir cuando se presiona el botón "Nueva categoria"
setState(() {
selectedPage = 'Nueva categoria';
});
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Nueva categoria presionada')),
// Navega a la página de nueva categoría
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const NewCategoryPage()),
);
}
......@@ -65,7 +63,7 @@ class _HomePageState extends State<HomePage> {
drawer: MenuWidget(),
body: TabBarView(
children: [
Column(
Column(
children: [
Expanded(
child: CategoryListWidget(),
......@@ -75,6 +73,9 @@ class _HomePageState extends State<HomePage> {
child: ElevatedButton(
onPressed: _handleNewCategory,
child: const Text('Nueva categoría'),
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white, backgroundColor: Colors.blue,
),
),
),
],
......
......@@ -42,6 +42,10 @@ class LoginPage extends StatelessWidget {
Navigator.pushNamed(context, 'home');
},
child: const Text('Acceder'),
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: Colors.blueLogin,
),
),
],
),
......
......@@ -136,6 +136,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.2"
intl:
dependency: "direct main"
description:
name: intl
sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
url: "https://pub.dev"
source: hosted
version: "0.18.1"
leak_tracker:
dependency: transitive
description:
......
......@@ -39,6 +39,7 @@ dependencies:
cupertino_icons: ^1.0.6
http: ^1.2.2
connectivity_plus: ^6.0.4
intl: ^0.18.0
dev_dependencies:
flutter_test:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment