I was working in Flutter to make an app and I only want the onboarding screen to be seen once by users. I have watched several videos showing how to do this, but the problem is my home screen will always be the Splash Screen. I am not sure how to use Shared Preferences to have the onboarding screen shown once but to still have the splash screen show every time. I could really use some assistance :).
My code for main.dart:
int? isViewed;
Future <void> main() async {
WidgetsFlutterBinding.ensureInitialized();
final prefs = await SharedPreferences.getInstance();
final showLogin = prefs.getBool('showLogin') ?? false;
Paint.enableDithering = true;
await Firebase.initializeApp();
// This is for our onboarding screen
isViewed = prefs.getInt('onboard');
runApp(MyApp(showLogin: showLogin));
}
class MyApp extends StatelessWidget {
final bool showLogin;
const MyApp({Key? key,
required this.showLogin}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Strength',
debugShowCheckedModeBanner: false,
theme: ThemeData(
appBarTheme: const AppBarTheme(color: Colors.white,
elevation: 0,
brightness: Brightness.light,
iconTheme: IconThemeData(color: Colors.black),
textTheme: TextTheme(headline6: TextStyle(color: Color(0xff888888), fontSize: 18),
)
),),
home: const SplashScreen(),
);
}
}
Chunks of code for my onboarding screen:
class OnboardingScreen extends StatefulWidget {
const OnboardingScreen({Key? key}) : super(key: key);
#override
_OnboardingScreenState createState() => _OnboardingScreenState();
}
class _OnboardingScreenState extends State<OnboardingScreen> {
final controller = PageController();
bool isLastPage = false;
#override
void dispose() {
controller.dispose();
super.dispose();
}
_storeOnboardingInfo() async {
int isViewed = 0;
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setInt('onBoard', isViewed);
}
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
.
.
.
TextButton(
style: TextButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0),
),
primary: Colors.white,
backgroundColor: const Color(0xff31708c),
minimumSize: const Size.fromHeight(60)
),
child: Text(
'Get Started',
style: GoogleFonts.montserrat(
fontSize: 24,
fontWeight: FontWeight.w600),
),
onPressed: () async {
final prefs = await SharedPreferences.getInstance();
prefs.setBool('showLogin', true);
await _storeOnboardingInfo();
Navigator.of(context).pushReplacement(
PageTransition(
type: PageTransitionType.fade,
duration: const Duration(milliseconds: 500),
child: LandingScreen()
)
);
}
)
Code for my Splash screen:
class SplashScreen extends StatefulWidget {
const SplashScreen ({Key? key}) : super(key: key);
#override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> with TickerProviderStateMixin{
late AnimationController _screenController;
#override
void initState() {
super.initState();
_screenController = AnimationController(vsync: this);
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
height: double.infinity,
width: double.infinity,
child: Lottie.asset('assets/lottie/splashScreen.lottie.json',
fit: BoxFit.fill,
controller: _screenController,
onLoaded: (composition) {
_screenController
..duration = composition.duration
..forward().whenComplete(() =>
Navigator.of(context).pushReplacement(
PageTransition(
type: PageTransitionType.fade,
duration: const Duration(milliseconds: 1800),
child: const OnboardingScreen()
)
));
}
)
)
);
}
}
You can check the shared preference value in the Splash Screen and redirect the user to the OnBoardingScreen or LandingScreen.
import 'package:custom_form_field/src/form_screen.dart';
import 'package:flutter/material.dart';
import 'package:lottie/lottie.dart';
import 'package:shared_preferences/shared_preferences.dart';
class SplashScreen extends StatefulWidget {
const SplashScreen({Key? key}) : super(key: key);
#override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen>
with TickerProviderStateMixin {
late AnimationController _screenController;
#override
void initState() {
super.initState();
_screenController = AnimationController(vsync: this);
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
height: double.infinity,
width: double.infinity,
child: Lottie.asset('assets/lottie/splashScreen.lottie.json',
fit: BoxFit.fill,
controller: _screenController, onLoaded: (composition) {
_screenController
..duration = composition.duration
..forward().whenComplete(() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
// check shared preference and show particular screen
});
})));
}
}
You can check the shared preference value at initState and do the logic after animation complete as well. Also you can check login state from shared preference here and show login page if needed.
Make a global variable :
Global.dart
library my_prj.globals;
bool newUser = true;
main.dart
globals.newUser == true ? LandingPage() : LoginPage()
signup.dart
Here i am passing the variable
globals.newUser = false;
along with Username or Password fields.
After then your value will be permanently set false until and unless you make a change on it.
Related
I want to write code that directs the user to a welcome page if it's the first time the app is being run. After the user logs in, any subsequent launches of the app direct the user to log in, skipping the welcome page. It seems that when I try to set the value of my key upon logging in, it's not changing, because after logging in, closing the app and launching it again it's still going to the welcome page. How do I fix this? I'm not sure whether the issue is with the initialisation or the setting of the value upon login.
Here's the initialisation of my app:
import 'package:screens/welcomepages/signup_or_login.dart';
import 'package:screens/welcomepages/welcome.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:config/theme.dart';
import 'package:shared_preferences/shared_preferences.dart';
Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarBrightness: Brightness.dark));
runApp(MyApp(prefs: await _prefs));
}
class MyApp extends StatefulWidget {
const MyApp({Key? key, this.title, required this.prefs})
: super(key: key);
final String? title;
final SharedPreferences prefs;
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late SharedPreferences prefs;
#override
void initState() {
super.initState();
initializePreference();
}
Future<void> initializePreference() async {
prefs = await SharedPreferences.getInstance();
setState(() {
prefs.setBool("hasLoggedIn", false);
});
}
#override
Widget build(BuildContext context) {
if (prefs.getBool("hasLoggedIn") == false) {
return MaterialApp(
theme: theme(),
debugShowCheckedModeBanner: false,
home: Welcome(prefs: prefs),
);
}
return MaterialApp(
theme: theme(),
debugShowCheckedModeBanner: false,
home: SignUpOrLogIn(prefs: prefs),
);
}
}
And here's the relevant parts of my log in page
import 'package:services/auth/auth_service.dart';
import 'package:widgets/text_fields_widgets/email_textfield.dart';
import 'package:widgets/text_fields_widgets/password_textfeild.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class Login extends StatefulWidget {
const Login({Key? key, required this.prefs}) : super(key: key);
final SharedPreferences prefs;
#override
_LoginState createState() => _LoginState(prefs);
}
class _LoginState extends State<Login> {
late final SharedPreferences prefs;
_LoginState(SharedPreferences prefs);
Future<void> initializePreference() async {
prefs = await SharedPreferences.getInstance();
}
#override
void initState() {
super.initState();
initializePreference().whenComplete(() {
setState(() {
prefs.getBool("isFirstRun");
});
});
}
#override
Widget build(BuildContext context) {
Material btnLogin = loginBTN(context);
return Scaffold(
.....
Padding(
padding: const EdgeInsets.all(8.0),
child: btnLogin,
)
}
Material loginBTN(BuildContext context) {
// ignore: unused_local_variable
final btnLogin = Material(
elevation: 5,
borderRadius: BorderRadius.circular(30),
color: Theme.of(context).primaryColor,
child: MaterialButton(
padding: const EdgeInsets.fromLTRB(20, 15, 20, 15),
minWidth: MediaQuery.of(context).size.width,
onPressed: () async {
setState(() {
prefs.setBool("hasLoggedIn", true);
});
setState(
() => loadingAnimation = true,
);
await Future.delayed(const Duration(seconds: 1));
setState(
() => loadingAnimation = false,
);
await Authservice().logInMethod(
emailController.text, passwordController.text, context, _formKey);
},
child: loadingAnimation
? const CircularProgressIndicator(
color: Colors.white,
)
: const Text(
"Log in",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 24, color: Colors.white),
),
),
);
return btnLogin;
}
}
Sorry for how lengthy this is, tried to shorten it to only provide what's relevant.
Your are calling initializePreference() inside initState() and that function set hasLoggedIn to false. So even if you set it to true in your login page, when restarting the app it will be set again to false.
Try this brother
if (prefs.getBool("hasLoggedIn") == null || prefs.getBool("hasLoggedIn") == false) {
return MaterialApp(
theme: theme(),
debugShowCheckedModeBanner: false,
home: Welcome(prefs: prefs),
);
}
I am new to flutter and am kinda lost on how to set up a time to my splash screen so after this time it goes to the main screen. am using rive for the splash screen
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
void main() {
runApp(const MaterialApp(home: SimpleAnimation()));
}
class SimpleAnimation extends StatelessWidget {
const SimpleAnimation({Key? key, this.loading}) : super(key: key);
final bool? loading;
#override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(
child: RiveAnimation.asset('assets/splash/splash.riv',
fit: BoxFit.cover)
),
);
}
}
You can set 3 second time in initstate after navigate to which screen you want
class SplashScreen extends StatefulWidget {
const SplashScreen({Key? key}) : super(key: key);
#override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
#override
void initState() {
// TODO: implement initState
super.initState();
// after 3 second it will navigate
Future.delayed(const Duration(seconds: 3)).then((val) {
// Navigation Here
});
}
#override
Widget build(BuildContext context) {
return const Scaffold(
// your code
);
}
}
#override
void initState() {
//set timer for splash screen
Timer(const Duration(seconds: 4), () async {
//add your logic here
Navigator.pushNamedAndRemoveUntil(
context, ScreenRoute.mainScreen, (route) => false);
super.initState();
}
This SimpleAnimation widget shows after the splash screen. While this is StatelessWidget widget, you can define method inside build method. Change Duration(seconds: 2) based on your need.
class SimpleAnimation extends StatelessWidget {
const SimpleAnimation({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
Future.delayed(const Duration(seconds: 2)).then((value) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const NextScreen(),
));
});
return const Scaffold(
body: Center(
As folks already mentioned the straighforward way would be to add a delay and do navigation after it:
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Flutter Demo',
home: SplashScreen(),
);
}
}
class SplashScreen extends StatefulWidget {
const SplashScreen({Key? key}) : super(key: key);
#override
State<SplashScreen> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
#override
void initState() {
super.initState();
Future.delayed(const Duration(seconds: 2), () {
if (mounted) {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => const MainScreen(),
),
);
}
});
}
#override
Widget build(BuildContext context) {
return const ColoredBox(color: Colors.green);
}
}
class MainScreen extends StatelessWidget {
const MainScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return const ColoredBox(color: Colors.yellow);
}
}
Though, with this implementation, you'll have to depend on the animation length. So when you'll update animation - you'll have not to forget to update it inside the splash screen. A more reliable (and complex) solution would be to listen to the animation status and do the navigation after the animation finishes. Like this (warning, change ):
class PlayOneShotAnimation extends StatefulWidget {
const PlayOneShotAnimation({Key? key}) : super(key: key);
#override
_PlayOneShotAnimationState createState() => _PlayOneShotAnimationState();
}
class _PlayOneShotAnimationState extends State<PlayOneShotAnimation> {
late RiveAnimationController _controller;
#override
void initState() {
super.initState();
_controller = OneShotAnimation(
'bounce',
autoplay: true,
onStop: () {
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (context) => const MainScreen(),
),
);
},
);
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: RiveAnimation.network(
'https://cdn.rive.app/animations/vehicles.riv',
animations: const ['idle', 'curves'],
controllers: [_controller],
),
),
);
}
}
class MainScreen extends StatelessWidget {
const MainScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return const ColoredBox(color: Colors.yellow);
}
}
This is my approach for splash screen, the advantage of this approach is to make sure that the splash screen launch only once when the app starting.
First define a static bool in app home class to indicate the app launch.
static bool launch = true;
Then at the home attribute in your MaterialApp widget at app home class, check if (launch) is true use a FutureBuilder to launch the splash screen, if (launch) is false set home to your second screen. With FutureBuilder you can set a timer for your splash screen, when it done your second screen will start (credit to https://stackoverflow.com/a/68699447/11619215).
home: launch? FutureBuilder(
future: Future.delayed(const Duration(seconds: 3)),
builder: (ctx, timer) =>
timer.connectionState == ConnectionState.done
? const SecondScreen(title: 'Flutter Demo Home Page')
: appSplashScreen(),
): const SecondScreen(title: 'Flutter Demo Home Page'),
In the Second screen, check if (launch) is true then set it to false. This will make sure that the splash screen will only launch once each time your application start.
if(AppHome.launch) {
AppHome.launch = false;
}
Below is the full code with appSplashScreen widget at the bottom:
import 'package:flutter/material.dart';
void main() {
runApp(const AppHome());
}
class AppHome extends StatelessWidget {
const AppHome({Key? key}) : super(key: key);
//static bool to indicate the launching of the app
static bool launch = true;
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: launch? FutureBuilder(
future: Future.delayed(const Duration(seconds: 3)),
builder: (ctx, timer) =>
timer.connectionState == ConnectionState.done
? const SecondScreen(title: 'Flutter Demo Home Page')
: appSplashScreen(),
): const SecondScreen(title: 'Flutter Demo Home Page'),
);
}
}
class SecondScreen extends StatefulWidget {
const SecondScreen({Key? key, required this.title}) : super(key: key);
final String title;
#override
State<SecondScreen> createState() => _SecondScreenState();
}
class _SecondScreenState extends State<SecondScreen> {
#override
Widget build(BuildContext context) {
//mack sure your splash screen only launch once at your app starting
if(AppHome.launch) {
AppHome.launch = false;
}
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: const Center(
child: Text(
'My Second screen',
),
),
);
}
}
Widget appSplashScreen() {
return Container(
decoration: const BoxDecoration(
////you can add background image/color to your splash screen
// image: DecorationImage(
// image: AssetImage('assets/background.png'),
// fit: BoxFit.cover,
// ),
color: Colors.white,
),
child: Center(
child: SizedBox(
//get MediaQuery from instance of window to get height and width (no need of context)
height: MediaQueryData.fromWindow(WidgetsBinding.instance.window).size.height*0.5,
width: MediaQueryData.fromWindow(WidgetsBinding.instance.window).size.width*0.5,
child: Column(
children: const [
////you can add image to your splash screen
// Image(
// image: AssetImage('assets/splashscreen_image.png'),
// ),
FittedBox(
child: Text(
'Loading',
textAlign: TextAlign.center,
style: TextStyle(
decoration: TextDecoration.none,
),
)
),
CircularProgressIndicator(),
],
),
),
),
);
}
What i want?
I want to do simple animation with this image.
What does it mean?
If i click on it, it should make smooth for example bounce in animation. Im open in ways through which we can achieve this effect.
What i tried?
I thought AnimatedContainer will get done but curve: parameter is not doing anything.
ps. I am beginner
import 'package:google_fonts/google_fonts.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Poppy App',
theme: ThemeData(
primarySwatch: Colors.brown,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({
Key? key,
}) : super(key: key);
#override
State<MyHomePage> createState() => _MyHomePageState();
}
double _imgwidth = 200;
double _imgheight = 200;
class _MyHomePageState extends State<MyHomePage> {
void poopAnimationIn() async {
setState(() {
_imgheight = 300;
_imgwidth = 300;
});
await Future.delayed(const Duration(milliseconds: 500), () {
setState(() {
_imgheight = 200;
_imgwidth = 200;
});
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: const Color.fromARGB(164, 117, 81, 1),
child: Center(
child: GestureDetector(
onTap: () {
poopAnimationIn();
},
child: AnimatedContainer(
curve: Curves.bounceIn,
duration: const Duration(milliseconds: 200),
child: Image.network(
'https://picsum.photos/250?image=9',
width: _imgwidth,
height: _imgheight,
)),
),
),
));
}
}
You need to specify the size for AnimatedContainer and change that size in setState.
Here is the edited code:
I suggest you use other curves like easeIn instead of bounceIn to have a smoother animation
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Poppy App',
theme: ThemeData(
primarySwatch: Colors.brown,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({
Key? key,
}) : super(key: key);
#override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
double initialHeight = 200;
double initialImageHeight = initialHeight;
double expandedImageHeight = 300;
void poopAnimationIn() async {
setState(() {
initialImageHeight = expandedImageHeight;
});
await Future.delayed(const Duration(milliseconds: 500), () {
setState(() {
initialImageHeight = initialHeight;
});
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: const Color.fromARGB(164, 117, 81, 1),
child: Center(
child: GestureDetector(
onTap: () async {
poopAnimationIn();
},
child: AnimatedContainer(
height: initialImageHeight,
curve: Curves.bounceIn,
duration: const Duration(milliseconds: 200),
child: Image.network(
'https://picsum.photos/250?image=9',
// width: _imgwidth,
// height: _imgheight,
))),
),
),
// ),
);
}
}
I'm using Shared Preferences in flutter , but it not working with me in vs code and andriod studio , after adding dependencies and import the package then try the app nothing happen when clicking on the button which it do the function.
------- this my code in home page --------
import 'package:flutter/material.dart';
import 'package:flutter_application_2/another_screen.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'another_screen.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Shared Preference',
theme: ThemeData(primarySwatch: Colors.blue),
home: const MyHomePage(title: 'Shared Preference'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
#override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
void initState() {
super.initState();
setData();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: ElevatedButton(
child: const Text('Go Another Screen'),
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (_) => const AnotherScreen(),
));
},
),
),
);
}
setData() async {
SharedPreferences _pref = await SharedPreferences.getInstance();
_pref.setString('name', 'Rady');
_pref.setInt('age', 19);
_pref.setString('university', 'Rady');
_pref.setInt('height', 19);
_pref.setStringList('skills', ['Dart', 'Flutter']);
}
}
----- the second page ------
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class AnotherScreen extends StatefulWidget {
const AnotherScreen({Key? key}) : super(key: key);
#override
State<StatefulWidget> createState() => AnotherScreenState();
}
class AnotherScreenState extends State<AnotherScreen> {
String _name = '';
int? _age;
String _university = '';
int? _height;
List<String> _skills = ['', ''];
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Info Screen'),
),
body: DefaultTextStyle(
style: const TextStyle(
fontSize: 30, fontWeight: FontWeight.bold, color: Colors.black),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Name : $_name'),
Text('Age : $_age'),
Text('University : $_university'),
Text('Height : $_height'),
Text('Skill1 : ${_skills[0]}'),
Text('Skill2 : ${_skills[1]}'),
ElevatedButton(
child: const Text('Get Data'),
onPressed: () async {
await getData();
},
)
],
),
),
),
);
}
getData() async {
SharedPreferences _pref = await SharedPreferences.getInstance();
setState(() {
_name = _pref.getString('name')!;
_age = _pref.getInt('age');
_university = _pref.getString('university')!;
_height = _pref.getInt('height');
_skills = _pref.getStringList('skills')!;
});
}
}
Storing Data in shared preferences requires the await keyword
SharedPreferences _prefs = await SharedPreferences.getInstance();
await _prefs.setString('token', newToken);
I Have Try to run my Flutter app using SplashScreen but when I back to drawer of App When it gives the error like : _SpinnerTextState#9863f(ticker active) was disposed with an active Ticker
I Used animated_splash_screen package for splash screen. When I back to my drawer that time screen just give the black color within microsecond and console gives the error
import 'package:animated_splash_screen/animated_splash_screen.dart';
import 'package:page_transition/page_transition.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'login/login.dart';
import 'pages/dashboard.dart';
import 'pages/drawer.dart';
var username;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
SharedPreferences prefs = await SharedPreferences.getInstance();
username = prefs.getString('username');
runApp(
MyApp(),
);
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: MasterScreen(),
);
}
}
class MasterScreen extends StatefulWidget {
#override
final AppBar appBar;
const MasterScreen({Key key, this.appBar}) : super(key: key);
#override
_MasterScreenState createState() => _MasterScreenState();
}
class _MasterScreenState extends State<MasterScreen> with SingleTickerProviderStateMixin {
AnimationController animationController;
Animation<double> animation;
var _visible = true;
#override
void initState() {
super.initState();
animationController = new AnimationController(
vsync: this,
duration: new Duration(seconds: 2),
);
animation =
new CurvedAnimation(parent: animationController, curve: Curves.easeOut);
animation.addListener(() => this.setState(() {}));
animationController.forward();
setState(() {
_visible = !_visible;
});
}
#override
dispose() {
animationController.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
return Scaffold(
home:AnimatedSplashScreen(
curve: Curves.bounceIn,
splash: Image.asset(
'assets/logo.png',
height: 200,
width: 200,
),
nextScreen: username == null
? LoginScreen()
: AppDrawer(
child: DashBoard(
appBar: widget.appBar,
),
),
splashTransition: SplashTransition.scaleTransition,
pageTransitionType: PageTransitionType.leftToRightWithFade,
backgroundColor: Colors.blue,
animationDuration: Duration(
seconds: 2,
),
),
);
}
}
In above code AnimatedSplashScreen package is replace by simple SplashScreen package and we find the splash screen package here splash screen package here
SplashScreen(
backgroundColor: Colors.blue,
seconds: 5,
navigateAfterSeconds: LoginScreen(),
image: new Image.asset(
'assets/logo.png',
),
styleTextUnderTheLoader: new TextStyle(),
photoSize: 150.0,
loaderColor: Colors.white,
loadingText: Text(
'Welcome To QA Platform',
style: TextStyle(
color: Colors.white,
fontSize: 20,
),
),
),