2024-06-03 13:04:05 +10:00
|
|
|
import 'package:flutter/material.dart';
|
2024-06-03 13:40:27 +10:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import 'dart:convert';
|
2024-06-03 14:08:57 +10:00
|
|
|
import 'package:firewallet/home.dart';
|
|
|
|
import 'package:firewallet/transactions.dart';
|
|
|
|
import 'package:firewallet/domains.dart';
|
2024-06-04 15:20:39 +10:00
|
|
|
import 'package:firewallet/receive.dart';
|
|
|
|
import 'package:firewallet/send.dart';
|
2024-06-03 13:04:05 +10:00
|
|
|
|
2024-06-03 13:40:27 +10:00
|
|
|
Future<void> main() async {
|
2024-06-03 14:08:57 +10:00
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
2024-06-03 13:40:27 +10:00
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
|
|
|
|
// Check for the uuid key in the shared preferences
|
|
|
|
if (!prefs.containsKey('uuid')) {
|
|
|
|
// Create an account using https://api.firewallet.au/account
|
|
|
|
// and get the uuid from the response
|
|
|
|
final response = await http.post(
|
|
|
|
Uri.parse('https://api.firewallet.au/account'),
|
|
|
|
headers: <String, String>{
|
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
|
|
},
|
|
|
|
body: '{}',
|
|
|
|
);
|
|
|
|
|
|
|
|
// Get uuid from { "userID": "..." }
|
|
|
|
final uuid = jsonDecode(response.body)['userID'];
|
|
|
|
// Save the uuid to the shared preferences
|
|
|
|
await prefs.setString('uuid', uuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the uuid from the shared preferences
|
|
|
|
final String? uuid = prefs.getString('uuid');
|
2024-06-03 17:06:45 +10:00
|
|
|
print('UUID: $uuid');
|
2024-06-03 13:40:27 +10:00
|
|
|
runApp(MyApp(uuid: uuid ?? 'null'));
|
2024-06-03 13:04:05 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
2024-06-03 13:40:27 +10:00
|
|
|
const MyApp({
|
|
|
|
super.key,
|
|
|
|
required this.uuid,
|
|
|
|
});
|
|
|
|
|
|
|
|
final String uuid;
|
2024-06-03 13:04:05 +10:00
|
|
|
|
|
|
|
// This widget is the root of your application.
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
2024-06-03 13:24:39 +10:00
|
|
|
title: 'Fire Wallet',
|
2024-06-03 13:04:05 +10:00
|
|
|
theme: ThemeData(
|
2024-06-03 13:40:27 +10:00
|
|
|
brightness: Brightness.light,
|
|
|
|
/* light theme settings */
|
2024-06-03 13:04:05 +10:00
|
|
|
),
|
2024-06-03 13:40:27 +10:00
|
|
|
darkTheme: ThemeData(
|
|
|
|
brightness: Brightness.dark,
|
|
|
|
/* dark theme settings */
|
|
|
|
),
|
|
|
|
themeMode: ThemeMode.system,
|
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
home: MyHomePage(uuid: uuid),
|
2024-06-03 13:04:05 +10:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyHomePage extends StatefulWidget {
|
2024-06-03 13:40:27 +10:00
|
|
|
const MyHomePage({
|
|
|
|
super.key,
|
|
|
|
required this.uuid,
|
|
|
|
});
|
|
|
|
|
|
|
|
final String uuid;
|
2024-06-03 13:04:05 +10:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<MyHomePage> createState() => _MyHomePageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
2024-06-03 13:24:39 +10:00
|
|
|
int currentPageIndex = 0;
|
2024-06-03 14:08:57 +10:00
|
|
|
String wallet = '';
|
2024-06-03 13:04:05 +10:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-06-03 13:24:39 +10:00
|
|
|
final ThemeData theme = Theme.of(context);
|
2024-06-03 13:04:05 +10:00
|
|
|
return Scaffold(
|
2024-06-03 13:24:39 +10:00
|
|
|
bottomNavigationBar: NavigationBar(
|
|
|
|
onDestinationSelected: (int index) {
|
|
|
|
setState(() {
|
|
|
|
currentPageIndex = index;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
selectedIndex: currentPageIndex,
|
|
|
|
destinations: const <Widget>[
|
|
|
|
NavigationDestination(
|
|
|
|
selectedIcon: Icon(Icons.home),
|
|
|
|
icon: Icon(Icons.home_outlined),
|
|
|
|
label: 'Home',
|
|
|
|
),
|
2024-06-04 15:20:39 +10:00
|
|
|
NavigationDestination(
|
|
|
|
icon: Icon(Icons.call_received), label: 'Receive'),
|
|
|
|
NavigationDestination(
|
|
|
|
icon: Icon(Icons.send),
|
|
|
|
label: 'Send',
|
|
|
|
),
|
2024-06-03 13:24:39 +10:00
|
|
|
NavigationDestination(
|
|
|
|
icon: Icon(Icons.text_format_rounded),
|
|
|
|
label: 'Domains',
|
|
|
|
),
|
|
|
|
NavigationDestination(
|
|
|
|
icon: Icon(Icons.receipt),
|
|
|
|
label: 'Transactions',
|
|
|
|
),
|
|
|
|
],
|
2024-06-03 13:04:05 +10:00
|
|
|
),
|
2024-06-03 14:08:57 +10:00
|
|
|
body: SafeArea(
|
|
|
|
child: IndexedStack(
|
|
|
|
index: currentPageIndex,
|
|
|
|
children: <Widget>[
|
|
|
|
IndexPage(uuid: widget.uuid, wallet: wallet, setWallet: setWallet),
|
2024-06-04 15:20:39 +10:00
|
|
|
ReceivePage(uuid: widget.uuid, wallet: wallet),
|
|
|
|
SendPage(uuid: widget.uuid, wallet: wallet),
|
2024-06-03 14:08:57 +10:00
|
|
|
DomainsPage(uuid: widget.uuid, wallet: wallet),
|
|
|
|
TransactionsPage(uuid: widget.uuid, wallet: wallet),
|
|
|
|
],
|
2024-06-03 13:24:39 +10:00
|
|
|
),
|
2024-06-03 14:08:57 +10:00
|
|
|
),
|
2024-06-03 13:04:05 +10:00
|
|
|
);
|
|
|
|
}
|
2024-06-03 14:08:57 +10:00
|
|
|
|
|
|
|
void setWallet(String s) {
|
|
|
|
setState(() {
|
|
|
|
wallet = s;
|
|
|
|
});
|
|
|
|
}
|
2024-06-03 13:04:05 +10:00
|
|
|
}
|