Add a page turn effect to widgets in your app.
This will add a line like this to your package’s pubspec.yaml (and run an implicit dart pub get
):
dependencies:
page_turn: ^1.0.1
Now in your Dart code, you can use:
import 'package:page_turn/page_turn.dart';
- Create “controller” as
_controller
:
final _controller = GlobalKey<PageTurnState>();
2. Use “PageTurn” widget :
Example
import 'package:flutter/material.dart';import 'package:page_turn/page_turn.dart';import '../common/index.dart';class HomeScreen extends StatefulWidget {
const HomeScreen({
Key key,
}) : super(key: key); @override
_HomeScreenState createState() => _HomeScreenState();
}class _HomeScreenState extends State<HomeScreen> {
final _controller = GlobalKey<PageTurnState>();
@override
Widget build(BuildContext context) {
return Scaffold(
body: PageTurn(
key: _controller,
backgroundColor: Colors.white,
showDragCutoff: false,
lastPage: Container(child: Center(child: Text('Last Page!'))),
children: <Widget>[
for (var i = 0; i < 20; i++) AlicePage(page: i),
],
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.search),
onPressed: () {
_controller.currentState.goToPage(2);
},
),
);
}
}
was explained by Söhrab Vahidli.