I have this error when I try to load Animation Controller. This problem shows when I changed my SDK 2.15.0 to 2.7.0. Red line in "vsync: this" This is my code:
main.dart
class SplashScreenState extends State<SplashScreen>
with SingleTickerProviderStateMixin {
final AnimationController _animationController = AnimationController(
vsync: this, duration: const Duration(milliseconds: 500));
String _connectionStatus = 'unKnown';
final Connectivity _connectivity = Connectivity();
StreamSubscription<ConnectivityResult> connectivitySubscription;
Future<void> _initPackageInfo() async {
final info = await PackageInfo.fromPlatform();
setState(() {
packageInfo = info;
});
}
SplashScreen.dart
AnimationController animationController = AnimationController(
vsync: this, duration: const Duration(milliseconds: 5));
the error is vsync: this. Red line.
CodePudding user response:
Just insert a late
before assigning a final variable like this:
late final AnimationController _animationController = AnimationController(
vsync: this, duration: const Duration(milliseconds: 500));
If you need explanation, comment below.