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

View File

@ -6,7 +6,14 @@ abstract class ConversationEvent {}
class InitConversationEvent extends ConversationEvent { class InitConversationEvent extends ConversationEvent {
final String backgroundPath; final String backgroundPath;
InitConversationEvent (this.backgroundPath); 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. /// Triggered when the content of the input field changed.

View File

@ -1,3 +1,4 @@
import "package:moxxyv2/ui/bloc/conversation_bloc.dart";
import "package:moxxyv2/shared/preferences.dart"; import "package:moxxyv2/shared/preferences.dart";
import "package:moxxyv2/shared/commands.dart"; import "package:moxxyv2/shared/commands.dart";
import "package:moxxyv2/shared/backgroundsender.dart"; import "package:moxxyv2/shared/backgroundsender.dart";
@ -16,12 +17,19 @@ class PreferencesBloc extends Bloc<PreferencesEvent, PreferencesState> {
if (event.notify) { if (event.notify) {
GetIt.I.get<BackgroundServiceDataSender>().sendData( GetIt.I.get<BackgroundServiceDataSender>().sendData(
SetPreferencesCommand( SetPreferencesCommand(
preferences: state preferences: event.preferences
), ),
awaitable: false 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); emit(event.preferences);
} }
} }

View File

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

View File

@ -426,43 +426,64 @@ class _ConversationPageState extends State<ConversationPage> {
GetIt.I.get<ConversationBloc>().add(CurrentConversationResetEvent()); GetIt.I.get<ConversationBloc>().add(CurrentConversationResetEvent());
return true; return true;
}, },
child: Scaffold( child: Stack(
appBar: BorderlessTopbar(_ConversationTopbarWidget()), children: [
body: Container( Positioned(
decoration: /*state.backgroundPath.isNotEmpty ? BoxDecoration( left: 0,
image: DecorationImage( right: 0,
fit: BoxFit.cover, bottom: 0,
image: FileImage(File(state.backgroundPath)) child: BlocBuilder<ConversationBloc, ConversationState>(
) buildWhen: (prev, next) => prev.backgroundPath != next.backgroundPath,
) :*/ null, builder: (context, state) {
child: Column( final query = MediaQuery.of(context);
crossAxisAlignment: CrossAxisAlignment.start, print(state.backgroundPath);
children: [ return Image.file(
BlocBuilder<ConversationBloc, ConversationState>( File(state.backgroundPath),
buildWhen: (prev, next) => prev.conversation?.inRoster != next.conversation?.inRoster, fit: BoxFit.cover,
builder: (context, state) { width: query.size.width,
if (state.conversation!.inRoster) return Container(); height: query.size.height - query.padding.top
);
}
)
),
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>(
buildWhen: (prev, next) => prev.conversation?.inRoster != next.conversation?.inRoster,
builder: (context, state) {
if (state.conversation!.inRoster) return Container();
return _renderNotInRosterWidget(state, context); return _renderNotInRosterWidget(state, context);
} }
), ),
BlocBuilder<ConversationBloc, ConversationState>( BlocBuilder<ConversationBloc, ConversationState>(
buildWhen: (prev, next) => prev.messages != next.messages, buildWhen: (prev, next) => prev.messages != next.messages,
builder: (context, state) => Expanded( builder: (context, state) => Expanded(
child: ListView.builder( child: ListView.builder(
reverse: true, reverse: true,
itemCount: state.messages.length, itemCount: state.messages.length,
itemBuilder: (context, index) => _renderBubble(state, context, index, maxWidth), itemBuilder: (context, index) => _renderBubble(state, context, index, maxWidth),
shrinkWrap: true shrinkWrap: true
) )
) )
), ),
_ConversationBottomRow(_controller, _isSpeedDialOpen) _ConversationBottomRow(_controller, _isSpeedDialOpen)
] ]
) )
) )
),
]
) )
); );
} }

View File

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