From 9c0d1085aefde73cd44499ae4b6e2d5fb1fca99f Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Mon, 3 Jun 2024 14:08:57 +1000 Subject: [PATCH] feat: Add wallet select across pages --- lib/domains.dart | 43 ++++++++++++++++++++ lib/home.dart | 64 ++++++++++++++++++++++++++++++ lib/main.dart | 92 ++++++++++--------------------------------- lib/transactions.dart | 43 ++++++++++++++++++++ test/widget_test.dart | 2 +- 5 files changed, 172 insertions(+), 72 deletions(-) create mode 100644 lib/domains.dart create mode 100644 lib/home.dart create mode 100644 lib/transactions.dart diff --git a/lib/domains.dart b/lib/domains.dart new file mode 100644 index 0000000..3b3b973 --- /dev/null +++ b/lib/domains.dart @@ -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 { + @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: [ + Text("Domain 1"), + Text("Domain 2"), + Text("Domain 3"), + ], + ); + }, + ), + ), + ); + } +} diff --git a/lib/home.dart b/lib/home.dart new file mode 100644 index 0000000..2541a7f --- /dev/null +++ b/lib/home.dart @@ -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 { + 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: [ + 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); + } +} diff --git a/lib/main.dart b/lib/main.dart index cec905b..1ec2acc 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,8 +2,13 @@ import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; +import 'package:firewallet/home.dart'; +import 'package:firewallet/transactions.dart'; +import 'package:firewallet/domains.dart'; Future main() async { + WidgetsFlutterBinding.ensureInitialized(); + final prefs = await SharedPreferences.getInstance(); // Check for the uuid key in the shared preferences @@ -71,6 +76,7 @@ class MyHomePage extends StatefulWidget { class _MyHomePageState extends State { int currentPageIndex = 0; + String wallet = ''; @override Widget build(BuildContext context) { @@ -99,78 +105,22 @@ class _MyHomePageState extends State { ), ], ), - body: [ - /// Home page - Card( - shadowColor: Colors.transparent, - margin: const EdgeInsets.all(8.0), - child: SizedBox.expand( - child: Center( - child: Text( - 'Welcome to Fire Wallet! 🚀', - style: theme.textTheme.titleLarge, - ), - ), - ), + body: SafeArea( + child: IndexedStack( + index: currentPageIndex, + children: [ + IndexPage(uuid: widget.uuid, wallet: wallet, setWallet: setWallet), + DomainsPage(uuid: widget.uuid, wallet: wallet), + TransactionsPage(uuid: widget.uuid, wallet: wallet), + ], ), - - /// Notifications page - Padding( - padding: const EdgeInsets.all(8.0), - child: Column( - children: [ - 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; + }); + } } diff --git a/lib/transactions.dart b/lib/transactions.dart new file mode 100644 index 0000000..0891cc3 --- /dev/null +++ b/lib/transactions.dart @@ -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 { + @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: [ + Text("Domain 1"), + Text("Domain 2"), + Text("Domain 3"), + ], + ); + }, + ), + ), + ); + } +} diff --git a/test/widget_test.dart b/test/widget_test.dart index f855687..2107562 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -13,7 +13,7 @@ import 'package:firewallet/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // 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. expect(find.text('0'), findsOneWidget);