feat: Add account creation

This commit is contained in:
2024-06-03 13:40:27 +10:00
parent 9900127587
commit 3ee4e50b71
4 changed files with 218 additions and 24 deletions

View File

@@ -1,11 +1,41 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
void main() {
runApp(const MyApp());
Future<void> main() async {
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');
runApp(MyApp(uuid: uuid ?? 'null'));
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
const MyApp({
super.key,
required this.uuid,
});
final String uuid;
// This widget is the root of your application.
@override
@@ -13,16 +43,27 @@ class MyApp extends StatelessWidget {
return MaterialApp(
title: 'Fire Wallet',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
brightness: Brightness.light,
/* light theme settings */
),
home: const MyHomePage(),
darkTheme: ThemeData(
brightness: Brightness.dark,
/* dark theme settings */
),
themeMode: ThemeMode.system,
debugShowCheckedModeBanner: false,
home: MyHomePage(uuid: uuid),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
const MyHomePage({
super.key,
required this.uuid,
});
final String uuid;
@override
State<MyHomePage> createState() => _MyHomePageState();
@@ -66,7 +107,7 @@ class _MyHomePageState extends State<MyHomePage> {
child: SizedBox.expand(
child: Center(
child: Text(
'Home page',
'Welcome to Fire Wallet! 🚀',
style: theme.textTheme.titleLarge,
),
),
@@ -74,24 +115,16 @@ class _MyHomePageState extends State<MyHomePage> {
),
/// Notifications page
const Padding(
padding: EdgeInsets.all(8.0),
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Card(
child: ListTile(
leading: Icon(Icons.notifications_sharp),
title: Text('Notification 1'),
subtitle: Text('This is a notification'),
),
),
Card(
child: ListTile(
leading: Icon(Icons.notifications_sharp),
title: Text('Notification 2'),
subtitle: Text('This is a notification'),
),
),
child: Center(
child: Text(
// UUID of the user
'UUID: ${widget.uuid}',
))),
],
),
),