Update profile image in status after change
All checks were successful
Build Flutter Web and Docker Image for Local Registry / Build Flutter Web App (push) Successful in 3m10s
All checks were successful
Build Flutter Web and Docker Image for Local Registry / Build Flutter Web App (push) Successful in 3m10s
This commit is contained in:
parent
b8dd01fc37
commit
f475c69402
146
lib/main.dart
146
lib/main.dart
@ -17,15 +17,43 @@ void main() {
|
||||
);
|
||||
}
|
||||
|
||||
class MyApp extends StatefulWidget {
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
MyAppState createState() => MyAppState();
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Pogdark',
|
||||
theme: _buildTheme(),
|
||||
home: const HomeScreen(),
|
||||
);
|
||||
}
|
||||
|
||||
ThemeData _buildTheme() {
|
||||
return 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),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyAppState extends State<MyApp> {
|
||||
Future<void>? _prefsReady;
|
||||
class HomeScreen extends StatefulWidget {
|
||||
const HomeScreen({super.key});
|
||||
|
||||
@override
|
||||
HomeScreenState createState() => HomeScreenState();
|
||||
}
|
||||
|
||||
class HomeScreenState extends State<HomeScreen> {
|
||||
late Future<void> _prefsReady;
|
||||
bool isProfileActive = false;
|
||||
bool showProfileInitially = false;
|
||||
|
||||
@ -33,16 +61,11 @@ class MyAppState extends State<MyApp> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
// Retrieve SharedPreferencesProvider instance outside async function
|
||||
final prefsProvider =
|
||||
Provider.of<SharedPreferencesProvider>(context, listen: false);
|
||||
_prefsReady = prefsProvider.ready;
|
||||
|
||||
_prefsReady!.then((_) {
|
||||
// Ensure the widget is still mounted before updating state
|
||||
_prefsReady = prefsProvider.ready.then((_) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
// Check if the username is not set, then show ProfileScreen initially
|
||||
showProfileInitially = prefsProvider.getUserName().isEmpty;
|
||||
});
|
||||
}
|
||||
@ -50,73 +73,62 @@ class MyAppState extends State<MyApp> {
|
||||
}
|
||||
|
||||
void toggleProfileScreen() {
|
||||
setState(() {
|
||||
isProfileActive = !isProfileActive;
|
||||
});
|
||||
setState(() => isProfileActive = !isProfileActive);
|
||||
}
|
||||
|
||||
void closeInitialProfileScreen() {
|
||||
setState(() {
|
||||
showProfileInitially = false;
|
||||
});
|
||||
setState(() => showProfileInitially = false);
|
||||
}
|
||||
|
||||
@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),
|
||||
),
|
||||
return FutureBuilder(
|
||||
future: _prefsReady,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
return Stack(
|
||||
children: [
|
||||
StatusPage(toggleProfile: toggleProfileScreen),
|
||||
if (showProfileInitially)
|
||||
ProfileOverlay(
|
||||
isEditing: false,
|
||||
onClose: closeInitialProfileScreen,
|
||||
),
|
||||
if (isProfileActive && !showProfileInitially)
|
||||
ProfileOverlay(
|
||||
isEditing: true,
|
||||
onClose: toggleProfileScreen,
|
||||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ProfileOverlay extends StatelessWidget {
|
||||
final bool isEditing;
|
||||
final VoidCallback onClose;
|
||||
|
||||
const ProfileOverlay(
|
||||
{super.key, required this.isEditing, required this.onClose});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
|
||||
child: Container(
|
||||
color: Colors.black.withOpacity(0.3),
|
||||
child: Center(
|
||||
child: ProfileScreen(
|
||||
isEditing: isEditing,
|
||||
onClose: onClose,
|
||||
),
|
||||
),
|
||||
),
|
||||
home: FutureBuilder(
|
||||
future: _prefsReady,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
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,
|
||||
onClose: closeInitialProfileScreen,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
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,
|
||||
onClose: toggleProfileScreen,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||
@ -24,7 +23,7 @@ class StatusPageState extends State<StatusPage> {
|
||||
late final Stream<dynamic> broadcastStream;
|
||||
late StreamController<dynamic> controller;
|
||||
List<Map<String, dynamic>> messages = [];
|
||||
final Map<String, ImageProvider> _imageCache = {}; // Cache for decoded images
|
||||
final Map<String, ImageProvider> _imageCache = {};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -81,12 +80,12 @@ class StatusPageState extends State<StatusPage> {
|
||||
await prefsProvider.setCurrentStatus('');
|
||||
} else {
|
||||
messages.add(message);
|
||||
_cacheImage(incomingId, image); // Cache image on message receive
|
||||
_cacheImage(incomingId, image);
|
||||
}
|
||||
}
|
||||
|
||||
void _cacheImage(String id, String? base64Image) {
|
||||
if (base64Image != null && !_imageCache.containsKey(id)) {
|
||||
if (base64Image != null) {
|
||||
_imageCache[id] = Image.memory(base64Decode(base64Image)).image;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user