From af572971b9fe972209c7c5a477cbe1f2657e1fec Mon Sep 17 00:00:00 2001 From: ashuntu Date: Tue, 17 Dec 2024 15:30:37 -0600 Subject: [PATCH] Dispose of TextEditingController --- .../subscribe_now/subscribe_now_page.dart | 59 +++++++++++-------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/gui/packages/ubuntupro/lib/pages/subscribe_now/subscribe_now_page.dart b/gui/packages/ubuntupro/lib/pages/subscribe_now/subscribe_now_page.dart index 7d43ec7af..cb3005c07 100644 --- a/gui/packages/ubuntupro/lib/pages/subscribe_now/subscribe_now_page.dart +++ b/gui/packages/ubuntupro/lib/pages/subscribe_now/subscribe_now_page.dart @@ -14,13 +14,44 @@ import '/pages/widgets/page_widgets.dart'; import 'subscribe_now_model.dart'; import 'subscribe_now_widgets.dart'; -class SubscribeNowPage extends StatelessWidget { - SubscribeNowPage({super.key, required this.onSubscriptionUpdate}); +class SubscribeNowPage extends StatefulWidget { + const SubscribeNowPage({super.key, required this.onSubscriptionUpdate}); final void Function(SubscriptionInfo) onSubscriptionUpdate; + @override + State createState() => _SubscribeNowPageState(); + + static Widget create(BuildContext context) { + final client = getService(); + final storePurchaseIsAllowed = + Wizard.of(context).routeData as bool? ?? false; + + return ChangeNotifierProvider( + create: (context) => SubscribeNowModel( + client, + isPurchaseAllowed: storePurchaseIsAllowed, + ), + child: SubscribeNowPage( + onSubscriptionUpdate: (info) { + final src = context.read>(); + src.value.proSubscription = info; + Wizard.of(context).next(); + }, + ), + ); + } +} + +class _SubscribeNowPageState extends State { final controller = TextEditingController(); + @override + void dispose() { + controller.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { final model = context.watch(); @@ -70,7 +101,7 @@ class SubscribeNowPage extends StatelessWidget { ), ); }, - ifRight: onSubscriptionUpdate, + ifRight: widget.onSubscriptionUpdate, ); }, child: Text(lang.getUbuntuPro), @@ -92,30 +123,10 @@ class SubscribeNowPage extends StatelessWidget { } void trySubmit(SubscribeNowModel model) { - model.applyProToken(model.token!).then(onSubscriptionUpdate); + model.applyProToken(model.token!).then(widget.onSubscriptionUpdate); model.clearToken(); controller.clear(); } - - static Widget create(BuildContext context) { - final client = getService(); - final storePurchaseIsAllowed = - Wizard.of(context).routeData as bool? ?? false; - - return ChangeNotifierProvider( - create: (context) => SubscribeNowModel( - client, - isPurchaseAllowed: storePurchaseIsAllowed, - ), - child: SubscribeNowPage( - onSubscriptionUpdate: (info) { - final src = context.read>(); - src.value.proSubscription = info; - Wizard.of(context).next(); - }, - ), - ); - } } extension PurchaseStatusl10n on PurchaseStatus {