Обратная проблема Flutter Nested Navigator в ИнтернетеIOS

Программируем под IOS
Ответить Пред. темаСлед. тема
Anonymous
 Обратная проблема Flutter Nested Navigator в Интернете

Сообщение Anonymous »

В приложении есть вложенный навигатор, как показано ниже

Код: Выделить всё

import 'package:aa/routes.dart';
import 'package:flutter/material.dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.teal,
),
initialRoute: root,
onGenerateRoute: AppRouter.mainRouteSettings,
navigatorKey: RouteConfig().appRouteKey,
);
}
}

class Test extends StatelessWidget {
const Test({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
RouteConfig().main.currentState!.maybePop();
return false;
},
child: Scaffold(
body: Container(
margin: const EdgeInsets.all(100),
decoration: BoxDecoration(
color: Colors.grey[500], borderRadius: BorderRadius.circular(20)),
child: Navigator(
key: RouteConfig().main,
initialRoute: one,
onGenerateRoute: AppRouter.generateRoute,
),
),
),
);
}
}

import 'package:aa/main.dart';
import 'package:flutter/material.dart';

//Pre
const String root = '/';
const String preRoute = '/preRoute';

const String one = '/';
const String two = '/two';
const String three = '/three';

class RouteConfig {
static final RouteConfig _routeConfig = RouteConfig._internal();
factory RouteConfig() {
return _routeConfig;
}
RouteConfig._internal();

///App Navigator Key
GlobalKey appRouteKey = GlobalKey();

///Pre Auth Key
GlobalKey main = GlobalKey();
}

class AppRouter {
static Route mainRouteSettings(RouteSettings settings) {
late Widget page;

switch (settings.name) {
case root:
page = Scaffold(
body: Container(
child: TextButton(
onPressed: () => RouteConfig()
.appRouteKey
.currentState!
.pushReplacementNamed(preRoute),
child: Center(child: Text('Click Me')))),
);
break;
case preRoute:
page = Test();
break;
default:
page = const Center(child: Text('Not Found'));
}

return MaterialPageRoute(
builder: (context) {
return page;
},
settings: settings,
);
}

static Route generateRoute(RouteSettings settings) {
late Widget page;

print(settings.name);

switch (settings.name) {
case one:
page = Builder(builder: (context) {
return WillPopScope(
onWillPop: () async =>  !Navigator.of(context).userGestureInProgress,
child: Container(
color: Colors.pink,
margin: const EdgeInsets.all(3),
child: Center(
child: Column(
children: [
TextButton(
onPressed: () {
RouteConfig().main.currentState!.pop();
},
child: Text('pop'),
),
TextButton(
onPressed: () {
RouteConfig().main.currentState!.pushNamed(two);
},
child: Text('dcdf'),
),
],
),
),
),
);
});
break;
case two:
page = const Text('Two');
break;
case three:
page = const Text('Three');
break;
default:
page = const Center(child: Text('Not Found'));
}

return MaterialPageRoute(
builder: (context) {
return page;
},
settings: settings,
);
}
}
Я могу провести назад по вложенному навигатору.
например, после того, как я нажму кнопку всплывающего окна, появится начальный маршрут вложенного навигатора, как может идти вложенный навигатор назад, когда это начальный маршрут приложения, как предотвратить такое поведение.
См., например, видео

Подробнее здесь: https://stackoverflow.com/questions/711 ... sue-on-web
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Обратная проблема Flutter Nested Navigator в Интернете
    Anonymous » » в форуме Android
    0 Ответы
    14 Просмотры
    Последнее сообщение Anonymous
  • Android-NestED Произошла ошибка: произошла ошибка при получении информации о клиенте.
    Anonymous » » в форуме Android
    0 Ответы
    39 Просмотры
    Последнее сообщение Anonymous
  • Как заменить тег Struts 1 в Struts 2?
    Anonymous » » в форуме JAVA
    0 Ответы
    22 Просмотры
    Последнее сообщение Anonymous
  • Nested object construction of the same type
    Anonymous » » в форуме C++
    0 Ответы
    4 Просмотры
    Последнее сообщение Anonymous
  • Не удалось перейти со страницы на страницу — Navigator.push — Flutter
    Anonymous » » в форуме IOS
    0 Ответы
    21 Просмотры
    Последнее сообщение Anonymous

Вернуться в «IOS»