import 'package:flutter/material.dart';
// リスト 5.3
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(home: SamplePage1());
}
}
// リスト 5.4
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.push(
context,
MaterialPageRoute<void>(
builder: (context) => SamplePage2()
)
),
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.push(
context,
MaterialPageRoute<void>(
builder: (context) => SamplePage3()
)
),
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))
]
)
)
);
}
}