Browse Source

código para cancelar pedido

Hugo Quijada 5 months ago
parent
commit
530fe76048
2 changed files with 86 additions and 41 deletions
  1. 79 35
      lib/views/pedido/pedido_screen.dart
  2. 7 6
      pubspec.yaml

+ 79 - 35
lib/views/pedido/pedido_screen.dart

@@ -10,6 +10,9 @@ import '../../models/models.dart';
 import '../../viewmodels/viewmodels.dart';
 import '../../viewmodels/viewmodels.dart';
 import '../../widgets/widgets_components.dart' as clase;
 import '../../widgets/widgets_components.dart' as clase;
 import 'pedido_form.dart';
 import 'pedido_form.dart';
+import 'package:otp/otp.dart';
+import 'package:timezone/data/latest.dart' as timezone;
+import 'package:timezone/timezone.dart' as timezone;
 
 
 class PedidoScreen extends StatefulWidget {
 class PedidoScreen extends StatefulWidget {
   const PedidoScreen({Key? key}) : super(key: key);
   const PedidoScreen({Key? key}) : super(key: key);
@@ -23,6 +26,7 @@ class _PedidoScreenState extends State<PedidoScreen> {
   DateTime? fechaInicio;
   DateTime? fechaInicio;
   DateTime? fechaFin;
   DateTime? fechaFin;
   ScrollController horizontalScrollController = ScrollController();
   ScrollController horizontalScrollController = ScrollController();
+  TextEditingController codeController = new TextEditingController();
 
 
   @override
   @override
   void initState() {
   void initState() {
@@ -143,44 +147,84 @@ class _PedidoScreenState extends State<PedidoScreen> {
                                   '¿Estás seguro de que deseas cancelar este pedido?',
                                   '¿Estás seguro de que deseas cancelar este pedido?',
                                   style: TextStyle(fontSize: 18)),
                                   style: TextStyle(fontSize: 18)),
                               actions: [
                               actions: [
-                                Row(
-                                  mainAxisAlignment:
-                                      MainAxisAlignment.spaceBetween,
+                                Column(
                                   children: [
                                   children: [
-                                    TextButton(
-                                      onPressed: () =>
-                                          Navigator.of(context).pop(false),
-                                      child: const Text('No',
-                                          style: TextStyle(fontSize: 18)),
-                                      style: ButtonStyle(
-                                          padding: MaterialStatePropertyAll(
-                                              EdgeInsets.fromLTRB(
-                                                  20, 10, 20, 10)),
-                                          backgroundColor:
-                                              MaterialStatePropertyAll(
-                                                  Colors.red),
-                                          foregroundColor:
-                                              MaterialStatePropertyAll(
-                                                  AppTheme.secondary)),
-                                    ),
-                                    TextButton(
-                                      onPressed: () =>
-                                          Navigator.of(context).pop(true),
-                                      child: const Text('Sí',
-                                          style: TextStyle(fontSize: 18)),
-                                      style: ButtonStyle(
-                                          padding: MaterialStatePropertyAll(
-                                              EdgeInsets.fromLTRB(
-                                                  20, 10, 20, 10)),
-                                          backgroundColor:
-                                              MaterialStatePropertyAll(
-                                                  AppTheme.tertiary),
-                                          foregroundColor:
-                                              MaterialStatePropertyAll(
-                                                  AppTheme.quaternary)),
+                                    Container(
+                                      padding: EdgeInsets.all(8.0),
+                                      child: TextField(
+                                        controller: codeController,
+                                        decoration: InputDecoration(
+                                          label: Text("Para cancelar debe capturar el código")
+                                        ),
+                                      ),
                                     ),
                                     ),
+                                    Row(
+                                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
+                                      children: [
+                                        TextButton(
+                                          onPressed: () =>
+                                              Navigator.of(context).pop(false),
+                                          child: const Text('No',
+                                              style: TextStyle(fontSize: 18)),
+                                          style: ButtonStyle(
+                                              padding: MaterialStatePropertyAll(
+                                                  EdgeInsets.fromLTRB(
+                                                      20, 10, 20, 10)),
+                                              backgroundColor:
+                                                  MaterialStatePropertyAll(
+                                                      Colors.red),
+                                              foregroundColor:
+                                                  MaterialStatePropertyAll(
+                                                      AppTheme.secondary)),
+                                        ),
+                                        TextButton(
+                                          onPressed: () {
+                                            final now = DateTime.now().toUtc();
+                                            timezone.initializeTimeZones();
+
+                                            final pacificTimeZone = timezone.getLocation('America/Los_Angeles');
+                                            final date = timezone.TZDateTime.from(now, pacificTimeZone);
+                                            final codigoTotp = OTP.generateTOTPCodeString('TYSNE4CMT5LVLGWS', date.millisecondsSinceEpoch, algorithm: Algorithm.SHA1, isGoogle: true);
+
+                                            String codigo = codeController.text;
+                                            print("totp: $codigoTotp codigo:$codigo");
+                                            List<String> codigosEstaticos = [
+                                              '172449',
+                                              '827329',
+                                              // Agregar más token fijos
+                                            ];
+                                            bool esCodigoEstatico = codigosEstaticos.contains(codigo);
+                                            print("¿Es código estático? ${esCodigoEstatico} ${!esCodigoEstatico && codigo != codigoTotp}");
+                                            if(!esCodigoEstatico && codigo != codigoTotp) {
+                                              ScaffoldMessenger.of(context).showSnackBar(
+                                                SnackBar(
+                                                  content: Text('El código no es correcto'),
+                                                  duration: Duration(seconds: 2),
+                                                )
+                                              );
+                                              return;
+                                            } else {
+                                              codeController.text = '';
+                                              Navigator.of(context).pop(true);
+                                            }
+                                          },
+                                          child: const Text('Sí',
+                                              style: TextStyle(fontSize: 18)),
+                                          style: ButtonStyle(
+                                              padding: MaterialStatePropertyAll(
+                                                  EdgeInsets.fromLTRB(
+                                                      20, 10, 20, 10)),
+                                              backgroundColor:
+                                                  MaterialStatePropertyAll(
+                                                      AppTheme.tertiary),
+                                              foregroundColor:
+                                                  MaterialStatePropertyAll(
+                                                      AppTheme.quaternary)),
+                                        ),
+                                      ],
+                                    )
                                   ],
                                   ],
-                                )
+                                ),
                               ],
                               ],
                             );
                             );
                           },
                           },

