【问题标题】:Showing error while routing from one screen to another in flutter从一个屏幕路由到另一个屏幕时显示错误
【发布时间】:2019-07-15 05:49:47
【问题描述】:

我正在从一个屏幕移动到另一个屏幕,但它显示路由错误。 我的第一个屏幕名为VenueOption,第二个屏幕名为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里面有一个按钮,这个类是有状态的类,通过这个方法可以导航到'PlayerOption'

 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: The getter 'status' 在 null 上调用。

我用MaterialApp 制作了PlayerOption,现在屏幕从'VenueOptiontoPlayerOptionbut when I tried to call another screen fromPlayerOptiontoPlayerConnect `显示错误

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

【问题讨论】:

  • 尝试更新flutter版本,应该可以了
  • @ManojPerumarath 会解决我的问题吗?最近我遇到了这个问题,在此之前,它工作正常。
  • 我正在尝试更新 SDK。
  • @ManojPerumarath 仍然面临同样的错误
  • @ManojPerumarath 1.7.8+hotfix 3

标签: android flutter navigation


【解决方案1】:

试试这个

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()));
 }
}

【讨论】:

    猜你喜欢
    • 2020-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多