Advertisement
yocky12k

flutter navigasi

Nov 21st, 2023 (edited)
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.09 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() {
  4.   runApp(MainApp());
  5. }
  6.  
  7. class MainApp extends StatelessWidget {
  8.   @override
  9.   Widget build(BuildContext context) {
  10.     return MaterialApp(
  11.       debugShowCheckedModeBanner: false,
  12.       home: HalamanPertama(),
  13.     );
  14.   }
  15. }
  16.  
  17. class HalamanPertama extends StatelessWidget {
  18.   @override
  19.   Widget build(BuildContext context) {
  20.     return Scaffold(
  21.       appBar: AppBar(
  22.         title: Text('Halaman Satu'),
  23.       ),
  24.       body: Center(
  25.         child: Column(
  26.           mainAxisAlignment: MainAxisAlignment.center,
  27.           children: [
  28.             Text(
  29.               'INI HALAMAN 1',
  30.               style: TextStyle(
  31.                 fontSize: 20,
  32.                 fontWeight: FontWeight.bold,
  33.                 color: Colors.blue,
  34.               ),
  35.             ),
  36.             SizedBox(height: 35),
  37.             ElevatedButton(
  38.               onPressed: () {
  39.                 //logic ketika tombol di tekan
  40.                 Navigator.push(
  41.                   context,
  42.                   MaterialPageRoute(builder: (context) => HalamanKedua()),
  43.                 );
  44.               },
  45.               child: Text('Pindah Halaman'),
  46.               ),
  47.           ],
  48.         ),
  49.       ),
  50.     );
  51.   }
  52. }
  53.  
  54. class HalamanKedua extends StatelessWidget {
  55.   @override
  56.   Widget build(BuildContext context) {
  57.     return Scaffold(
  58.       appBar: AppBar(
  59.         title: Text('Halaman Dua'),
  60.       ),
  61.       body: Center(
  62.         child: Column(
  63.           mainAxisAlignment: MainAxisAlignment.center,
  64.           children: [
  65.             Text(
  66.               'INI HALAMAN 2',
  67.               style: TextStyle(
  68.                 fontSize: 20,
  69.                 fontWeight: FontWeight.bold,
  70.                 color: Colors.orange,
  71.               ),
  72.             ),
  73.             SizedBox(height: 35),
  74.             ElevatedButton(
  75.               onPressed: () {
  76.                 //logic ketika tombol di tekan
  77.                 Navigator.pop(context);
  78.               },
  79.               child: Text('Kembali'),
  80.               ),
  81.           ],
  82.         ),
  83.       ),
  84.     );
  85.   }
  86. }
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement