Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception has occurred. FlutterError (setState() called after dispose(): #21

Closed
YuneshShrestha opened this issue Jul 7, 2020 · 0 comments

Comments

@YuneshShrestha
Copy link

My home.dart:

import 'package:flutter/material.dart';
class Home extends StatefulWidget {
@OverRide
_HomeState createState() => _HomeState();
}

class _HomeState extends State {
Map data={};
dynamic result;
@OverRide
Widget build(BuildContext context) {
data = data.isNotEmpty? data : ModalRoute.of(context).settings.arguments;

return SafeArea(
  child: Scaffold(

      body: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            image: data['isdaytime']? AssetImage('images/day.jpg'): AssetImage('images/night.jpg'),
            fit: BoxFit.cover,
          ),
          
        ),
        child: Padding(
          padding: const EdgeInsets.fromLTRB(0, 80, 0, 0),
          child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            FlatButton(
              onPressed: () async{
               result = await Navigator.pushReplacementNamed(context, '/editlocation');
                if(result!=0){
                  setState(() {
                  data = {
                        'location': result['location'],
                        'flag': result['flag'],
                        'time': result['time'],
                        'isdaytime': result['isdaytime'],
                      };
                });
                    
                }

// Exception has occurred.
// FlutterError (setState() called after dispose():
// if(result!=0){
// print("11");
// data = {
// 'location': result['location'],
// 'flag': result['flag'],
// 'time': result['time'],
// 'isdaytime': result['isdaytime'],
// };
// print(data);
// // setState(() {
// // print("12");
// // data = {
// // 'location': result['location'],
// // 'flag': result['flag'],
// // 'time': result['time'],
// // 'isdaytime': result['isdaytime'],
// // };
// // print(data['location']);
// // });
// }

              }, 
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[

                  Icon(Icons.location_on,color: Colors.white,),
                  SizedBox(width:10.0),
                  Text(
                    "Edit Location",
                    style: TextStyle(
                      color: Colors.white,
                    ),
                  
                  ),
                ],
              ),
             
                              ),
             SizedBox(
               height: 10.0,
             ),
            Center(
              child: Text(data['time'],style: data['isdaytime']? 
              TextStyle(
                fontSize: 40.0,
                letterSpacing: 3.0,
                fontWeight: FontWeight.bold,
              ) : TextStyle(
                fontSize: 40.0,
                letterSpacing: 3.0,
                color: Colors.white,
                fontWeight: FontWeight.bold,
              ),
              
            ),
            ),
             SizedBox(
               height: 10.0,
             ),
             Center(
               child: Text(data['location'],style: data['isdaytime']? 
                TextStyle(
                  fontSize: 30.0,
                  letterSpacing: 3.0,
                  fontStyle: FontStyle.italic,
                ) : TextStyle(
                  fontSize: 30.0,
                  letterSpacing: 3.0,
                  color: Colors.white,
                  fontStyle: FontStyle.italic,
                ),
                
            ),
             ),
           
          ],
    ),
        ),
      ),
  ),
  
);

}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant