ui: Fix background images not appearing

This commit is contained in:
PapaTutuWawa 2022-04-10 18:42:10 +02:00
parent 4e2761a7b8
commit 3daa290d64
6 changed files with 88 additions and 40 deletions

View File

@ -45,6 +45,7 @@ class ConversationBloc extends Bloc<ConversationEvent, ConversationState> {
on<MessageUpdatedEvent>(_onMessageUpdated);
on<ConversationUpdatedEvent>(_onConversationUpdated);
on<AppStateChanged>(_onAppStateChanged);
on<BackgroundChangedEvent>(_onBackgroundChanged);
}
void _setLastChangeTimestamp() {
@ -269,4 +270,8 @@ class ConversationBloc extends Bloc<ConversationEvent, ConversationState> {
_updateChatState(ChatState.gone);
}
}
Future<void> _onBackgroundChanged(BackgroundChangedEvent event, Emitter<ConversationState> emit) async {
return emit(state.copyWith(backgroundPath: event.backgroundPath));
}
}

View File

@ -9,6 +9,13 @@ class InitConversationEvent extends ConversationEvent {
InitConversationEvent(this.backgroundPath);
}
/// Triggered when the background image changed
class BackgroundChangedEvent extends ConversationEvent {
final String backgroundPath;
BackgroundChangedEvent(this.backgroundPath);
}
/// Triggered when the content of the input field changed.
class MessageTextChangedEvent extends ConversationEvent {
final String value;

View File

@ -1,3 +1,4 @@
import "package:moxxyv2/ui/bloc/conversation_bloc.dart";
import "package:moxxyv2/shared/preferences.dart";
import "package:moxxyv2/shared/commands.dart";
import "package:moxxyv2/shared/backgroundsender.dart";
@ -16,12 +17,19 @@ class PreferencesBloc extends Bloc<PreferencesEvent, PreferencesState> {
if (event.notify) {
GetIt.I.get<BackgroundServiceDataSender>().sendData(
SetPreferencesCommand(
preferences: state
preferences: event.preferences
),
awaitable: false
);
}
// Notify the conversation UI if we changed the background
if (event.preferences.backgroundPath != state.backgroundPath) {
GetIt.I.get<ConversationBloc>().add(
BackgroundChangedEvent(event.preferences.backgroundPath)
);
}
emit(event.preferences);
}
}

View File

@ -9,5 +9,7 @@ class PreferencesChangedEvent extends PreferencesEvent {
final PreferencesState preferences;
final bool notify;
PreferencesChangedEvent(this.preferences, { this.notify = true });
PreferencesChangedEvent(this.preferences, {
this.notify = true,
});
}

View File

@ -426,16 +426,35 @@ class _ConversationPageState extends State<ConversationPage> {
GetIt.I.get<ConversationBloc>().add(CurrentConversationResetEvent());
return true;
},
child: Scaffold(
appBar: BorderlessTopbar(_ConversationTopbarWidget()),
body: Container(
decoration: /*state.backgroundPath.isNotEmpty ? BoxDecoration(
image: DecorationImage(
child: Stack(
children: [
Positioned(
left: 0,
right: 0,
bottom: 0,
child: BlocBuilder<ConversationBloc, ConversationState>(
buildWhen: (prev, next) => prev.backgroundPath != next.backgroundPath,
builder: (context, state) {
final query = MediaQuery.of(context);
print(state.backgroundPath);
return Image.file(
File(state.backgroundPath),
fit: BoxFit.cover,
image: FileImage(File(state.backgroundPath))
width: query.size.width,
height: query.size.height - query.padding.top
);
}
)
) :*/ null,
child: Column(
),
Positioned(
left: 0,
right: 0,
top: 0,
bottom: 0,
child: Scaffold(
backgroundColor: Color.fromRGBO(0, 0, 0, 0),
appBar: BorderlessTopbar(_ConversationTopbarWidget()),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
BlocBuilder<ConversationBloc, ConversationState>(
@ -463,6 +482,8 @@ class _ConversationPageState extends State<ConversationPage> {
]
)
)
),
]
)
);
}

View File

@ -92,10 +92,15 @@ class BorderlessTopbar extends StatelessWidget implements PreferredSizeWidget {
@override
Widget build(BuildContext context) {
return SafeArea(
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).backgroundColor,
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: child
)
)
);
}
}