Search code examples
flutterdispose

The predefined dispose function is not available in android studio


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


Solution

  • 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.