Created
December 17, 2019 20:00
Revisions
-
allansrc created this gist
Dec 17, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,206 @@ import 'package:flutter/material.dart'; import 'dart:async'; import 'dart:convert'; import 'package:http/http.dart' as http; import 'package:sac_soma/constant.dart'; import '../conversas.dart'; import 'package:sac_soma/app_data.dart'; // import 'package:js/js.dart'; // import 'package:js/js_util.dart'; // import 'package:sac_soma/utils/sha256.js'; // import 'package:sac_soma/utils/socket.io.js'; import 'package:adhara_socket_io/adhara_socket_io.dart'; class LoginScreen extends StatefulWidget { // final WebSocketChannel channel; LoginScreen({Key key}) : super(key: key); @override _LoginScreenState createState() => _LoginScreenState(); } class _LoginScreenState extends State<LoginScreen> { List<String> toPrint = ["trying to conenct"]; SocketIOManager manager; SocketIO socket; bool isProbablyConnected = false; // ###################################### _showDialog(String mensagem) { showDialog( context: context, builder: (BuildContext context) { return AlertDialog( backgroundColor: Colors.yellow[400], title: Text( 'Erro no Login', style: TextStyle(color: Colors.red, fontWeight: FontWeight.w700), ), content: Text( mensagem, style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.w800), ), actions: <Widget>[ RaisedButton( color: Colors.lightGreenAccent[400], child: Text( 'ok', style: TextStyle(color: Colors.white, fontSize: 18.0), ), onPressed: () { Navigator.of(context).pop(); }, ) ], ); }, ); } Future<String> loginServe() async { var url = "$baseURL/login"; print(url); http.Response response = await http.post( //Uri.encodeFull removes all the dashes or extra characters present in our Uri Uri.encodeFull(url), headers: { 'Conten-Type': 'application/json' }, body: { 'usuario': _userController.text, 'senha': _passController.text, 'tipo': 'mobile', 'chave': chave }); print("encoded json ${response.body}"); Map<String, dynamic> data = json.decode(response.body); if (data['result'] == 'success') { appData.dadosJson = data['usuario']; // var usuarioid = data['usuario']['id']; // var urlConversas = "$baseURL/conversas/$usuarioid"; // http.Response resposta = await http.get( // Uri.encodeFull(urlConversas), headers: { // 'Conten-Type': 'application/json', // 'Authorization': chave, // }); // print(resposta.body); // Map<String, dynamic> dados = json.decode(resposta.body); // socket // Navigator.pushReplacement( // context, // MaterialPageRoute<Map>( // builder: (context) => ConversasScreen( // // add conversas posteriormente :: linha abaixo // // conversas: data['usuario'], // dadosUsuario: data['usuario'], // ), // ), // ); } else { _showDialog(data['msg']); } } // controllers TextEditingController _userController = TextEditingController(); TextEditingController _passController = TextEditingController(); @override Widget build(BuildContext context) { var btnLogin = Container( margin: EdgeInsets.only(top: 20.0), width: MediaQuery.of(context).size.width, height: 35.0, child: FlatButton.icon( onPressed: loginServe, //getData, // declarar sem parentesis icon: Icon( Icons.forward, color: Colors.white, ), color: Color(0xFF81dc54), label: Text( "Entrar", style: TextStyle( color: Colors.white, ), ), ), ); var formLogin = Column(children: <Widget>[ TextField( controller: _userController, decoration: InputDecoration( suffixIcon: Icon(Icons.account_circle), labelText: 'Usuário', ), ), Container( margin: EdgeInsets.only(top: 20.0, bottom: 20.0), child: TextField( obscureText: true, controller: _passController, decoration: InputDecoration( suffixIcon: Icon(Icons.security), labelText: 'Senha', ), ), ), ]); var logoSomaSac = Container( margin: EdgeInsets.only(bottom: 30.0, top: 30.0), child: Image.asset( 'images/SomaSac.png', alignment: Alignment.center, height: 80.0, ), ); return Scaffold( backgroundColor: Colors.grey[100], body: Container( alignment: Alignment.center, child: ListView(children: <Widget>[ Container( alignment: Alignment.center, margin: EdgeInsets.all(40.0), padding: EdgeInsets.all(16.0), child: Column( children: <Widget>[ logoSomaSac, Column( children: [ formLogin, btnLogin, ], ), ], )) ]), )); } }