+ 7 - 6
pubspec.yaml

@@ -41,14 +41,14 @@ dependencies:
   assets_audio_player: ^3.1.1
   assets_audio_player: ^3.1.1
   permission_handler: ^11.3.0
   permission_handler: ^11.3.0
   path_provider: ^2.1.2
   path_provider: ^2.1.2
-  camera: ^0.10.5+9
+  camera: ^0.11.0+2
   universal_html: ^2.2.4
   universal_html: ^2.2.4
-  dropdown_search: ^5.0.6
-  intl: ^0.19.0
-  omni_datetime_picker: ^1.0.9
+  dropdown_search: ^6.0.1
+  intl: ^0.20.1
+  omni_datetime_picker: ^2.0.4
   datetime_picker_formfield: ^2.0.1
   datetime_picker_formfield: ^2.0.1
   url_launcher: ^6.2.5
   url_launcher: ^6.2.5
-  timezone: ^0.9.2
+  timezone: ^0.10.0
   provider: ^6.1.2
   provider: ^6.1.2
   image: ^4.1.7
   image: ^4.1.7
   file_picker: ^8.0.0+1
   file_picker: ^8.0.0+1
@@ -63,11 +63,12 @@ dependencies:
   spelling_number: ^0.0.4
   spelling_number: ^0.0.4
   file_picker_writable: ^2.1.0+1
   file_picker_writable: ^2.1.0+1
   bcrypt: ^1.1.3
   bcrypt: ^1.1.3
+  otp: ^3.1.3
 
 
 dev_dependencies:
 dev_dependencies:
   flutter_test:
   flutter_test:
     sdk: flutter
     sdk: flutter
-  flutter_launcher_icons: "^0.13.1"
+  flutter_launcher_icons: ^0.14.1
 
 
 flutter_launcher_icons:
 flutter_launcher_icons:
     android: "launcher_icon"
     android: "launcher_icon"