feat: Add wallet select across pages

This commit is contained in:
Nathan Woodburn 2024-06-03 14:08:57 +10:00
parent 3ee4e50b71
commit 9c0d1085ae
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
5 changed files with 172 additions and 72 deletions

43
lib/domains.dart Normal file
View File

@ -0,0 +1,43 @@
import 'package:flutter/material.dart';
class DomainsPage extends StatefulWidget {
DomainsPage({Key? key, required this.uuid, required this.wallet})
: super(key: key);
final String uuid;
String wallet;
@override
_DomainsPageState createState() => _DomainsPageState();
}
class _DomainsPageState extends State<DomainsPage> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('${widget.wallet} Domains'),
),
// Get wallet list from api and display here
body: Center(
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("Domain 1"),
Text("Domain 2"),
Text("Domain 3"),
],
);
},
),
),
);
}
}

64
lib/home.dart Normal file
View File

@ -0,0 +1,64 @@
import 'package:flutter/material.dart';
class IndexPage extends StatefulWidget {
IndexPage(
{Key? key,
required this.uuid,
required this.wallet,
required this.setWallet})
: super(key: key);
final String uuid;
String wallet;
final Function setWallet;
@override
_IndexPageState createState() => _IndexPageState();
}
class _IndexPageState extends State<IndexPage> {
late String wallet;
@override
void initState() {
super.initState();
wallet = widget.wallet;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(wallet),
),
// Get wallet list from api and display here
body: Center(
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextButton(
onPressed: () => setWallet('wallet1'),
child: Text('Wallet 1')),
TextButton(
onPressed: () => setWallet('wallet2'),
child: Text('Wallet 2')),
TextButton(
onPressed: () => setWallet('wallet3'),
child: Text('Wallet 3')),
],
);
},
),
),
);
}
void setWallet(String s) {
setState(() {
wallet = s;
});
widget.setWallet(s);
}
}

View File

@ -2,8 +2,13 @@ import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'dart:convert'; import 'dart:convert';
import 'package:firewallet/home.dart';
import 'package:firewallet/transactions.dart';
import 'package:firewallet/domains.dart';
Future<void> main() async { Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
final prefs = await SharedPreferences.getInstance(); final prefs = await SharedPreferences.getInstance();
// Check for the uuid key in the shared preferences // Check for the uuid key in the shared preferences
@ -71,6 +76,7 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> { class _MyHomePageState extends State<MyHomePage> {
int currentPageIndex = 0; int currentPageIndex = 0;
String wallet = '';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -99,78 +105,22 @@ class _MyHomePageState extends State<MyHomePage> {
), ),
], ],
), ),
body: <Widget>[ body: SafeArea(
/// Home page child: IndexedStack(
Card( index: currentPageIndex,
shadowColor: Colors.transparent, children: <Widget>[
margin: const EdgeInsets.all(8.0), IndexPage(uuid: widget.uuid, wallet: wallet, setWallet: setWallet),
child: SizedBox.expand( DomainsPage(uuid: widget.uuid, wallet: wallet),
child: Center( TransactionsPage(uuid: widget.uuid, wallet: wallet),
child: Text( ],
'Welcome to Fire Wallet! 🚀',
style: theme.textTheme.titleLarge,
),
),
),
), ),
),
/// Notifications page
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Card(
child: Center(
child: Text(
// UUID of the user
'UUID: ${widget.uuid}',
))),
],
),
),
/// Messages page
ListView.builder(
reverse: true,
itemCount: 2,
itemBuilder: (BuildContext context, int index) {
if (index == 0) {
return Align(
alignment: Alignment.centerRight,
child: Container(
margin: const EdgeInsets.all(8.0),
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: theme.colorScheme.primary,
borderRadius: BorderRadius.circular(8.0),
),
child: Text(
'Hello',
style: theme.textTheme.bodyLarge!
.copyWith(color: theme.colorScheme.onPrimary),
),
),
);
}
return Align(
alignment: Alignment.centerLeft,
child: Container(
margin: const EdgeInsets.all(8.0),
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: theme.colorScheme.primary,
borderRadius: BorderRadius.circular(8.0),
),
child: Text(
'Hi!',
style: theme.textTheme.bodyLarge!
.copyWith(color: theme.colorScheme.onPrimary),
),
),
);
},
),
][currentPageIndex],
); );
} }
void setWallet(String s) {
setState(() {
wallet = s;
});
}
} }

43
lib/transactions.dart Normal file
View File

@ -0,0 +1,43 @@
import 'package:flutter/material.dart';
class TransactionsPage extends StatefulWidget {
TransactionsPage({Key? key, required this.uuid, required this.wallet})
: super(key: key);
final String uuid;
String wallet;
@override
_TransactionsPageState createState() => _TransactionsPageState();
}
class _TransactionsPageState extends State<TransactionsPage> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('${widget.wallet} Transactions'),
),
// Get wallet list from api and display here
body: Center(
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("Domain 1"),
Text("Domain 2"),
Text("Domain 3"),
],
);
},
),
),
);
}
}

View File

@ -13,7 +13,7 @@ import 'package:firewallet/main.dart';
void main() { void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async { testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame. // Build our app and trigger a frame.
await tester.pumpWidget(const MyApp()); await tester.pumpWidget(const MyApp(uuid: 'null'));
// Verify that our counter starts at 0. // Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget); expect(find.text('0'), findsOneWidget);