Skip to content

Commit

Permalink
Dispose of TextEditingController
Browse files Browse the repository at this point in the history
  • Loading branch information
ashuntu committed Dec 17, 2024
1 parent 99d9134 commit af57297
Showing 1 changed file with 35 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<SubscribeNowPage> createState() => _SubscribeNowPageState();

static Widget create(BuildContext context) {
final client = getService<AgentApiClient>();
final storePurchaseIsAllowed =
Wizard.of(context).routeData as bool? ?? false;

return ChangeNotifierProvider<SubscribeNowModel>(
create: (context) => SubscribeNowModel(
client,
isPurchaseAllowed: storePurchaseIsAllowed,
),
child: SubscribeNowPage(
onSubscriptionUpdate: (info) {
final src = context.read<ValueNotifier<ConfigSources>>();
src.value.proSubscription = info;
Wizard.of(context).next();

Check warning on line 39 in gui/packages/ubuntupro/lib/pages/subscribe_now/subscribe_now_page.dart

View check run for this annotation

Codecov / codecov/patch

gui/packages/ubuntupro/lib/pages/subscribe_now/subscribe_now_page.dart#L36-L39

Added lines #L36 - L39 were not covered by tests
},
),
);
}
}

class _SubscribeNowPageState extends State<SubscribeNowPage> {
final controller = TextEditingController();

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

@override
Widget build(BuildContext context) {
final model = context.watch<SubscribeNowModel>();
Expand Down Expand Up @@ -70,7 +101,7 @@ class SubscribeNowPage extends StatelessWidget {
),
);
},
ifRight: onSubscriptionUpdate,
ifRight: widget.onSubscriptionUpdate,
);
},
child: Text(lang.getUbuntuPro),
Expand All @@ -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<AgentApiClient>();
final storePurchaseIsAllowed =
Wizard.of(context).routeData as bool? ?? false;

return ChangeNotifierProvider<SubscribeNowModel>(
create: (context) => SubscribeNowModel(
client,
isPurchaseAllowed: storePurchaseIsAllowed,
),
child: SubscribeNowPage(
onSubscriptionUpdate: (info) {
final src = context.read<ValueNotifier<ConfigSources>>();
src.value.proSubscription = info;
Wizard.of(context).next();
},
),
);
}
}

extension PurchaseStatusl10n on PurchaseStatus {
Expand Down

0 comments on commit af57297

Please sign in to comment.