简体   繁体   English

如何在具有命名路由的 Flutter 应用程序顶部覆盖小部件?

[英]How to overlay a widget on top of a Flutter app with named routes?

In my Flutter app (Android and iOS only), I want to add a widget that will overlay the entire app.在我的 Flutter 应用程序(仅限 Android 和 iOS)中,我想添加一个覆盖整个应用程序的小部件。

Here is what my main class looks like:这是我的主要 class 的样子:

import 'package:flutter/material.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      initialRoute: "/someroute"
      onGenerateRoute: MyRouteManager.generateRoute
    );
  }

I tried to follow that example , but my problem is that I use named routes in my app, and I don't know how to overlay a widget above my entire app in that case.我试着按照那个例子,但我的问题是我在我的应用程序中使用了命名路由,在这种情况下我不知道如何在我的整个应用程序上方覆盖一个小部件。

I also tried the overlay_screen plugin , but it has some bugs and does not allow the user to interact with the screen below the overlay screen.我也尝试了overlay_screen 插件,但它有一些错误并且不允许用户与覆盖屏幕下方的屏幕进行交互。

How can I achieve that?我怎样才能做到这一点?

Thanks.谢谢。

try this out:试试这个:

Navigator.pushNamed(context, '/name_of_your_second_page');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM