ui: Fix background images not appearing
This commit is contained in:
parent
4e2761a7b8
commit
3daa290d64
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,14 @@ abstract class ConversationEvent {}
|
||||
class InitConversationEvent extends ConversationEvent {
|
||||
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.
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
@ -426,43 +426,64 @@ 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(
|
||||
fit: BoxFit.cover,
|
||||
image: FileImage(File(state.backgroundPath))
|
||||
)
|
||||
) :*/ null,
|
||||
child: 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();
|
||||
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,
|
||||
width: query.size.width,
|
||||
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>(
|
||||
buildWhen: (prev, next) => prev.messages != next.messages,
|
||||
builder: (context, state) => Expanded(
|
||||
child: ListView.builder(
|
||||
reverse: true,
|
||||
itemCount: state.messages.length,
|
||||
itemBuilder: (context, index) => _renderBubble(state, context, index, maxWidth),
|
||||
shrinkWrap: true
|
||||
)
|
||||
)
|
||||
),
|
||||
BlocBuilder<ConversationBloc, ConversationState>(
|
||||
buildWhen: (prev, next) => prev.messages != next.messages,
|
||||
builder: (context, state) => Expanded(
|
||||
child: ListView.builder(
|
||||
reverse: true,
|
||||
itemCount: state.messages.length,
|
||||
itemBuilder: (context, index) => _renderBubble(state, context, index, maxWidth),
|
||||
shrinkWrap: true
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
_ConversationBottomRow(_controller, _isSpeedDialOpen)
|
||||
]
|
||||
)
|
||||
)
|
||||
_ConversationBottomRow(_controller, _isSpeedDialOpen)
|
||||
]
|
||||
)
|
||||
)
|
||||
),
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -92,9 +92,14 @@ class BorderlessTopbar extends StatelessWidget implements PreferredSizeWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: child
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).backgroundColor,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: child
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user