从一个屏幕路由到另一个屏幕时显示错误 [英] Showing error while routing from one screen to another in flutter

查看:220
本文介绍了从一个屏幕路由到另一个屏幕时显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从一个屏幕移动到另一个屏幕,但是显示路由错误. 我的第一个屏幕命名为VenueOption,第二个屏幕命名为PlayerOption

I'm moving from one screen to another screen but it shows error in routing. My First screen named as VenueOption and the second one is PlayerOption

这是场地选项类

class VenueOption extends StatelessWidget {
  final String userType;

  const VenueOption({Key key, @required this.userType}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ProfileBoard(
        userType: userType,
      ),
    );
    /*return MaterialApp(
      debugShowCheckedModeBanner: false,
      home:Scaffold(
      body: ProfileBoard(
        userType: userType,
      ),)
    );*/
  }
}

ProfileBoard内有一个按钮,该类是statefull类,并且通过此方法可导航到"PlayerOption"屏幕

There is a button inside ProfileBoard, this class is statefull class and navigation screen to 'PlayerOption' by this method

 void pushToDashboard(BuildContext context) {
      Navigator.push(
        context,
        MaterialPageRoute(builder: (context) => PlayerOption()),
      );
      // Navigator.push(context, MaterialPageRoute(builder: (context) => VenuProfile(userType: userType,)),);
    }

PlayerOption

class PlayerOption extends StatefulWidget {
  @override
  _PlayerOptionState createState() => _PlayerOptionState();
}

class _PlayerOptionState extends State<PlayerOption> {
  @override
  Widget build(BuildContext context) {

 return Scaffold(
   resizeToAvoidBottomInset:false,
   body: PlayerOptionHome(),
 );
   /* return MaterialApp(
      debugShowCheckedModeBanner: false,
      home:Scaffold(
        resizeToAvoidBottomInset:false,

        body: PlayerOptionHome(),

      )
    );*/
  }
}

> The following NoSuchMethodError was thrown building
> _OverlayEntry-[LabeledGlobalKey<_OverlayEntryState>#be2a0](dirty, state: _OverlayEntryState#6e209): The getter 'status' was called on
> null. Receiver: null Tried calling: status When the exception was
> thrown, this was the stack:
> #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5)
> #1      ModalRoute._buildModalBarrier (package:flutter/src/widgets/routes.dart:1239:27)
> #2      _OverlayEntryState.build (package:flutter/src/widgets/overlay.dart:170:25)
> #3      StatefulElement.build (package:flutter/src/widgets/framework.dart:3825:27)
> #4      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3739:15)
> #5      Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5)
> #6      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3722:5)
> #7      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3864:11)

引发了另一个异常:NoSuchMethodError:吸气剂状态" 被调用为null.

Another exception was thrown: NoSuchMethodError: The getter 'status' was called on null.

我用MaterialApp制成了PlayerOption,现在屏幕从'VenueOption to PlayerOption but when I tried to call another screen from PlayerOption to PlayerConnect`导航,显示错误

I made PlayerOption with MaterialApp now the screen is navigating from 'VenueOptiontoPlayerOptionbut when I tried to call another screen fromPlayerOptiontoPlayerConnect ` showing error

> Another exception was thrown:
> 'package:flutter/src/widgets/navigator.dart': Failed assertion: line
> 1562 pos 12: '!_debugLocked': is not true.

class PlayerConnect extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: FeedView(),
    );
  }
}

推荐答案

尝试一下

class VenueOption extends StatelessWidget {
  final String userType;
  BuildContext ctx;

  const VenueOption({Key key, @required this.userType}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    ctx = context;
    return Scaffold(
      body: ProfileBoard(
        userType: userType,
      ),
    ); 
  }
 void pushToDashboard() {

    Navigator.of(ctx).push(MaterialPageRoute(
              builder: (BuildContext context) => PlayerOption()));
 }
}

这篇关于从一个屏幕路由到另一个屏幕时显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