//flutter import 'package:flutter/material.dart'; void main() { return runApp(TestPage()); } //リスト4.20 class TestPage extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'ListView', home: Scaffold( appBar: AppBar(title: Text('ListView')), body: HogeListWidget() ) ); } } class HogeListWidget extends StatefulWidget { @override State<HogeListWidget> createState() => _HogeListWidgetState(); } class _HogeListWidgetState extends State<HogeListWidget> { ScrollController? _scrollController; @override void initState() { super.initState(); _scrollController = ScrollController(); _scrollController!.addListener(() { final positionRate = _scrollController!.offset / _scrollController!.position.maxScrollExtent; if (positionRate == 1.0) { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: const Text('1番下です'))); } }); } @override Widget build(BuildContext context) { return ListView( controller: _scrollController, children: List.generate(100, (i) => Text('Item$i')), ); } @override void dispose() { _scrollController?.dispose(); super.dispose(); } }