Skip to content

Commit

Permalink
fix: Added Controllers Dispose methods (#1383)
Browse files Browse the repository at this point in the history
  • Loading branch information
DGoiana authored Nov 29, 2024
2 parents 2d7697d + e904194 commit cb285d9
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 4 deletions.
8 changes: 8 additions & 0 deletions packages/uni_app/lib/view/bug_report/widgets/form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,12 @@ class BugReportFormState extends State<BugReportForm> {
_isConsentGiven = false;
});
}

@override
void dispose() {
titleController.dispose();
descriptionController.dispose();
emailController.dispose();
super.dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class LastUpdateTimeStamp<T extends StateProviderNotifier<dynamic>>
class _LastUpdateTimeStampState<T extends StateProviderNotifier<dynamic>>
extends State<StatefulWidget> {
DateTime currentTime = DateTime.now();

Timer? timer;
@override
void initState() {
super.initState();
Timer.periodic(
timer = Timer.periodic(
const Duration(seconds: 60),
(timer) {
if (mounted) {
Expand All @@ -34,6 +34,12 @@ class _LastUpdateTimeStampState<T extends StateProviderNotifier<dynamic>>
);
}

@override
void dispose() {
timer?.cancel();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Consumer<T>(
Expand Down
6 changes: 6 additions & 0 deletions packages/uni_app/lib/view/locations/locations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class LocationsPageState extends SecondaryPageViewState
@override
String? getTitle() =>
S.of(context).nav_title(NavigationItem.navLocations.route);

@override
void dispose() {
scrollViewController?.dispose();
super.dispose();
}
}

class LocationsPageView extends StatefulWidget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@ class _RestaurantPageViewState extends GeneralPageViewState<RestaurantPageView>
void initState() {
super.initState();
final weekDay = DateTime.now().weekday;
super.initState();
tabController = TabController(vsync: this, length: DayOfWeek.values.length);
tabController.animateTo(tabController.index + (weekDay - 1));
scrollViewController = ScrollController();
}

@override
void dispose() {
tabController.dispose();
scrollViewController.dispose();
super.dispose();
}

@override
String? getTitle() =>
S.of(context).nav_title(NavigationItem.navRestaurants.route);
Expand Down
8 changes: 8 additions & 0 deletions packages/uni_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.28.0"
scrollable_positioned_list:
dependency: transitive
description:
name: scrollable_positioned_list
sha256: "1b54d5f1329a1e263269abc9e2543d90806131aa14fe7c6062a8054d57249287"
url: "https://pub.dev"
source: hosted
version: "0.3.8"
sentry:
dependency: transitive
description:
Expand Down
8 changes: 7 additions & 1 deletion packages/uni_ui/lib/timeline/timeline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ class _TimelineState extends State<Timeline> {
});
}

@override
void dispose() {
_tabScrollController.dispose();
super.dispose();
}

void _onTabTapped(int index) {
_itemScrollController.scrollTo(
index: index,
Expand Down Expand Up @@ -123,7 +129,7 @@ class _TimelineState extends State<Timeline> {
child: ScrollablePositionedList.builder(
itemCount: widget.content.length,
itemScrollController: _itemScrollController,
itemPositionsListener: _itemPositionsListener,
itemPositionsListener: _itemPositionsListener,
itemBuilder: (context, index) {
return widget.content[index];
},
Expand Down

0 comments on commit cb285d9

Please sign in to comment.