相关疑难解决方法(0)

Flutter Navigator无法正常工作

我有两个屏幕的应用程序,我想按下按钮从第一个屏幕到第二个屏幕.

屏幕1

import 'package:flutter/material.dart';
import './view/second_page.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return new MainScreen();
  }
}

class MainScreen extends State<MyApp> {

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
        home: new Scaffold(
            appBar: new AppBar(
                title: new Text("Title")
            ),
            body: new Center(
                child: new FlatButton(child: new Text("Second page"),
                    onPressed: () {
                      Navigator.push(context,
                          new MaterialPageRoute(
                              builder: (context) => new SecondPage()))
                    }
                )
            )
        )
    );
  } …
Run Code Online (Sandbox Code Playgroud)

dart flutter

8
推荐指数
3
解决办法
7337
查看次数

Flutter Redux Navigator GlobalKey.currentState返回null

我正在使用Redux开发Flutter.

当用户启动一个应用程序,我想Redux自动dispatchaction.此操作将Navigator依赖于推送不同的路径.

此片段由颤振dev的部件提供使用该GlobalKey使用Navigatormiddleware.

在此之后,我按如下方式组织我的代码:

main.dart

void main() {
  final store = new Store(appStateReducer,
      middleware:createRouteMiddleware()
  );
  runApp(new MyApp(store));
}

class MyApp extends StatelessWidget {
  final Store<AppState> store;

  MyApp(this.store);

  @override
  Widget build(BuildContext context) {
    return new StoreProvider<AppState>(
        store: store,
        child: MaterialApp(
            routes: {
              Routes.REGISTER: (context) {
                return RegisterScreenContainer();
              },
              Routes.SET_PROFILE: (context) {
                return SetProfileScreenContainer();
              },
              //Routes.HOME = "/" so this route will be run first
              Routes.HOME: …
Run Code Online (Sandbox Code Playgroud)

redux flutter redux-middleware

3
推荐指数
1
解决办法
2316
查看次数

颤动:从子节点检索顶级状态返回null

我正在尝试使用.of()方法获取我的应用程序的顶级状态,类似于Scaffold.of()函数.这是(精简的)代码:

class IApp extends StatefulWidget {    
  @override
  IAppState createState() => new IAppState();

  static IAppState of(BuildContext context) =>
    context.ancestorStateOfType(const TypeMatcher<IAppState>());
}
Run Code Online (Sandbox Code Playgroud)

该应用程序使用runApp(新IApp)启动

此窗口小部件创建一个HomePage:

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      // ommitted: some localization and theming details
      home: new HomePage(),
    );
  }
Run Code Online (Sandbox Code Playgroud)

然后,我尝试从HomePage(StatefulWidget本身)访问状态:

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      // ommited: some Scaffold properties such as AppBar
      // runtimeType not actual goal, but just for demonstration purposes
      body: new Text(IApp.of(context).runtimeType.toString()),
    );
  }
Run Code Online (Sandbox Code Playgroud)

奇怪的是,当我将HomePage的代码放在与 IApp 相同的文件中时,代码可以工作,但只是作为一个额外的类.但是,当我将HomePage 放在一个单独的文件 …

dart flutter

2
推荐指数
1
解决办法
2698
查看次数

标签 统计

flutter ×3

dart ×2

redux ×1

redux-middleware ×1