import 'package:flutter/material.dart'; // リスト 5.1 void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: SamplePage1(), routes: { '/sample_page_1': (context) => SamplePage1(), '/sample_page_2': (context) => SamplePage2(), '/sample_page_3': (context) => SamplePage3() } ); } } // リスト 5.2 class SamplePage1 extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('SamplePage1')), body: Center( child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ IconButton(onPressed: null, icon: Icon(Icons.arrow_back)), Text("SamplePage1"), IconButton( onPressed: () => Navigator.of(context).pushNamed('/sample_page_2'), icon: Icon(Icons.arrow_forward) ) ] ) ) ); } } class SamplePage2 extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('SamplePage2')), body: Center( child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ IconButton( onPressed: () => Navigator.of(context).pop(), icon: Icon(Icons.arrow_back) ), Text('SamplePage2'), IconButton( onPressed: () => Navigator.of(context).pushNamed('/sample_page_3'), icon: Icon(Icons.arrow_forward) ) ] ) ) ); } } class SamplePage3 extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('SamplePage3')), body: Center( child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ IconButton( onPressed: () => Navigator.of(context).pop(), icon: Icon(Icons.arrow_back) ), Text('SamplePage3'), IconButton(onPressed: null, icon: Icon(Icons.arrow_forward)) ] ) ) ); } }