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 13:04:05 +10:00
|
|
|
|
2024-06-03 13:40:27 +10:00
|
|
|
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'));
|
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 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',
|
|
|
|
),
|
|
|
|
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 13:24:39 +10:00
|
|
|
body: <Widget>[
|
|
|
|
/// Home page
|
|
|
|
Card(
|
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
margin: const EdgeInsets.all(8.0),
|
|
|
|
child: SizedBox.expand(
|
|
|
|
child: Center(
|
|
|
|
child: Text(
|
2024-06-03 13:40:27 +10:00
|
|
|
'Welcome to Fire Wallet! 🚀',
|
2024-06-03 13:24:39 +10:00
|
|
|
style: theme.textTheme.titleLarge,
|
|
|
|
),
|
2024-06-03 13:04:05 +10:00
|
|
|
),
|
2024-06-03 13:24:39 +10:00
|
|
|
),
|
2024-06-03 13:04:05 +10:00
|
|
|
),
|
2024-06-03 13:24:39 +10:00
|
|
|
|
|
|
|
/// Notifications page
|
2024-06-03 13:40:27 +10:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
2024-06-03 13:24:39 +10:00
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Card(
|
2024-06-03 13:40:27 +10:00
|
|
|
child: Center(
|
|
|
|
child: Text(
|
|
|
|
// UUID of the user
|
|
|
|
'UUID: ${widget.uuid}',
|
|
|
|
))),
|
2024-06-03 13:24:39 +10:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
/// 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],
|
2024-06-03 13:04:05 +10:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|