Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:navigation_test/app_routes.dart';
- import 'package:navigation_test/navigator_app.dart';
- import 'dart:developer';
- // class FirstScreen extends StatefulWidget {
- // const FirstScreen({Key? key}) : super(key: key);
- // //const FirstScreen({Key? key, required this.inputData}) : super(key: key);
- //
- // @override
- // FirstScreenState createState() => FirstScreenState();
- // }
- class FirstScreen extends StatelessWidget {
- final String? inputData = "default";
- const FirstScreen({Key? key}) : super(key: key);
- Future<bool> showExitDialog(BuildContext context) async => await showDialog(
- context: context,
- builder: (context) => AlertDialog(
- title: const Text('Question'),
- content: const Text('Do you want to exit?'),
- actions: <Widget>[
- TextButton(
- child: const Text('Yes'),
- onPressed: () => Navigator.of(context).pop(true),
- ),
- TextButton(
- onPressed: () => Navigator.of(context).pop(false),
- child: const Text('No'),
- ),
- ],
- ),
- );
- @override
- Widget build(BuildContext context) {
- return WillPopScope(
- onWillPop: () {
- log("this is onWillPop method");
- return showExitDialog(context);
- },
- child: Scaffold(
- appBar: AppBar(
- centerTitle: true,
- title: const Text('Module three'),
- leading: IconButton(
- onPressed: () async {
- bool exit = await (showExitDialog(context));
- if (exit) {
- Navigator.of(context).pop();
- }
- },
- icon: const Icon(Icons.arrow_back),
- )),
- body: Column(
- children: [
- Container(
- alignment: Alignment.center,
- child: ElevatedButton(
- onPressed: () =>
- Navigator.of(context).pushNamed(AppRoutes.secondScreen),
- child: const Text('Go next'),
- ),
- ),
- Text('$inputData'),
- ],
- ),
- ),
- );
- }
- }
- class SecondScreen extends StatelessWidget {
- const SecondScreen({Key? key}) : super(key: key);
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- home: Scaffold(
- appBar: AppBar(),
- body: Column(
- children: [
- Container(
- alignment: Alignment.center,
- child: ElevatedButton(
- onPressed: () => Navigator.of(context)
- .pushNamed(AppRoutes.home, arguments: 'Return 42'),
- child: const Text('Return 42'),
- ),
- ),
- Container(
- alignment: Alignment.topCenter,
- child: ElevatedButton(
- onPressed: () => Navigator.of(context)
- .pushNamed(AppRoutes.home, arguments: 'Return AbErVaLIG'),
- child: const Text('Return AbErVaLIG'),
- ),
- ),
- ],
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment