df_will_dispose 0.2.0 df_will_dispose: ^0.2.0 copied to clipboard
A package to mark resources for disposal upon definition, simplifying your code.
//.title
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//
// Dart/Flutter (DF) Packages by DevCetra.com & contributors. Use of this
// source code is governed by an MIT-style license that can be found in the
// LICENSE file located in this project's root directory.
//
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//.title~
import 'package:df_will_dispose/df_will_dispose.dart';
import 'package:flutter/material.dart';
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
class MyWidget extends StatefulWidget {
const MyWidget({super.key});
@override
_MyWidgetState createState() => _MyWidgetState();
}
// Option 1: WillDisposeState<MyWidget>.
// Option 2: State<MyWidget> with DisposeMixin, WillDisposeMixin.
class _MyWidgetState extends WillDisposeState<MyWidget> {
// Define and mark resources for disposal on the same line.
late final _textController = willDispose(TextEditingController());
late final _valueNotifier = willDispose(ValueNotifier('Initial Value'));
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('WillDispose Example')),
body: Column(
children: [
TextField(controller: _textController),
ValueListenableBuilder<String>(
valueListenable: _valueNotifier,
builder: (context, value, child) => Text('Value: $value'),
),
ElevatedButton(
onPressed: () {
_valueNotifier.value = 'Updated Value';
},
child: const Text('Update Value'),
),
],
),
);
}
@override
void dispose() {
// Resources marked with `willDispose` will be disposed automatically here.
super.dispose();
}
}
void main() => runApp(const MaterialApp(home: MyWidget()));