Issue
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,
),
),
);
}
}
Solution
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,
),
),
),
Answered By - Ravindra S. Patil
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.