0
I’m trying to navigate from the login screen to the homescreen, but when creating the void _onSuccess is returning the error: error: The argument type 'Jsobject' can’t be Assigned to the Parameter type 'Buildcontext'.
Follows the code:
import 'dart:js';
import 'package:flutter/material.dart';
import 'package:inyouhands/models/user_model.dart';
import 'package:inyouhands/screen/home_screen.dart';
import 'package:scoped_model/scoped_model.dart';
class LoginScreen extends StatelessWidget {
final _emailController = TextEditingController();
final _passController = TextEditingController();
final _scaffoldKey = GlobalKey<ScaffoldState>();
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).primaryColor,
body: ScopedModelDescendant<UserModel>(
builder: (context, child, model){
if(model.isLoading)
return Center(child: CircularProgressIndicator(),);
else
return Form(
key: _formKey,
child: ListView(
padding: EdgeInsets.all(36.0),
children: [
Expanded(child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 50.0,
),
Image.asset("images/icons8-ok-hand-96.png"),
SizedBox(
height: 16.0,
),
Text(
"In You Hands",
style: TextStyle(
fontSize: 32.0,
fontWeight: FontWeight.w500,
color: Colors.black,
),
)
],
),
),
SizedBox(
height: 100.0,
),
TextFormField(
controller: _emailController,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(hintText: "E-mail",
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Color.fromARGB(255, 4, 100, 141), width: 50.0),
borderRadius: BorderRadius.circular(32.0),),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Color.fromARGB(255, 4, 100, 141),width: 50.0),
borderRadius: BorderRadius.circular(32.0)),
hintStyle: TextStyle(color: Colors.white),
),
keyboardType: TextInputType.emailAddress,
validator: (text) {
if (text.isEmpty || !text.contains("@"))
return "E-mail inválido!";
},
),
SizedBox(
height: 16.0,
),
TextFormField(
controller: _passController,
decoration: InputDecoration(hintText: "Senha",
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Color.fromARGB(255, 4, 100, 141),width: 50.0),
borderRadius: BorderRadius.circular(32.0)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Color.fromARGB(255, 4, 100, 141),width: 50.0,),
borderRadius: BorderRadius.circular(32.0),),
hintStyle: TextStyle(color: Colors.white),),
obscureText: true,
validator: (text) {
if (text.isEmpty || text.length < 6) return "Senha Inválida!";
},
),
// SizedBox(
// height: 16.0,
// ),
Padding(
padding: EdgeInsets.all(16.0),
child: Material(
elevation: 5.0,
borderRadius: BorderRadius.circular(32.0),
color: Color.fromARGB(255, 4, 100, 141),
child: MaterialButton(
padding: EdgeInsets.all(16.0),
onPressed: () {
if(_formKey.currentState.validate()){
}
model.signIn(email: _emailController.text,
pass: _passController.text,
onSuccess: _onSuccess,
onFail: _onFail);
},
child: Text(
"Login",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20.0, color: Colors.white, fontWeight: FontWeight.bold),
),
),
),
),
],
),
);
},
)
);
}
void _onSuccess(){
Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (context)=>HomeScreen()),(Route<dynamic> route) => false);
}
void _onFail(){
_scaffoldKey.currentState.showSnackBar(
SnackBar(content: Text("Falha ao Entrar!"),
backgroundColor: Colors.redAccent,
duration: Duration(seconds: 2),)
);
}
}