×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Text
Posted by: JORGE ALCALA
Added: Apr 4, 2021 1:42 PM
Views: 3956
Tags: no tags
  1. import 'package:flutter/material.dart';
  2. import 'package:invent_app/model/general.dart';
  3. import '../general/constantes.dart';
  4.  
  5. class Clase1Sc extends StatefulWidget {
  6.   int _uno_; // es hijo
  7.   int _uno_;
  8.   Clase1Sc({Key key, @required this._uno_, @required this._uno_}) : super(key: key);
  9.   @override
  10.   _clase2State createState() => _clase2();
  11. }
  12.  
  13. ///
  14. class _clase2State extends State<Clase1> {
  15.   bool _enProceso = false;
  16.   algoCrl control = new AlgoCrl(); // el control
  17.   int _nuevo = 1;
  18.   bool _autoValidar = false;
  19.   final _formaKey = GlobalKey<FormState>();
  20.   /*
  21.   generados
  22.     bool _interno;
  23.     int _claTipoProveedor;
  24.     int _claEstado;
  25.     int _claBanco;
  26.     int _iva;
  27.     final TextEditingController _nomProveedorCtrl = new TextEditingController();
  28.    */
  29.  
  30.   @override
  31.   void initState() {
  32.     /*
  33.     generados
  34.       //inicia los bool de la forma
  35.      */
  36.     _datosIniciales();
  37.     super.initState();
  38.   }
  39.   @override
  40.   void dispose() {
  41.     super.dispose();
  42.   }
  43.   @override
  44.   Widget build(BuildContext context) {
  45.     return Scaffold(
  46.       appBar: barra(),
  47.       body: SafeArea(
  48.           child: Stack(
  49.             fit: StackFit.expand,
  50.             children: [
  51.               forma(context),
  52.               Visibility(visible: _enProceso, child: progreso(),),
  53.             ],
  54.           )
  55.       ),
  56.     );
  57.   }
  58.   ///
  59.   Widget barra(){
  60.     String titulo = _nuevo == 1 ? general.n('Nueva que') : general.n('Modificar que');
  61.     return AppBar(
  62.         title: Text(titulo,
  63.             style: TextStyle(fontWeight: FontWeight.normal,
  64.                 fontSize: 17.0)
  65.         ),
  66.         brightness: Brightness.dark,
  67.         leading: IconButton(
  68.           icon: Icon(Icons.arrow_back, color: Colors.white),
  69.           onPressed: () => Navigator.of(context).pop(),
  70.         ),
  71.         actions: <Widget>[
  72.           Visibility(
  73.             visible: general.hasCredencial('cual'),
  74.             child: TextButton(
  75.               style: TextButton.styleFrom(
  76.                   primary: Colors.white,
  77.                   backgroundColor: iaColor1,
  78.                   onSurface: Colors.grey
  79.               ),
  80.               onPressed: _validar,
  81.               child: Text(general.n('Guardar'),
  82.                   style: TextStyle(
  83.                       fontWeight: FontWeight.normal,
  84.                       fontSize: 15.0,
  85.                       fontStyle: FontStyle.italic)
  86.               ),
  87.             ),
  88.           ),
  89.         ],
  90.     );
  91.   }
  92.   ///
  93.   Widget forma(context){
  94.     return Container(
  95.         color: Colors.white,
  96.         margin: EdgeInsets.all(8.0),
  97.         padding: EdgeInsets.all(8.0),
  98.         child: SingleChildScrollView(
  99.             child: Form(
  100.                 key: _formaKey,
  101.                 autovalidateMode: _autoValidadando(),
  102.                 child: Column(
  103.                   crossAxisAlignment: CrossAxisAlignment.start,
  104.                   mainAxisAlignment: MainAxisAlignment.start,
  105.                   children: [
  106.                     /*
  107.                     generados
  108.                       txtNomProveedor(),
  109.                      */
  110.                   ],
  111.                 )
  112.             )
  113.         )
  114.     );
  115.   }
  116.   ///
  117.   AutovalidateMode _autoValidadando(){
  118.     if(_autoValidar){
  119.       return AutovalidateMode.always;
  120.     }
  121.     if(!_autoValidar){
  122.       return AutovalidateMode.disabled;
  123.     }
  124.     return AutovalidateMode.onUserInteraction;
  125.   }
  126.   ///
  127.   Widget progreso() {
  128.     return Column(
  129.       crossAxisAlignment: CrossAxisAlignment.center,
  130.       mainAxisSize: MainAxisSize.max,
  131.       mainAxisAlignment: MainAxisAlignment.center,
  132.       children: [
  133.         Container(child: CircularProgressIndicator()),
  134.       ],
  135.     );
  136.   }
  137.   /*
  138.     generados
  139.       WIDGETS
  140.    */
  141.   ///
  142.   _validar(){
  143.     if(_enProceso){
  144.       return;
  145.     }
  146.     FocusScope.of(context).unfocus();
  147.     if (_formaKey.currentState.validate()) {
  148.       _guardar();
  149.     }else{
  150.       setState(() { _autoValidar = true; });
  151.       ScaffoldMessenger.of(context).showSnackBar(
  152.           SnackBar(content: Text(general.n('Datos no válidos'),),
  153.             backgroundColor: iaColor1,
  154.           )
  155.       );
  156.     }
  157.   }
  158.   ///
  159.   _guardar() async{
  160.     setState(() { _enProceso = true; });
  161.     String url = general.servidor + '/modulo_app/sendUNO';
  162.     var parametros = {
  163.       'claInvent': general.claInvent,
  164.       'nuevo': _nuevo.toString(),
  165.       /*
  166.        generados
  167.         'claProveedor': widget.claProveedor.toString(),
  168.         'nomProveedor': _nomProveedorCtrl.text,
  169.        */
  170.     };
  171.  
  172.     Map<String, dynamic> datos = await API.post(url, parametros, debug: false);
  173.     // print(datos);
  174.     int idRespuesta = datos['idRespuesta'] + 0;
  175.     if( idRespuesta == 1 ) {
  176.       _tres_Model _dirActualizada = new _tres_Model(
  177.         /*generados
  178.         claProveedor: datos['data']['claProveedor'] ?? 0,
  179.         nomProveedor: datos['data']['nomProveedor'] ?? '',
  180.          */
  181.       );
  182.       ScaffoldMessenger.of(context).showSnackBar(
  183.           SnackBar(
  184.             content: Text(datos['aviso']),
  185.             backgroundColor: iaColor1,
  186.           )
  187.       );
  188.       Navigator.pop(context, _dirActualizada);
  189.     }else{
  190.       ScaffoldMessenger.of(context).showSnackBar(
  191.           SnackBar(
  192.             content: Text(datos['aviso'],),
  193.             backgroundColor: iaColor1,
  194.           )
  195.       );
  196.     }
  197.     setState(() { _enProceso = false; });
  198.   }
  199.   ///
  200.   _datosIniciales() async {
  201.     setState(() => _enProceso = true);
  202.     if(widget.claDireccion > 0) {
  203.       var datos = await control.getProveedor(widget.claProveedor);
  204.       _nuevo = datos['nuevo'];
  205.       /*
  206.         generados
  207.         _nomProveedorCtrl.text = datos['nomProveedor'] ?? '';
  208.        */
  209.     }
  210.     setState(() => _enProceso = false);
  211.   }
  212. } // fin clase
  213.