diff --git a/lib/main_pageview_test.dart b/lib/main_pageview_test.dart index bd5748a..aab2b7b 100644 --- a/lib/main_pageview_test.dart +++ b/lib/main_pageview_test.dart @@ -33,9 +33,7 @@ class MyAppState extends State { physics: AlwaysScrollableScrollPhysics(), controller: PageController(viewportFraction: 0.8), children: [ - CounterPage(), - CounterPage(), - CounterPage(), // Add as many pages as you want + for (int i = 0; i < 10; i++) CounterPage(), ], ), ), @@ -44,11 +42,14 @@ class MyAppState extends State { } class CounterPage extends StatefulWidget { + CounterPage({Key? key}) : super(key: key); + @override _CounterPageState createState() => _CounterPageState(); } -class _CounterPageState extends State { +class _CounterPageState extends State + with AutomaticKeepAliveClientMixin { int _counter = 0; void _incrementCounter() { @@ -91,4 +92,7 @@ class _CounterPageState extends State { ), ); } + + @override + bool get wantKeepAlive => true; }