Advertisement
yudiwibisono

flutter_router_pop

Apr 17th, 2022
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.28 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. class LayarKedua extends StatelessWidget {
  4.   @override
  5.   Widget build(BuildContext context) {
  6.     return Scaffold(
  7.         appBar: AppBar(
  8.           title: const Text('Screen 2'),
  9.         ),
  10.         body: Center(
  11.             child: ElevatedButton(
  12.           child: const Text("Ini screen kedua, tap icon back di app bar"),
  13.           onPressed: () {
  14.             Navigator.of(context).pop();
  15.           },
  16.         )));
  17.   }
  18. }
  19.  
  20. void main() {
  21.   runApp(const MyApp());
  22. }
  23.  
  24. class MyApp extends StatelessWidget {
  25.   const MyApp({Key? key}) : super(key: key);
  26.  
  27.   @override
  28.   Widget build(BuildContext context) {
  29.     return MaterialApp(title: 'Test Route', home: MyHome());
  30.   }
  31. }
  32.  
  33. //perlu  dipisah karena Navigator perlu punya parent Material App
  34. class MyHome extends StatelessWidget {
  35.   @override
  36.   Widget build(BuildContext context) {
  37.     return Scaffold(
  38.       appBar: AppBar(
  39.         title: const Text('Test Route'),
  40.       ),
  41.       body: Center(
  42.         child: ElevatedButton(
  43.             child: const Text('Ke screen Kedua'),
  44.             onPressed: () {
  45.               Navigator.of(context).push(MaterialPageRoute(builder: (context) {
  46.                 return LayarKedua();
  47.               }));
  48.             }),
  49.       ),
  50.     );
  51.   }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement