Line data Source code
1 : // Copyright 2023 The terCAD team. All rights reserved. 2 : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file. 3 : 4 : import 'package:app_finance/_classes/herald/app_locale.dart'; 5 : import 'package:app_finance/_classes/structure/goal_app_data.dart'; 6 : import 'package:app_finance/pages/goal/goal_add_page.dart'; 7 : import 'package:flutter/material.dart'; 8 : 9 : class GoalEditPage extends GoalAddPage { 10 : final String uuid; 11 : 12 0 : const GoalEditPage({ 13 : super.key, 14 : required this.uuid, 15 : }); 16 : 17 0 : @override 18 0 : GoalEditPageState createState() => GoalEditPageState(); 19 : } 20 : 21 : class GoalEditPageState extends GoalAddPageState<GoalEditPage> { 22 : late String uuid; 23 : bool isFirstRun = true; 24 : 25 0 : @override 26 : void initState() { 27 0 : uuid = (widget as GoalEditPage).uuid; 28 0 : super.initState(); 29 : } 30 : 31 0 : @override 32 : String getTitle() { 33 0 : return AppLocale.labels.editGoalHeader; 34 : } 35 : 36 0 : @override 37 : void updateStorage() { 38 0 : var data = state.getByUuid(uuid) as GoalAppData; 39 0 : data.title = title.text; 40 0 : data.color = color; 41 0 : data.icon = icon; 42 0 : data.details = double.tryParse(details.text) ?? 0.0; 43 0 : data.closedAt = closedAt ?? DateTime.now(); 44 0 : data.currency = currency; 45 0 : state.update(uuid, data); 46 : } 47 : 48 0 : void bindState() { 49 0 : if (!isFirstRun) { 50 : return; 51 : } 52 0 : setState(() { 53 0 : isFirstRun = false; 54 0 : var form = super.state.getByUuid(uuid) as GoalAppData; 55 0 : super.title.text = form.title; 56 0 : super.details.text = form.details != null ? form.details.toString() : ''; 57 0 : super.color = form.color; 58 0 : super.icon = form.icon; 59 0 : super.currency = form.currency; 60 0 : super.closedAt = form.closedAt; 61 : }); 62 : } 63 : 64 0 : @override 65 : String getButtonName() { 66 0 : return AppLocale.labels.updateGoalTooltip; 67 : } 68 : 69 0 : @override 70 : Widget buildContent(BuildContext context, BoxConstraints constraints) { 71 0 : WidgetsBinding.instance.addPostFrameCallback((_) => bindState()); 72 0 : return super.buildContent(context, constraints); 73 : } 74 : }