Skip to content

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

@YuneshShrestha

Description

@YuneshShrestha

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,
                ),
                
            ),
             ),
           
          ],
    ),
        ),
      ),
  ),
  
);

}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions