import 'package:flutter/material.dart'; void main() => runApp(SnackBarDemo()); // リスト 5.13 class SnackBarDemo extends StatelessWidget { const SnackBarDemo({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp( title: 'SnackBar', home: Scaffold( appBar: AppBar( title: const Text('SnackBar') ), body: const TestPage(), floatingActionButton: FloatingActionButton( onPressed: () {}, child: const Icon(Icons.arrow_forward) ) ) ); } } class TestPage extends StatelessWidget { const TestPage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Center( child: IconButton( icon: Icon(Icons.airplanemode_active), onPressed: () { ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: const Text('機内モードに設定しました'), action: SnackBarAction( label: 'キャンセル', onPressed: () {} ) ) ); } ) ); } }