error: The argument type 'Jsobject' can’t be Assigned to the Parameter type 'Buildcontext'

Asked

Viewed 116 times

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'.

inserir a descrição da imagem aqui

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),)
    );

  }
}

1 answer

0

You probably imported the library dart-js by mistake.

This library has the property context that makes your code confuse and generate this error.

Try removing the import:

import 'dart:js'; //Remova essa linha

I didn’t see anything in your code that could make use of this property, since this library serves to expose some Javascript objects. That is why you should be able to remove without any problems.

For more information you can see that one Related content on Flutter’s official github.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.