diff --git a/lib/src/pages/NewCategoryPage.dart b/lib/src/pages/NewCategoryPage.dart new file mode 100644 index 0000000..32aaf09 --- /dev/null +++ b/lib/src/pages/NewCategoryPage.dart @@ -0,0 +1,96 @@ +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 { + final _formKey = GlobalKey(); + 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, + ), + ), + ], + ), + ), + ), + ); + } +} diff --git a/lib/src/pages/home_page.dart b/lib/src/pages/home_page.dart index 4130c7c..fa9d467 100644 --- a/lib/src/pages/home_page.dart +++ b/lib/src/pages/home_page.dart @@ -1,6 +1,6 @@ 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 { 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 { drawer: MenuWidget(), body: TabBarView( children: [ - Column( + Column( children: [ Expanded( child: CategoryListWidget(), @@ -75,6 +73,9 @@ class _HomePageState extends State { child: ElevatedButton( onPressed: _handleNewCategory, child: const Text('Nueva categoría'), + style: ElevatedButton.styleFrom( + foregroundColor: Colors.white, backgroundColor: Colors.blue, + ), ), ), ], diff --git a/lib/src/pages/login_page.dart b/lib/src/pages/login_page.dart index 39c3684..275b2c0 100644 --- a/lib/src/pages/login_page.dart +++ b/lib/src/pages/login_page.dart @@ -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, + ), ), ], ), diff --git a/pubspec.lock b/pubspec.lock index 58e5797..7ed2635 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: diff --git a/pubspec.yaml b/pubspec.yaml index f3cfe6b..1ceca89 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: