Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Flutter code sample for AppBar
- // This sample shows an [AppBar] with two simple actions. The first action
- // opens a [SnackBar], while the second action navigates to a new page.
- import 'package:flutter/material.dart';
- void main() => runApp(const MyApp());
- /// This is the main application widget.
- class MyApp extends StatelessWidget {
- const MyApp({Key? key}) : super(key: key);
- static const String _title = 'Flutter Code Sample';
- @override
- Widget build(BuildContext context) {
- return const MaterialApp(
- title: _title,
- home: MyStatelessWidget(),
- );
- }
- }
- /// This is the stateless widget that the main application instantiates.
- class MyStatelessWidget extends StatelessWidget {
- const MyStatelessWidget({Key? key}) : super(key: key);
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: const Text('AppBar Demo'),
- actions: <Widget>[
- IconButton(
- icon: const Icon(Icons.add_alert),
- tooltip: 'Show Snackbar',
- onPressed: () {
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(content: Text('This is a snackbar')));
- },
- ),
- IconButton(
- icon: const Icon(Icons.navigate_next),
- tooltip: 'Go to the next page',
- onPressed: () {
- Navigator.push(context, MaterialPageRoute<void>(
- builder: (BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: const Text('Next page'),
- ),
- body: const Center(
- child: Text(
- 'This is the next page',
- style: TextStyle(fontSize: 24),
- ),
- ),
- );
- },
- ));
- },
- ),
- ],
- ),
- body: const Center(
- child: Text(
- 'This is the home page',
- style: TextStyle(fontSize: 24),
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement