2024-11-10 01:19:14 +00:00
|
|
|
import 'dart:async';
|
2024-11-10 03:50:56 +00:00
|
|
|
import 'dart:ui';
|
2024-11-10 01:19:14 +00:00
|
|
|
|
2024-11-05 18:05:16 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
2024-11-10 01:19:14 +00:00
|
|
|
|
|
|
|
import 'profile_screen.dart';
|
|
|
|
import 'shared_preferences_provider.dart';
|
|
|
|
import 'status_page.dart';
|
2024-11-05 18:05:16 +00:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
runApp(
|
|
|
|
ChangeNotifierProvider(
|
|
|
|
create: (_) => SharedPreferencesProvider(),
|
|
|
|
child: const MyApp(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatefulWidget {
|
|
|
|
const MyApp({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
MyAppState createState() => MyAppState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyAppState extends State<MyApp> {
|
|
|
|
Future<void>? _prefsReady;
|
2024-11-10 03:50:56 +00:00
|
|
|
bool isProfileActive = false;
|
|
|
|
bool showProfileInitially = false;
|
2024-11-05 18:05:16 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2024-11-10 04:19:59 +00:00
|
|
|
|
|
|
|
// Retrieve SharedPreferencesProvider instance outside async function
|
|
|
|
final prefsProvider =
|
|
|
|
Provider.of<SharedPreferencesProvider>(context, listen: false);
|
|
|
|
_prefsReady = prefsProvider.ready;
|
|
|
|
|
2024-11-10 03:50:56 +00:00
|
|
|
_prefsReady!.then((_) {
|
2024-11-10 04:19:59 +00:00
|
|
|
// Ensure the widget is still mounted before updating state
|
|
|
|
if (mounted) {
|
2024-11-10 03:50:56 +00:00
|
|
|
setState(() {
|
2024-11-10 04:19:59 +00:00
|
|
|
// Check if the username is not set, then show ProfileScreen initially
|
|
|
|
showProfileInitially = prefsProvider.getUserName().isEmpty;
|
2024-11-10 03:50:56 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void toggleProfileScreen() {
|
|
|
|
setState(() {
|
|
|
|
isProfileActive = !isProfileActive;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void closeInitialProfileScreen() {
|
|
|
|
setState(() {
|
|
|
|
showProfileInitially = false;
|
|
|
|
});
|
2024-11-05 18:05:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
|
|
|
title: 'Pogdark',
|
|
|
|
theme: ThemeData(
|
|
|
|
primarySwatch: Colors.blue,
|
|
|
|
visualDensity: VisualDensity.adaptivePlatformDensity,
|
|
|
|
elevatedButtonTheme: ElevatedButtonThemeData(
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
home: FutureBuilder(
|
|
|
|
future: _prefsReady,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.connectionState == ConnectionState.done) {
|
2024-11-10 03:50:56 +00:00
|
|
|
return Stack(
|
|
|
|
children: [
|
|
|
|
StatusPage(toggleProfile: toggleProfileScreen),
|
|
|
|
if (showProfileInitially)
|
|
|
|
BackdropFilter(
|
|
|
|
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
|
|
|
|
child: Container(
|
|
|
|
color: Colors.black.withOpacity(0.3),
|
|
|
|
child: Center(
|
|
|
|
child: ProfileScreen(
|
|
|
|
isEditing: false,
|
2024-11-10 04:19:59 +00:00
|
|
|
onClose: closeInitialProfileScreen,
|
2024-11-10 03:50:56 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (isProfileActive && !showProfileInitially)
|
|
|
|
BackdropFilter(
|
|
|
|
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
|
|
|
|
child: Container(
|
|
|
|
color: Colors.black.withOpacity(0.3),
|
|
|
|
child: Center(
|
|
|
|
child: ProfileScreen(
|
|
|
|
isEditing: true,
|
2024-11-10 04:19:59 +00:00
|
|
|
onClose: toggleProfileScreen,
|
2024-11-10 03:50:56 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
2024-11-05 18:05:16 +00:00
|
|
|
} else {
|
|
|
|
return const Center(child: CircularProgressIndicator());
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|