mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
manual fixes: memory leaks due to not disposing
This commit is contained in:
@@ -131,6 +131,16 @@ class _AuthCardState extends State<AuthCard> {
|
||||
text: kDebugMode ? DEFAULT_SERVER_TEST : DEFAULT_SERVER_PROD,
|
||||
);
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_usernameController.dispose();
|
||||
_passwordController.dispose();
|
||||
_password2Controller.dispose();
|
||||
_emailController.dispose();
|
||||
_serverUrlController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
@@ -46,6 +46,13 @@ class _ImageFormState extends State<ImageForm> {
|
||||
final dateController = TextEditingController();
|
||||
final TextEditingController descriptionController = TextEditingController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
dateController.dispose();
|
||||
descriptionController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -190,11 +197,11 @@ class _ImageFormState extends State<ImageForm> {
|
||||
|
||||
if (widget._image.id == null) {
|
||||
Provider.of<GalleryProvider>(context, listen: false)
|
||||
.addImage(widget._image, _file!);
|
||||
.addImage(widget._image, _file!);
|
||||
Navigator.of(context).pop();
|
||||
} else {
|
||||
Provider.of<GalleryProvider>(context, listen: false)
|
||||
.editImage(widget._image, _file);
|
||||
.editImage(widget._image, _file);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -198,6 +198,16 @@ class IngredientFormState extends State<IngredientForm> {
|
||||
_timeController.text = timeToString(TimeOfDay.fromDateTime(now))!;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_ingredientController.dispose();
|
||||
_ingredientIdController.dispose();
|
||||
_amountController.dispose();
|
||||
_dateController.dispose();
|
||||
_timeController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
TextEditingController get ingredientIdController => _ingredientIdController;
|
||||
|
||||
MealItem get mealItem => _mealItem;
|
||||
@@ -232,9 +242,8 @@ class IngredientFormState extends State<IngredientForm> {
|
||||
Widget build(BuildContext context) {
|
||||
final String unit = AppLocalizations.of(context).g;
|
||||
final queryLower = _searchQuery.toLowerCase();
|
||||
final suggestions = widget.recent
|
||||
.where((e) => e.ingredient.name.toLowerCase().contains(queryLower))
|
||||
.toList();
|
||||
final suggestions =
|
||||
widget.recent.where((e) => e.ingredient.name.toLowerCase().contains(queryLower)).toList();
|
||||
return Container(
|
||||
margin: const EdgeInsets.all(20),
|
||||
child: Form(
|
||||
@@ -500,6 +509,13 @@ class _PlanFormState extends State<PlanForm> {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_descriptionController.dispose();
|
||||
colorController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Form(
|
||||
@@ -540,13 +556,13 @@ class _PlanFormState extends State<PlanForm> {
|
||||
child: DropdownButtonFormField<GoalType>(
|
||||
value: _goalType,
|
||||
items: GoalType.values
|
||||
.map(
|
||||
(e) => DropdownMenuItem<GoalType>(
|
||||
value: e,
|
||||
child: Text(e.label),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
.map(
|
||||
(e) => DropdownMenuItem<GoalType>(
|
||||
value: e,
|
||||
child: Text(e.label),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
onChanged: (GoalType? g) {
|
||||
setState(() {
|
||||
if (g == null) {
|
||||
|
||||
@@ -45,6 +45,12 @@ class _UserProfileFormState extends State<UserProfileForm> {
|
||||
emailController.text = widget._profile.email;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
emailController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Form(
|
||||
@@ -102,9 +108,7 @@ class _UserProfileFormState extends State<UserProfileForm> {
|
||||
}
|
||||
|
||||
// Verify
|
||||
await context
|
||||
.read<UserProvider>()
|
||||
.verifyEmail();
|
||||
await context.read<UserProvider>().verifyEmail();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
@@ -125,9 +129,7 @@ class _UserProfileFormState extends State<UserProfileForm> {
|
||||
_form.currentState!.save();
|
||||
|
||||
// Update profile
|
||||
context
|
||||
.read<UserProvider>()
|
||||
.saveProfile();
|
||||
context.read<UserProvider>().saveProfile();
|
||||
Navigator.of(context).pop();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
|
||||
@@ -290,6 +290,12 @@ class _SetFormWidgetState extends State<SetFormWidget> {
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_exercisesController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// Adds an exercise to the current set
|
||||
void addExercise(Exercise base) {
|
||||
setState(() {
|
||||
@@ -336,9 +342,7 @@ class _SetFormWidgetState extends State<SetFormWidget> {
|
||||
min: 1,
|
||||
max: 10,
|
||||
divisions: 10,
|
||||
label: _currentSetSliderValue
|
||||
.round()
|
||||
.toString(),
|
||||
label: _currentSetSliderValue.round().toString(),
|
||||
onChanged: (double value) {
|
||||
setState(() {
|
||||
widget._set.sets = value.round();
|
||||
@@ -439,13 +443,11 @@ class _SetFormWidgetState extends State<SetFormWidget> {
|
||||
if (pattern == '') {
|
||||
return null;
|
||||
}
|
||||
return context
|
||||
.read<ExercisesProvider>()
|
||||
.searchExercise(
|
||||
pattern,
|
||||
languageCode: Localizations.localeOf(context).languageCode,
|
||||
searchEnglish: _searchEnglish,
|
||||
);
|
||||
return context.read<ExercisesProvider>().searchExercise(
|
||||
pattern,
|
||||
languageCode: Localizations.localeOf(context).languageCode,
|
||||
searchEnglish: _searchEnglish,
|
||||
);
|
||||
},
|
||||
itemBuilder: (
|
||||
BuildContext context,
|
||||
@@ -920,8 +922,8 @@ class _WeightUnitInputWidgetState extends State<WeightUnitInputWidget> {
|
||||
});
|
||||
},
|
||||
items: Provider.of<WorkoutPlansProvider>(context, listen: false)
|
||||
.weightUnits
|
||||
.map<DropdownMenuItem<WeightUnit>>((WeightUnit value) {
|
||||
.weightUnits
|
||||
.map<DropdownMenuItem<WeightUnit>>((WeightUnit value) {
|
||||
return DropdownMenuItem<WeightUnit>(
|
||||
key: Key(value.id.toString()),
|
||||
value: value,
|
||||
@@ -962,8 +964,8 @@ class _RepetitionUnitInputWidgetState extends State<RepetitionUnitInputWidget> {
|
||||
});
|
||||
},
|
||||
items: Provider.of<WorkoutPlansProvider>(context, listen: false)
|
||||
.repetitionUnits
|
||||
.map<DropdownMenuItem<RepetitionUnit>>((RepetitionUnit value) {
|
||||
.repetitionUnits
|
||||
.map<DropdownMenuItem<RepetitionUnit>>((RepetitionUnit value) {
|
||||
return DropdownMenuItem<RepetitionUnit>(
|
||||
key: Key(value.id.toString()),
|
||||
value: value,
|
||||
|
||||
@@ -150,7 +150,7 @@ class _GymModeState extends State<GymMode> {
|
||||
...getContent(),
|
||||
SessionPage(
|
||||
Provider.of<WorkoutPlansProvider>(context, listen: false)
|
||||
.findById(widget._workoutDay.workoutId),
|
||||
.findById(widget._workoutDay.workoutId),
|
||||
_controller,
|
||||
widget._start,
|
||||
_exercisePages,
|
||||
@@ -192,9 +192,7 @@ class StartPage extends StatelessWidget {
|
||||
.name,
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
...set
|
||||
.getSmartRepr(s.exerciseObj)
|
||||
.map((e) => Text(e)),
|
||||
...set.getSmartRepr(s.exerciseObj).map((e) => Text(e)),
|
||||
const SizedBox(height: 15),
|
||||
],
|
||||
);
|
||||
@@ -279,6 +277,8 @@ class _LogPageState extends State<LogPage> {
|
||||
@override
|
||||
void dispose() {
|
||||
focusNode.dispose();
|
||||
_repsController.dispose();
|
||||
_weightController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -746,6 +746,15 @@ class _SessionPageState extends State<SessionPage> {
|
||||
_session.date = DateTime.now();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
impressionController.dispose();
|
||||
notesController.dispose();
|
||||
timeStartController.dispose();
|
||||
timeEndController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
@@ -977,10 +986,7 @@ class _TimerWidgetState extends State<TimerWidget> {
|
||||
child: Center(
|
||||
child: Text(
|
||||
DateFormat('m:ss').format(today.add(Duration(seconds: _seconds))),
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.displayLarge!
|
||||
.copyWith(color: wgerPrimaryColor),
|
||||
style: Theme.of(context).textTheme.displayLarge!.copyWith(color: wgerPrimaryColor),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -41,6 +41,12 @@ class WorkoutLogs extends StatefulWidget {
|
||||
class _WorkoutLogsState extends State<WorkoutLogs> {
|
||||
final dayController = TextEditingController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
dayController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
|
||||
Reference in New Issue
Block a user