-
Notifications
You must be signed in to change notification settings - Fork 0
flutter: ShareService — unify SharePlus usage + micro-cleanups #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d98cf7c
8806e23
da149ba
034b128
2cbd72e
6d018ca
b62a65b
df049e0
8f5ca97
bf23234
adb1ff1
b2af2b8
4c046f0
905fc01
959e66a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,10 +3,10 @@ import 'package:flutter/material.dart'; | |
| import 'package:jive_money/core/constants/app_constants.dart'; | ||
| import 'package:jive_money/ui/components/cards/account_card.dart'; | ||
| import 'package:jive_money/ui/components/loading/loading_widget.dart'; | ||
| import 'package:jive_money/models/account.dart'; | ||
| import 'package:jive_money/models/account.dart' as model; | ||
|
|
||
| // 类型别名以兼容现有代码 | ||
| typedef AccountData = Account; | ||
| typedef AccountData = model.Account; | ||
|
|
||
| class AccountList extends StatelessWidget { | ||
| final List<AccountData> accounts; | ||
|
|
@@ -102,7 +102,7 @@ class AccountList extends StatelessWidget { | |
| itemCount: accounts.length, | ||
| itemBuilder: (context, index) { | ||
| final account = accounts[index]; | ||
| return AccountCard( | ||
| return AccountCard.fromAccount( | ||
| account: account, | ||
| onTap: () => onAccountTap?.call(account), | ||
| onLongPress: () => onAccountLongPress?.call(account), | ||
|
|
@@ -138,7 +138,7 @@ class AccountList extends StatelessWidget { | |
|
|
||
| // 该类型的账户 | ||
| ...typeAccounts.map( | ||
| (account) => AccountCard( | ||
| (account) => AccountCard.fromAccount( | ||
| account: account, | ||
| onTap: () => onAccountTap?.call(account), | ||
| onLongPress: () => onAccountLongPress?.call(account), | ||
|
|
@@ -284,10 +284,11 @@ class AccountList extends StatelessWidget { | |
| final Map<AccountType, List<AccountData>> grouped = {}; | ||
|
|
||
| for (final account in accounts) { | ||
| if (!grouped.containsKey(account.type)) { | ||
| grouped[account.type] = []; | ||
| final key = _toUiAccountType(account.type); | ||
| if (!grouped.containsKey(key)) { | ||
| grouped[key] = []; | ||
| } | ||
| grouped[account.type]!.add(account); | ||
| grouped[key]!.add(account); | ||
| } | ||
|
|
||
| // 按类型排序:资产、负债 | ||
|
|
@@ -299,7 +300,7 @@ class AccountList extends StatelessWidget { | |
|
|
||
| double _calculateTotal(AccountType type) { | ||
| return accounts | ||
| .where((account) => account.type == type) | ||
| .where((account) => _matchesLocalType(type, account.type)) | ||
| .fold(0.0, (sum, account) => sum + account.balance); | ||
| } | ||
|
|
||
|
|
@@ -360,6 +361,26 @@ enum AccountSubType { | |
| mortgage, // 房贷 | ||
| } | ||
|
|
||
|
|
||
| // Model<->UI AccountType adapter | ||
| // Map model.AccountType (checking/savings/creditCard/loan/...) to local grouping (asset/liability) | ||
| AccountType _toUiAccountType(model.AccountType t) { | ||
|
Comment on lines
+364
to
+367
|
||
| switch (t) { | ||
| case model.AccountType.creditCard: | ||
| case model.AccountType.loan: | ||
| return AccountType.liability; | ||
| default: | ||
| return AccountType.asset; | ||
| } | ||
| } | ||
|
|
||
| bool _matchesLocalType(AccountType localType, model.AccountType modelType) { | ||
| final isLiability = modelType == model.AccountType.creditCard || modelType == model.AccountType.loan; | ||
| if (localType == AccountType.liability) return isLiability; | ||
| return !isLiability; | ||
| } | ||
|
Comment on lines
+377
to
+381
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The implementation of bool _matchesLocalType(AccountType localType, model.AccountType modelType) {
return _toUiAccountType(modelType) == localType;
} |
||
|
|
||
|
|
||
| /// 账户分组列表 | ||
| class GroupedAccountList extends StatelessWidget { | ||
| final Map<String, List<AccountData>> groupedAccounts; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The null-aware operator on
urlsuggests it might be null, but this could result in the text ending with an empty string. Consider handling null urls more explicitly, such as only appending the url if it's not null.