Implement a nicer account switcher
This commit is contained in:
parent
88c9991e0d
commit
e0c16031ef
@ -73,7 +73,7 @@ final _pages = <OkanePageItem>[
|
||||
"Accounts",
|
||||
AccountListPage(isPage: false),
|
||||
null,
|
||||
false,
|
||||
true,
|
||||
),
|
||||
OkanePageItem(
|
||||
OkanePage.transactions,
|
||||
@ -226,17 +226,10 @@ class OkaneNavigationLayout extends StatelessWidget {
|
||||
if (p.showAccountName &&
|
||||
state.activeAccountIndex != null)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 8),
|
||||
child: Text(
|
||||
state
|
||||
.accounts[state
|
||||
.activeAccountIndex!]
|
||||
.name!,
|
||||
style:
|
||||
Theme.of(
|
||||
context,
|
||||
).textTheme.titleLarge,
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
),
|
||||
child: AccountSwitcher(),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -249,12 +242,7 @@ class OkaneNavigationLayout extends StatelessWidget {
|
||||
children: [
|
||||
if (p.showAccountName &&
|
||||
state.activeAccountIndex != null)
|
||||
AccountIndicator(
|
||||
accountName:
|
||||
state
|
||||
.accounts[state.activeAccountIndex!]
|
||||
.name!,
|
||||
),
|
||||
AccountIndicator(),
|
||||
Expanded(
|
||||
child:
|
||||
p.details != null
|
||||
|
@ -32,90 +32,6 @@ class AccountListPageState extends State<AccountListPage> {
|
||||
children: [
|
||||
ListView(
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Text(
|
||||
t.pages.accounts.title,
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
),
|
||||
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: BlocBuilder<CoreCubit, CoreState>(
|
||||
builder:
|
||||
(context, state) => Row(
|
||||
children: [
|
||||
OutlinedButton(
|
||||
onPressed:
|
||||
state.accounts.isEmpty
|
||||
? null
|
||||
: () {
|
||||
showDialogOrModal(
|
||||
context: context,
|
||||
builder:
|
||||
(context) => ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: state.accounts.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item =
|
||||
state.accounts[index];
|
||||
return ListTile(
|
||||
title: Text(item.name!),
|
||||
trailing: IconButton(
|
||||
icon: Icon(Icons.delete),
|
||||
color: Colors.red,
|
||||
onPressed: () async {
|
||||
await showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder:
|
||||
(context) =>
|
||||
DeleteAccountPopup(
|
||||
account: item,
|
||||
onCancel: () {
|
||||
Navigator.of(
|
||||
context,
|
||||
).pop();
|
||||
Navigator.of(
|
||||
context,
|
||||
).pop();
|
||||
},
|
||||
afterDelete: () {
|
||||
Navigator.of(
|
||||
context,
|
||||
).pop();
|
||||
Navigator.of(
|
||||
context,
|
||||
).pop();
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
onTap: () {
|
||||
GetIt.I
|
||||
.get<CoreCubit>()
|
||||
.setActiveAccountIndex(
|
||||
index,
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Text(
|
||||
bloc.activeAccount?.name ??
|
||||
t.pages.accounts.accountSelector.none,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: BlocBuilder<CoreCubit, CoreState>(
|
||||
|
@ -1,11 +1,86 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:okane/ui/pages/account/delete_account.dart';
|
||||
import 'package:okane/ui/state/core.dart';
|
||||
import 'package:okane/ui/utils.dart';
|
||||
|
||||
class AccountSwitcher extends StatelessWidget {
|
||||
const AccountSwitcher({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bloc = GetIt.I.get<CoreCubit>();
|
||||
return BlocBuilder<CoreCubit, CoreState>(
|
||||
builder:
|
||||
(context, state) => InkWell(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
onTap: () {
|
||||
showDialogOrModal(
|
||||
context: context,
|
||||
builder:
|
||||
(context) => ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: state.accounts.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = state.accounts[index];
|
||||
return ListTile(
|
||||
title: Text(item.name!),
|
||||
trailing: IconButton(
|
||||
icon: Icon(Icons.delete),
|
||||
color: Colors.red,
|
||||
onPressed: () async {
|
||||
await showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder:
|
||||
(context) => DeleteAccountPopup(
|
||||
account: item,
|
||||
onCancel: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
afterDelete: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
onTap: () {
|
||||
GetIt.I.get<CoreCubit>().setActiveAccountIndex(
|
||||
index,
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
bloc.activeAccount!.name!,
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
Icon(Icons.arrow_drop_down),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AccountIndicator extends StatelessWidget {
|
||||
final String accountName;
|
||||
|
||||
final Widget? trailing;
|
||||
|
||||
const AccountIndicator({super.key, this.trailing, required this.accountName});
|
||||
const AccountIndicator({super.key, this.trailing});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -15,11 +90,8 @@ class AccountIndicator extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.all(8),
|
||||
child: Text(
|
||||
accountName,
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
child: AccountSwitcher(),
|
||||
),
|
||||
const Spacer(),
|
||||
if (trailing != null) trailing!,
|
||||
|
Loading…
Reference in New Issue
Block a user