fix: save the placeholder name into name var
This commit is contained in:
parent
095e2f62ba
commit
2226d37f8f
1 changed files with 85 additions and 74 deletions
|
@ -24,6 +24,7 @@ import 'package:prasule/pw/platformbutton.dart';
|
||||||
import 'package:prasule/pw/platformfield.dart';
|
import 'package:prasule/pw/platformfield.dart';
|
||||||
import 'package:prasule/pw/platformroute.dart';
|
import 'package:prasule/pw/platformroute.dart';
|
||||||
import 'package:prasule/util/drawer.dart';
|
import 'package:prasule/util/drawer.dart';
|
||||||
|
import 'package:prasule/util/sorting.dart';
|
||||||
import 'package:prasule/util/text_color.dart';
|
import 'package:prasule/util/text_color.dart';
|
||||||
import 'package:prasule/util/utils.dart';
|
import 'package:prasule/util/utils.dart';
|
||||||
import 'package:prasule/views/create_entry.dart';
|
import 'package:prasule/views/create_entry.dart';
|
||||||
|
@ -41,13 +42,15 @@ class HomeView extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _HomeViewState extends State<HomeView> {
|
class _HomeViewState extends State<HomeView> {
|
||||||
Wallet? selectedWallet;
|
Wallet? selectedWallet; // current wallet
|
||||||
List<Wallet> wallets = [];
|
List<Wallet> wallets = []; // all available wallets
|
||||||
DateTime? prevDate;
|
DateTime? prevDate;
|
||||||
late String locale;
|
late String locale; // user's locale
|
||||||
var _searchActive = false;
|
var _searchActive = false; // whether search field is shown
|
||||||
var _filter = "";
|
var _filter = ""; // search filter
|
||||||
final searchFocus = FocusNode();
|
final searchFocus = FocusNode();
|
||||||
|
var sort = SortType.newest;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
|
@ -191,40 +194,67 @@ class _HomeViewState extends State<HomeView> {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
actions: [
|
actions: _searchActive
|
||||||
if (!_searchActive)
|
? []
|
||||||
IconButton(
|
: [
|
||||||
onPressed: () {
|
IconButton(
|
||||||
_searchActive = true;
|
onPressed: () {
|
||||||
setState(() {});
|
_searchActive = true;
|
||||||
},
|
setState(() {});
|
||||||
icon: const Icon(Icons.search),
|
},
|
||||||
),
|
icon: const Icon(Icons.search),
|
||||||
if (!_searchActive)
|
),
|
||||||
PopupMenuButton(
|
PopupMenuButton(
|
||||||
itemBuilder: (context) => [
|
tooltip: AppLocalizations.of(context).sort,
|
||||||
AppLocalizations.of(context).settings,
|
icon: const Icon(Icons.sort_rounded),
|
||||||
AppLocalizations.of(context).about,
|
itemBuilder: (context) => [
|
||||||
].map((e) => PopupMenuItem(value: e, child: Text(e))).toList(),
|
AppLocalizations.of(context).sortNewest,
|
||||||
onSelected: (value) {
|
AppLocalizations.of(context).sortOldest,
|
||||||
if (value == AppLocalizations.of(context).settings) {
|
]
|
||||||
Navigator.of(context)
|
.map(
|
||||||
.push(
|
(e) => PopupMenuItem(
|
||||||
platformRoute(
|
value: e,
|
||||||
(context) => const SettingsView(),
|
child: Text(e),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.then((value) async {
|
.toList(),
|
||||||
wallets = await WalletManager.listWallets();
|
onSelected: (value) {
|
||||||
selectedWallet =
|
if (value == AppLocalizations.of(context).sortNewest) {
|
||||||
await WalletManager.loadWallet(selectedWallet!.name);
|
sort = SortType.newest;
|
||||||
});
|
setState(() {});
|
||||||
} else if (value == AppLocalizations.of(context).about) {
|
} else if (value ==
|
||||||
showAbout(context);
|
AppLocalizations.of(context).sortOldest) {
|
||||||
}
|
sort = SortType.oldest;
|
||||||
},
|
setState(() {});
|
||||||
),
|
}
|
||||||
],
|
},
|
||||||
|
),
|
||||||
|
PopupMenuButton(
|
||||||
|
itemBuilder: (context) => [
|
||||||
|
AppLocalizations.of(context).settings,
|
||||||
|
AppLocalizations.of(context).about,
|
||||||
|
]
|
||||||
|
.map((e) => PopupMenuItem(value: e, child: Text(e)))
|
||||||
|
.toList(),
|
||||||
|
onSelected: (value) {
|
||||||
|
if (value == AppLocalizations.of(context).settings) {
|
||||||
|
Navigator.of(context)
|
||||||
|
.push(
|
||||||
|
platformRoute(
|
||||||
|
(context) => const SettingsView(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.then((value) async {
|
||||||
|
wallets = await WalletManager.listWallets();
|
||||||
|
selectedWallet = await WalletManager.loadWallet(
|
||||||
|
selectedWallet!.name);
|
||||||
|
});
|
||||||
|
} else if (value == AppLocalizations.of(context).about) {
|
||||||
|
showAbout(context);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
body: Center(
|
body: Center(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
|
@ -358,43 +388,15 @@ class _HomeViewState extends State<HomeView> {
|
||||||
)
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
itemComparator: (a, b) =>
|
itemComparator: (a, b) =>
|
||||||
b.date.compareTo(a.date),
|
(sort == SortType.newest)
|
||||||
|
? b.date.compareTo(a.date)
|
||||||
|
: a.date.compareTo(b.date),
|
||||||
groupBy: (e) =>
|
groupBy: (e) =>
|
||||||
DateFormat.yMMMM(locale).format(e.date),
|
DateFormat.yMMMM(locale).format(e.date),
|
||||||
groupComparator: (a, b) {
|
groupComparator: (a, b) =>
|
||||||
// TODO: better sorting algorithm lol
|
(sort == SortType.newest)
|
||||||
final yearA =
|
? groupSortNewest(a, b, locale)
|
||||||
RegExp(r'\d+').firstMatch(a);
|
: groupSortOldest(a, b, locale),
|
||||||
if (yearA == null) return 0;
|
|
||||||
final yearB =
|
|
||||||
RegExp(r'\d+').firstMatch(b);
|
|
||||||
if (yearB == null) return 0;
|
|
||||||
final compareYears =
|
|
||||||
int.parse(yearB.group(0)!).compareTo(
|
|
||||||
int.parse(yearA.group(0)!),
|
|
||||||
);
|
|
||||||
if (compareYears != 0) {
|
|
||||||
return compareYears;
|
|
||||||
}
|
|
||||||
final months = List<String>.generate(
|
|
||||||
12,
|
|
||||||
(index) =>
|
|
||||||
DateFormat.MMMM(locale).format(
|
|
||||||
DateTime(2023, index + 1),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
final monthA =
|
|
||||||
RegExp('[^0-9 ]+').firstMatch(a);
|
|
||||||
if (monthA == null) return 0;
|
|
||||||
final monthB =
|
|
||||||
RegExp('[^0-9 ]+').firstMatch(b);
|
|
||||||
if (monthB == null) return 0;
|
|
||||||
return months
|
|
||||||
.indexOf(monthB.group(0)!)
|
|
||||||
.compareTo(
|
|
||||||
months.indexOf(monthA.group(0)!),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
itemBuilder: (context, element) => Slidable(
|
itemBuilder: (context, element) => Slidable(
|
||||||
endActionPane: ActionPane(
|
endActionPane: ActionPane(
|
||||||
motion: const ScrollMotion(),
|
motion: const ScrollMotion(),
|
||||||
|
@ -760,3 +762,12 @@ class _HomeViewState extends State<HomeView> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Represents entry sorting type
|
||||||
|
enum SortType {
|
||||||
|
/// Sort newest first
|
||||||
|
newest,
|
||||||
|
|
||||||
|
/// Sort oldest first
|
||||||
|
oldest
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue