Home > front end >  The predefined dispose function is not available in android studio
The predefined dispose function is not available in android studio

Time:12-14

i am creating a connection between my flutter application and firebase but when the time came to use the dispose function it is not defined

i've added the package as a library to the flutter and dart

dart pub add dispose
flutter pub add dispose

then i import the package in my class using :

import 'package:dispose/dispose.dart';

but nothing happedned also and the functon still undefined the packages that i've added

CodePudding user response:

Did you mean to use this instead?

@override
void dispose() {
  yourStream.cancel(); //Cancel your subscription here.
  super.dispose();
}

CodePudding user response:

The dispose() method is only available in Stateful widgets, convert your widget into a Stateful widget and it should let you use it as normal. This is always required if you use Controllers or Listeners to properly dispose them.

  • Related