从一个屏幕切换到另一个屏幕时显示错误

时间:2019-07-15 05:49:47

标签: android flutter navigation

我正在从一个屏幕转到另一个屏幕,但显示路由错误。 我的第一个屏幕名为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内有一个按钮,该类是statefull类,通过此方法可以导航到“ 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:吸气剂“状态”   被调用为null。

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

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

1 个答案:

答案 0 :(得分:0)

尝试一下

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