feat: Add wallet select across pages
This commit is contained in:
parent
3ee4e50b71
commit
9c0d1085ae
43
lib/domains.dart
Normal file
43
lib/domains.dart
Normal 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
64
lib/home.dart
Normal 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);
|
||||
}
|
||||
}
|
@ -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<void> 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<MyHomePage> {
|
||||
int currentPageIndex = 0;
|
||||
String wallet = '';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -99,78 +105,22 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
),
|
||||
],
|
||||
),
|
||||
body: <Widget>[
|
||||
/// 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: <Widget>[
|
||||
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: <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
43
lib/transactions.dart
Normal 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"),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user