I am trying to implement a walkthrough screen to be displayed when the system is first started.
The shared_preference package is used in initState to determine if it is the first time it is started.
When I execute the following code (simplified), it transitions to the waklThrou screen, but the home screen is displayed for a moment.
Do you have any good ideas?
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutterapp/ui/pages/walk/walk_through_page.dart';
import 'package:shared_preferences/shared_preferences.dart';
class RootPage extends StatefulWidget {
@override
_RootPageState createState() => _RootPageState();
}
class _RootPageState extends State<RootPage> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) async {
final prefs = await SharedPreferences.getInstance();
if (prefs.getBool('isFirstLaunch') ?? true) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => WalkThroughPage()),
);
}
});
}
@override
Widget build(BuildContext context) {
return Consumer(
builder: (ctx, watch, _) {
return WillPopScope(
onWillPop: () async => false,
child: Scaffold(
appBar: AppBar(),
body: Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: AssetImage('images/back_ground.png'),
fit: BoxFit.cover,
),
),
child: Center(child: Text('Home')),
),
));
},
);
}
}