Advertisement
Guest User

NikkiClub.dart

a guest
Apr 16th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. import 'package:jugueteriasnikki/UI/Drawer/Drawer.dart';
  4. import 'package:flutter/src/widgets/basic.dart';
  5. import 'package:jugueteriasnikki/UI/NikkiClub/Cliente.dart';
  6. import 'package:jugueteriasnikki/UI/NikkiClub/menuNikkiClub.dart';
  7. import 'package:mysql1/mysql1.dart';
  8.  
  9. import 'package:jugueteriasnikki/UI/NikkiClub/Cliente.dart' as dire;
  10.  
  11.  
  12. class nikkiclub extends StatelessWidget{
  13. final Cliente cliente;
  14. const nikkiclub ({Key key, this.cliente}) : super(key: key);
  15.  
  16. @override
  17. Widget build(BuildContext context) {
  18. return Scaffold(
  19. appBar: new AppBar(
  20. title: Text('Jugueterias Nikki - NikkiClub'),
  21. textTheme: TextTheme(title: TextStyle(color: Colors.white,fontSize: 24))),
  22. body:bodyNikkiClub(cliente: cliente) ,
  23. drawer: drawer(),
  24. );
  25.  
  26. }
  27. }
  28.  
  29. class bodyNikkiClub extends StatefulWidget {
  30. final Cliente cliente;
  31.  
  32. const bodyNikkiClub({this.cliente});
  33.  
  34. @override
  35. State<StatefulWidget> createState() => new _bodyNikkiClub();
  36.  
  37. }
  38.  
  39. class _bodyNikkiClub extends State<bodyNikkiClub> {
  40.  
  41. final GlobalKey<FormState> _formKey = new GlobalKey<FormState>();
  42. final ControllerTarjeta = TextEditingController();
  43. final ControllerClave = TextEditingController();
  44. Cliente cliente;
  45. var settings;
  46.  
  47. @override
  48. void initState(){
  49. cliente = widget.cliente;
  50. settings = new ConnectionSettings(
  51. host: '5.145.175.138',
  52. user: 'admin_admin',
  53. password: 'Joman\$2016',
  54. db: 'admin_wp_nikkiclub'
  55. );
  56. super.initState();
  57. }
  58.  
  59.  
  60. @override
  61. Widget build(BuildContext context) {
  62. return new Container(
  63. padding: new EdgeInsets.only(left: 200,right: 200,top: 40),
  64. child: new Form(
  65. key: this._formKey,
  66. child: new ListView(
  67. children: <Widget>[
  68. new TextFormField(
  69. controller: ControllerTarjeta,
  70. keyboardType: TextInputType.number,
  71. decoration: new InputDecoration(
  72. hintText: 'Número de tarjeta',
  73. labelText: 'Número de tarjeta'
  74. )
  75. ),
  76. new TextFormField(
  77. controller: ControllerClave,
  78. obscureText: true,
  79. decoration: new InputDecoration(
  80. hintText: 'Clave de tarjeta',
  81. labelText: 'Clave de tarjeta'
  82. )
  83. ),
  84. new Container(
  85. width: MediaQuery.of(context).size.width,
  86. margin: new EdgeInsets.only(top: 20.0),
  87. child: new Container(
  88. margin: EdgeInsets.only(right: 5),
  89. child: new RaisedButton(
  90. child: new Text(
  91. 'Acceder',
  92. style: new TextStyle(
  93. color: Colors.white
  94. ),
  95. ),
  96. onPressed: () async {
  97.  
  98. var conn = await MySqlConnection.connect(settings);
  99.  
  100. if (conn != null){
  101. print("Conectado a la base de datos");
  102. }
  103. else {
  104. print("Fallo al conectar a la base de datos");
  105. }
  106.  
  107. var NumeroTarjeta = ControllerTarjeta.text;
  108.  
  109. var results = await conn.query('SELECT * FROM nikkiclub WHERE numerotarjeta = ?', [NumeroTarjeta]);
  110.  
  111. if (results != null){
  112.  
  113. print("Leectura de la base de datos correcta");
  114. print(results);
  115.  
  116. }
  117. else{
  118. print("Ha ocurrido un error al leer en la base de datos");
  119. }
  120.  
  121. for (var row in results) {
  122.  
  123. if(row[26].toString().trim() == ControllerTarjeta.text && row[27].toString().trim() == ControllerClave.text){
  124.  
  125. print("Coinciden los caracteres");
  126. cliente.setNumeroTarjeta("${row[26]}");
  127. print(cliente.getNumeroTrjeta());
  128.  
  129. Navigator.push(
  130. context,
  131. MaterialPageRoute(builder: (context) => menunikkiclub(cliente: cliente)));
  132.  
  133. }
  134. else{
  135. print("No se encontraron coincidencias en la base de datos");
  136. }
  137. };
  138. },
  139. color: Colors.blue,
  140. ),
  141. )
  142. )
  143. ],
  144. ),
  145. )
  146. );
  147. }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement