rajath_pai

AppBar button with toast

Aug 3rd, 2021
996
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// Flutter code sample for AppBar
  2.  
  3. // This sample shows an [AppBar] with two simple actions. The first action
  4. // opens a [SnackBar], while the second action navigates to a new page.
  5.  
  6. import 'package:flutter/material.dart';
  7.  
  8. void main() => runApp(const MyApp());
  9.  
  10. /// This is the main application widget.
  11. class MyApp extends StatelessWidget {
  12.   const MyApp({Key? key}) : super(key: key);
  13.  
  14.   static const String _title = 'Flutter Code Sample';
  15.  
  16.   @override
  17.   Widget build(BuildContext context) {
  18.     return const MaterialApp(
  19.       title: _title,
  20.       home: MyStatelessWidget(),
  21.     );
  22.   }
  23. }
  24.  
  25. /// This is the stateless widget that the main application instantiates.
  26. class MyStatelessWidget extends StatelessWidget {
  27.   const MyStatelessWidget({Key? key}) : super(key: key);
  28.  
  29.   @override
  30.   Widget build(BuildContext context) {
  31.     return Scaffold(
  32.       appBar: AppBar(
  33.         title: const Text('AppBar Demo'),
  34.         actions: <Widget>[
  35.           IconButton(
  36.             icon: const Icon(Icons.add_alert),
  37.             tooltip: 'Show Snackbar',
  38.             onPressed: () {
  39.               ScaffoldMessenger.of(context).showSnackBar(
  40.                   const SnackBar(content: Text('This is a snackbar')));
  41.             },
  42.           ),
  43.           IconButton(
  44.             icon: const Icon(Icons.navigate_next),
  45.             tooltip: 'Go to the next page',
  46.             onPressed: () {
  47.               Navigator.push(context, MaterialPageRoute<void>(
  48.                 builder: (BuildContext context) {
  49.                   return Scaffold(
  50.                     appBar: AppBar(
  51.                       title: const Text('Next page'),
  52.                     ),
  53.                     body: const Center(
  54.                       child: Text(
  55.                         'This is the next page',
  56.                         style: TextStyle(fontSize: 24),
  57.                       ),
  58.                     ),
  59.                   );
  60.                 },
  61.               ));
  62.             },
  63.           ),
  64.         ],
  65.       ),
  66.       body: const Center(
  67.         child: Text(
  68.           'This is the home page',
  69.           style: TextStyle(fontSize: 24),
  70.         ),
  71.       ),
  72.     );
  73.   }
  74. }
  75.  
RAW Paste Data