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});
|
const MyApp({super.key});
|
||||||
|
|
||||||
@override
|
@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> {
|
class HomeScreen extends StatefulWidget {
|
||||||
Future<void>? _prefsReady;
|
const HomeScreen({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
HomeScreenState createState() => HomeScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class HomeScreenState extends State<HomeScreen> {
|
||||||
|
late Future<void> _prefsReady;
|
||||||
bool isProfileActive = false;
|
bool isProfileActive = false;
|
||||||
bool showProfileInitially = false;
|
bool showProfileInitially = false;
|
||||||
|
|
||||||
@ -33,16 +61,11 @@ class MyAppState extends State<MyApp> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
// Retrieve SharedPreferencesProvider instance outside async function
|
|
||||||
final prefsProvider =
|
final prefsProvider =
|
||||||
Provider.of<SharedPreferencesProvider>(context, listen: false);
|
Provider.of<SharedPreferencesProvider>(context, listen: false);
|
||||||
_prefsReady = prefsProvider.ready;
|
_prefsReady = prefsProvider.ready.then((_) {
|
||||||
|
|
||||||
_prefsReady!.then((_) {
|
|
||||||
// Ensure the widget is still mounted before updating state
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
// Check if the username is not set, then show ProfileScreen initially
|
|
||||||
showProfileInitially = prefsProvider.getUserName().isEmpty;
|
showProfileInitially = prefsProvider.getUserName().isEmpty;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -50,73 +73,62 @@ class MyAppState extends State<MyApp> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void toggleProfileScreen() {
|
void toggleProfileScreen() {
|
||||||
setState(() {
|
setState(() => isProfileActive = !isProfileActive);
|
||||||
isProfileActive = !isProfileActive;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void closeInitialProfileScreen() {
|
void closeInitialProfileScreen() {
|
||||||
setState(() {
|
setState(() => showProfileInitially = false);
|
||||||
showProfileInitially = false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return FutureBuilder(
|
||||||
title: 'Pogdark',
|
future: _prefsReady,
|
||||||
theme: ThemeData(
|
builder: (context, snapshot) {
|
||||||
primarySwatch: Colors.blue,
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
visualDensity: VisualDensity.adaptivePlatformDensity,
|
return Stack(
|
||||||
elevatedButtonTheme: ElevatedButtonThemeData(
|
children: [
|
||||||
style: ElevatedButton.styleFrom(
|
StatusPage(toggleProfile: toggleProfileScreen),
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
if (showProfileInitially)
|
||||||
shape: RoundedRectangleBorder(
|
ProfileOverlay(
|
||||||
borderRadius: BorderRadius.circular(12),
|
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:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:web_socket_channel/web_socket_channel.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 final Stream<dynamic> broadcastStream;
|
||||||
late StreamController<dynamic> controller;
|
late StreamController<dynamic> controller;
|
||||||
List<Map<String, dynamic>> messages = [];
|
List<Map<String, dynamic>> messages = [];
|
||||||
final Map<String, ImageProvider> _imageCache = {}; // Cache for decoded images
|
final Map<String, ImageProvider> _imageCache = {};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -81,12 +80,12 @@ class StatusPageState extends State<StatusPage> {
|
|||||||
await prefsProvider.setCurrentStatus('');
|
await prefsProvider.setCurrentStatus('');
|
||||||
} else {
|
} else {
|
||||||
messages.add(message);
|
messages.add(message);
|
||||||
_cacheImage(incomingId, image); // Cache image on message receive
|
_cacheImage(incomingId, image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _cacheImage(String id, String? base64Image) {
|
void _cacheImage(String id, String? base64Image) {
|
||||||
if (base64Image != null && !_imageCache.containsKey(id)) {
|
if (base64Image != null) {
|
||||||
_imageCache[id] = Image.memory(base64Decode(base64Image)).image;
|
_imageCache[id] = Image.memory(base64Decode(base64Image)).image;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user