Pessoal, sou novato no flutter, gos taria de saber como faço para exibir um dialog quando entrar no primeiro if da minha condição?
void submit() async{
final login = _loginController.value;
final password = _passwordController.value;
Map data = {
'login':login,
'senha':password
};
const url = "http://192.168.0.101:2020/RIF/WsAutenticar.rule?sys=RIF";
var body = json.encode(data);
var response = await http.post(url,
headers: {"Content-Type": "application/json", "accept" : "application/json",},
body: body
);
if(json.decode(response.body)["error"]){
_stateController.add(LoginState.FAIL);
// print(json.decode(response.body)["error"]);
}else {
_stateController.add(LoginState.SUCCESS);
// print(json.decode(response.body)["error"]);
return json.decode(response.body)["message"];
}
}
-----------------O código abaixo é onde renderizo a tela de login--------------
import 'package:app_rifas/blocs/login_bloc.dart';
import 'package:app_rifas/screens/home_screen.dart';
import 'package:app_rifas/widgets/input_field.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
//StatefulWidget quando tiver modificação na tela o teclado irá subir com a tela de login se adapitando ao teclado
class LoginScreen extends StatefulWidget {
@override
__LoginScreenState createState() => __LoginScreenState();
}
class __LoginScreenState extends State<LoginScreen> {
final _loginBloc = LoginBloc();
@override
Widget build(BuildContext context) {
Widget _buildDrawerBack() => Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Color.fromARGB(255, 211, 118, 138),
Color.fromARGB(255, 253, 181, 168),
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter
),
)
);
@override
void iniState(){
super.initState();
_loginBloc.outState.listen((state) {
switch(state){
case LoginState.SUCCESS:
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context)=>HomeScreen())
);
break;
case LoginState.FAIL:
showDialog(context: context, builder: (context)=>AlertDialog(
title: Text('Erro'),
content: Text("erroooooooo"),
));
break;
case LoginState.LOADING:
case LoginState.IDLE:
}
});
}
return Scaffold(
body: StreamBuilder<LoginState>(
stream: _loginBloc.outState,
// initialData: LoginState.LOADING,
builder: (context, snapshot){
print(snapshot.data);
switch(snapshot.data){
// case LoginState.LOADING:
// return Center(child: CircularProgressIndicator (valueColor: AlwaysStoppedAnimation(Colors.pinkAccent),),);
case LoginState.FAIL:
case LoginState.SUCCESS:
}
return Stack(//permitir rolar a tela quando aparecer o teclado
alignment: Alignment.center,
children: <Widget>[
_buildDrawerBack(),
Container(),
SingleChildScrollView(
child:Container(//definindo a margem pro conteúdo.
margin:EdgeInsets.all(16),
child:Column(
crossAxisAlignment: CrossAxisAlignment.stretch, //CrossAxisAlignment irá esticar tudo na horizontal
children: <Widget>[
Icon(
Icons.store_mall_directory,
color: Colors.blue,
size:160
),
InputField(
icon: Icons.person_outline,
hint: "Usuário",
obscure: false,
stream: _loginBloc.outLogin,
onChanged: _loginBloc.changeLogin,
),
InputField(
icon:Icons.lock_outline,
hint:"Senha",
obscure: true,
stream: _loginBloc.outPassword,
onChanged: _loginBloc.changePassword,
),
SizedBox(height:32,),
SizedBox( // coloquei o RaisedButton para o butão ficar com uma altura de 50
height: 50,
child: RaisedButton(
color: Colors.blue,
child: Text("Entrar"),
onPressed: _loginBloc.submit,
textColor: Colors.white,
),
)
],
),
)
)
],
);
},
)
);
}
}