diff --git a/lib/main_pageview_test.dart b/lib/main_pageview_test.dart new file mode 100644 index 0000000..bd5748a --- /dev/null +++ b/lib/main_pageview_test.dart @@ -0,0 +1,94 @@ +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; + +void main() { + runApp(MyApp()); +} + +class MyApp extends StatefulWidget { + @override + State createState() => MyAppState(); +} + +class MyAppState extends State { + int parentCounter = 10; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Flutter Demo', + theme: ThemeData( + primarySwatch: Colors.blue, + ), + scrollBehavior: MaterialScrollBehavior().copyWith( + dragDevices: { + PointerDeviceKind.mouse, + PointerDeviceKind.touch, + PointerDeviceKind.stylus, + PointerDeviceKind.unknown + }, + ), + home: Scaffold( + body: PageView( + physics: AlwaysScrollableScrollPhysics(), + controller: PageController(viewportFraction: 0.8), + children: [ + CounterPage(), + CounterPage(), + CounterPage(), // Add as many pages as you want + ], + ), + ), + ); + } +} + +class CounterPage extends StatefulWidget { + @override + _CounterPageState createState() => _CounterPageState(); +} + +class _CounterPageState extends State { + int _counter = 0; + + void _incrementCounter() { + setState(() { + _counter++; + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('Counter Page'), + ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + 'Parent Counter: ${context.findAncestorStateOfType()?.parentCounter}'), + ElevatedButton( + onPressed: () { + context + .findAncestorStateOfType() + ?.parentCounter += 1; + context + .findAncestorStateOfType() + ?.setState(() {}); + }, + child: Text('Increment Parent Counter')), + Text('You have pushed the button this many times:'), + Text('$_counter', style: Theme.of(context).textTheme.headline4), + ], + ), + ), + floatingActionButton: FloatingActionButton( + onPressed: _incrementCounter, + tooltip: 'Increment', + child: Icon(Icons.add), + ), + ); + } +}