Failed assertion: line 4021 pos 12: 'name != null': is not true

Viewed 38

Hello programmers I have the following problem Failed assertion: line 4021 pos 12: 'name != null': is not true. when I use onTap(){_con.goToPage} Clicking on the image takes the user to another page I need help please, this error has stalled my process I show the two Dart files involved in the error

class RolesPage extends StatefulWidget {
  const RolesPage({Key key}) : super(key: key);
  @override
  _RolesPageState createState() => _RolesPageState();
}
class _RolesPageState extends State<RolesPage> {

  RolesController _con = new RolesController();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    SchedulerBinding.instance.addPostFrameCallback((timeStamp) {
      _con.init(context, refresh);
    });
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("select a role"),
      ),
      body: Container(
        margin: EdgeInsets.only(top: MediaQuery.of(context).size.height * 0.14),
        child: ListView(
            children: _con.user != null ? _con.user.roles.map((Rol rol){
              return _cardRol(rol);
            }).toList() : []
        ),
      ),
    );
  }
  Widget _cardRol(Rol rol){
    return GestureDetector(
      onTap: (){
        _con.goToPage(rol.route);
      },
      child: Column(
        children: [
          Container(
            height: 100,
            child: FadeInImage(
              image: rol.image != null
                  ? NetworkImage(rol.image)
                  : AssetImage('assets/img/enchufe.jpg'),
              fit: BoxFit.contain,
              fadeInDuration: Duration(milliseconds: 50),
              placeholder: AssetImage('assets/img/enchufe.jpg'),
            ),
          ),
          SizedBox(height: 15),
          Text(
            rol.name ?? '',
            style: TextStyle(
                fontSize: 16,
                color: Colors.black
            ),
          ),
          SizedBox(height: 25),
        ],
      ),
    );
  }
  void refresh(){
    setState(() {
    });
  }
}


class RolesController {

  BuildContext context;
  Function refresh;

  User user;
  SharedPref sharedPref = new SharedPref();
  Future init(BuildContext context, Function refresh) async{
    this.context = context;
    this.refresh = refresh;

    user = User.fromJson(await sharedPref.read('user'));
    refresh();
  }
  void goToPage(String route) {
    Navigator.pushNamedAndRemoveUntil( context, route, (route) => false);
  }

}

using the debug mode I realized that the route arrives null

0 Answers
Related