1

this question similar on flutter error: This widget has been unmounted, so the State no longer has a context (and should be considered defunct) flutter

i have two stateFullWidget

  1. PersonScreen
  2. _HandScreen

where in PersonScreen i have Column

...
PersonScreen

children [
Text('Hand'),
_HandScreen()
]

and then in HandScreen i have DragTarget

DragTarget<String>(
            onAccept: (value) async {
              print('value $value');
              await onAccept(value);
            },
...
onAccept(value) async {
//   i tried to open view alert or automatically navigator into any screen
try {
Alert(
          context: context,
          title: 'Finished!',
          desc: 'You\'ve reached ',
          image:Lottie.asset(
                  'assets/lotties/completed-check.json',
                  height: 85.0,
                  width: 85.0,
                ),
          buttons: [
            DialogButton(
              child: Text(
                "Selesai",
                style: TextStyle(color: Colors.white, fontSize: 20),
              ),
              onPressed: () => Navigator.of(context, rootNavigator: true).pop(),
              color: Color.fromRGBO(0, 179, 134, 1.0),
            ),
          ],
        ).show();
} catch(e) {
print('error = $e'); // this throw This widget has been unmounted, so the State no longer has a context (and should be considered defunct)
}
}

but when i tried drag an item against (x2) into accept event, the alert can view or open. i have change the instead of Alert with Navigator.pushNamed(context, MainScreen.id); the error is same.

i have tried with one stateFullWidget its look normal on running , but how i can handle it with two stateFullWidget , its posible ? because a lot of code in _HandScreen, i dont want to wrap into PersonScreen. by the way i use Provider instead of setState.

Yogi Arif Widodo
  • 563
  • 6
  • 22

0 Answers0