131 lines
4.0 KiB
Dart
131 lines
4.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:sxchnge_wallet/sxchnge_wallet.dart';
|
|
|
|
import '../auth/brand_panel.dart';
|
|
import '../providers/locale.dart';
|
|
|
|
import '../generated/i18n/app_localizations.dart';
|
|
|
|
class WorkspaceShell extends StatefulWidget {
|
|
const WorkspaceShell({super.key, required this.child, required this.path});
|
|
final Widget child;
|
|
final String path;
|
|
@override
|
|
State<WorkspaceShell> createState() => _WorkspaceShellState();
|
|
}
|
|
|
|
class _WorkspaceShellState extends State<WorkspaceShell> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
if (!mounted) return;
|
|
final wallet = context.read<WalletProvider>();
|
|
if (wallet.data == null) wallet.refresh();
|
|
context.read<LocaleProvider>().loadAccount(wallet);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l = AppLocalizations.of(context)!;
|
|
final t = Theme.of(context);
|
|
final c = t.colorScheme;
|
|
final paths = ['/accounts', '/activity', '/limits', '/settings'];
|
|
final labels = [l.wAccounts, l.wActivity, l.wLimits, l.wSettings];
|
|
final icons = [
|
|
Icons.account_balance_wallet_outlined,
|
|
Icons.receipt_long_outlined,
|
|
Icons.speed_outlined,
|
|
Icons.tune_rounded,
|
|
];
|
|
final index = widget.path.startsWith('/activity')
|
|
? 1
|
|
: widget.path.startsWith('/limits') ||
|
|
widget.path.startsWith('/identity')
|
|
? 2
|
|
: widget.path.startsWith('/settings')
|
|
? 3
|
|
: 0;
|
|
void navigate(int i) {
|
|
if (['/top-up', '/exchange', '/payout'].contains(widget.path) && i >= 2) {
|
|
context.push(paths[i]);
|
|
} else {
|
|
context.go(paths[i]);
|
|
}
|
|
}
|
|
|
|
final wide = MediaQuery.sizeOf(context).width >= 900;
|
|
final content = Column(
|
|
children: [
|
|
if (!wide)
|
|
const Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 12),
|
|
child: Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: BrandWordmark(),
|
|
),
|
|
),
|
|
Expanded(child: widget.child),
|
|
],
|
|
);
|
|
return Scaffold(
|
|
body: SafeArea(
|
|
child: Row(
|
|
children: [
|
|
if (wide)
|
|
Container(
|
|
width: 220,
|
|
padding: const EdgeInsets.all(20),
|
|
decoration: BoxDecoration(
|
|
color: c.surfaceContainerLow,
|
|
border: Border(right: BorderSide(color: c.outlineVariant)),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
const Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 24),
|
|
child: BrandWordmark(),
|
|
),
|
|
const SizedBox(height: 48),
|
|
for (var i = 0; i < 4; i++)
|
|
Padding(
|
|
padding: const EdgeInsets.only(bottom: 12),
|
|
child: ListTile(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(18),
|
|
),
|
|
selected: i == index,
|
|
selectedTileColor: c.primaryContainer,
|
|
leading: Icon(icons[i]),
|
|
title: Text(labels[i]),
|
|
onTap: () => navigate(i),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Expanded(child: content),
|
|
],
|
|
),
|
|
),
|
|
bottomNavigationBar: wide
|
|
? null
|
|
: NavigationBar(
|
|
selectedIndex: index,
|
|
onDestinationSelected: navigate,
|
|
destinations: [
|
|
for (var i = 0; i < 4; i++)
|
|
NavigationDestination(icon: Icon(icons[i]), label: labels[i]),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|