Implement a nicer account switcher
This commit is contained in:
parent
88c9991e0d
commit
e0c16031ef
@ -73,7 +73,7 @@ final _pages = <OkanePageItem>[
|
|||||||
"Accounts",
|
"Accounts",
|
||||||
AccountListPage(isPage: false),
|
AccountListPage(isPage: false),
|
||||||
null,
|
null,
|
||||||
false,
|
true,
|
||||||
),
|
),
|
||||||
OkanePageItem(
|
OkanePageItem(
|
||||||
OkanePage.transactions,
|
OkanePage.transactions,
|
||||||
@ -226,17 +226,10 @@ class OkaneNavigationLayout extends StatelessWidget {
|
|||||||
if (p.showAccountName &&
|
if (p.showAccountName &&
|
||||||
state.activeAccountIndex != null)
|
state.activeAccountIndex != null)
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.only(left: 8),
|
padding: EdgeInsets.symmetric(
|
||||||
child: Text(
|
horizontal: 8,
|
||||||
state
|
|
||||||
.accounts[state
|
|
||||||
.activeAccountIndex!]
|
|
||||||
.name!,
|
|
||||||
style:
|
|
||||||
Theme.of(
|
|
||||||
context,
|
|
||||||
).textTheme.titleLarge,
|
|
||||||
),
|
),
|
||||||
|
child: AccountSwitcher(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -249,12 +242,7 @@ class OkaneNavigationLayout extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
if (p.showAccountName &&
|
if (p.showAccountName &&
|
||||||
state.activeAccountIndex != null)
|
state.activeAccountIndex != null)
|
||||||
AccountIndicator(
|
AccountIndicator(),
|
||||||
accountName:
|
|
||||||
state
|
|
||||||
.accounts[state.activeAccountIndex!]
|
|
||||||
.name!,
|
|
||||||
),
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child:
|
child:
|
||||||
p.details != null
|
p.details != null
|
||||||
|
@ -32,90 +32,6 @@ class AccountListPageState extends State<AccountListPage> {
|
|||||||
children: [
|
children: [
|
||||||
ListView(
|
ListView(
|
||||||
children: [
|
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(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
child: BlocBuilder<CoreCubit, CoreState>(
|
child: BlocBuilder<CoreCubit, CoreState>(
|
||||||
|
@ -1,11 +1,86 @@
|
|||||||
import 'package:flutter/material.dart';
|
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 {
|
class AccountIndicator extends StatelessWidget {
|
||||||
final String accountName;
|
|
||||||
|
|
||||||
final Widget? trailing;
|
final Widget? trailing;
|
||||||
|
|
||||||
const AccountIndicator({super.key, this.trailing, required this.accountName});
|
const AccountIndicator({super.key, this.trailing});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -15,11 +90,8 @@ class AccountIndicator extends StatelessWidget {
|
|||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.all(8),
|
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||||
child: Text(
|
child: AccountSwitcher(),
|
||||||
accountName,
|
|
||||||
style: Theme.of(context).textTheme.titleLarge,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
if (trailing != null) trailing!,
|
if (trailing != null) trailing!,
|
||||||
|
Loading…
Reference in New Issue
Block a user