animated_splash
animated_splash copied to clipboard
Problem loading screen
Good afternoon,
First of all, congratulations on the plugin, very good idea.
I have a problem; Calling my class is generating the following error:
Looking up a deactivated widget's ancestor is unsafe. E / flutter (2844): At this point the state of the widget's element tree is no longer stable. E / flutter (2844): To safely refer to a widget's ancestor in its dispose () method, save a reference to its ancestor by calling inheritFromWidgetOfExactType () in the widget's didChangeDependencies () method.
This error is generated when calling screen after Splash Screen.
Should I configure something in my class not to generate such a problem, or this is really a plugin problem.
Thanks.
Hi, Good morning, can you drop the code actually you are trying to execute here!
Here is a code that generate the error (excuse me if it's too long, but it's fully functional) :
import 'package:flutter/material.dart'; import 'package:rflutter_alert/rflutter_alert.dart'; import 'dart:math'; import 'package:animated_splash/animated_splash.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { final Function duringSplash = () { int rnd = Random().nextInt(10); print('rnd $rnd'); return rnd op = {1: MainScreen(), 2: DummyScreen()}; @override Widget build(BuildContext context) { return MaterialApp( home: AnimatedSplash( imagePath: 'assets/images/Banner-BooksRoom-mobile.png', home: MainScreen(), customFunction: duringSplash, duration: 5000, type: AnimatedSplashType.BackgroundProcess, outputAndHome: op, ), ); } } class MainScreen extends StatefulWidget { @override _MainScreenState createState() => _MainScreenState(); } class _MainScreenState extends State{ TextEditingController usernameController = TextEditingController(); TextEditingController passwordController = TextEditingController(); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("BooksRoom.it"), leading: Icon(Icons.menu), backgroundColor: Colors.amber[700], ), body: Center( child: Padding( padding: const EdgeInsets.symmetric(horizontal: 40.0), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ TextField( controller: usernameController, keyboardType: TextInputType.emailAddress, decoration: InputDecoration( floatingLabelBehavior: FloatingLabelBehavior.auto, labelText: 'Email'), ), const SizedBox(height: 30), TextField( controller: passwordController, keyboardType: TextInputType.text, obscureText: true, decoration: InputDecoration( floatingLabelBehavior: FloatingLabelBehavior.auto, labelText: 'Password'), ), const SizedBox(height: 30), Row( children: [ Expanded( child: RaisedButton( child: Text( 'Accedi', style: TextStyle( fontSize: 20.0, fontWeight: FontWeight.bold, color: Colors.white, ), ), color: Colors.blueAccent, padding: EdgeInsets.symmetric(vertical: 20.0), onPressed: () { if (usernameController.text.isEmpty || passwordController.text.isEmpty) { Alert( context: context, type: AlertType.error, title: 'Attenzione!', desc: 'Tutti i campi sono obbligatori!', buttons: [ DialogButton( child: Text('OK'), onPressed: () { Navigator.pop(context); }) ], ).show(); } else { Alert( context: context, type: AlertType.info, title: 'Attenzione!', desc: 'username = ${usernameController.text}\npassword = ${passwordController.text}', buttons: [ DialogButton( child: Text('OK'), onPressed: () { Navigator.pop(context); }) ], ).show(); } }, ), ), ], ) ], ), ), ), ); } } class DummyScreen extends StatelessWidget { @override Widget build(BuildContext context) { return SafeArea( child: Container( color: Colors.teal, child: Center( child: Text('Dummy Screen', style: TextStyle( color: Colors.yellow, fontSize: 40, fontWeight: FontWeight.bold)), ), ), ); } }
Thanks in advance
Hi @ferdinandocecchini , I will look into it. Thanks
Getting the same error.
E/flutter (23831): [ERROR:flutter/shell/common/shell.cc(213)] Dart Error: Unhandled exception: E/flutter (23831): Looking up a deactivated widget's ancestor is unsafe. E/flutter (23831): At this point the state of the widget's element tree is no longer stable. E/flutter (23831): To safely refer to a widget's ancestor in its dispose() method, save a refe