🐛 Bug fixes and optimization

This commit is contained in:
2024-06-08 21:35:50 +08:00
parent e88a0ddb22
commit 6acbd1ee9e
34 changed files with 481 additions and 392 deletions

View File

@ -2,7 +2,6 @@ import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_background/flutter_background.dart';
import 'package:flutter_webrtc/flutter_webrtc.dart';
import 'package:get/get.dart';
import 'package:livekit_client/livekit_client.dart';
@ -171,35 +170,6 @@ class _ControlsWidgetState extends State<ControlsWidget> {
}
return;
}
if (lkPlatformIs(PlatformType.android)) {
requestBackgroundPermission([bool isRetry = false]) async {
try {
bool hasPermissions = await FlutterBackground.hasPermissions;
if (!isRetry) {
const androidConfig = FlutterBackgroundAndroidConfig(
notificationTitle: 'Screen Sharing',
notificationText: 'Solar Messager is sharing your screen',
notificationImportance: AndroidNotificationImportance.Default,
notificationIcon:
AndroidResource(name: 'launcher_icon', defType: 'mipmap'),
);
hasPermissions = await FlutterBackground.initialize(
androidConfig: androidConfig);
}
if (hasPermissions &&
!FlutterBackground.isBackgroundExecutionEnabled) {
await FlutterBackground.enableBackgroundExecution();
}
} catch (e) {
if (!isRetry) {
return await Future<void>.delayed(const Duration(seconds: 1),
() => requestBackgroundPermission(true));
}
}
}
await requestBackgroundPermission();
}
if (lkPlatformIs(PlatformType.iOS)) {
var track = await LocalVideoTrack.createScreenShareTrack(
const ScreenShareCaptureOptions(
@ -223,12 +193,6 @@ class _ControlsWidgetState extends State<ControlsWidget> {
void disableScreenShare() async {
await participant.setScreenShareEnabled(false);
if (lkPlatformIs(PlatformType.android)) {
// Android specific
try {
await FlutterBackground.disableBackgroundExecution();
} catch (_) {}
}
}
@override

View File

@ -56,7 +56,7 @@ class _ChatMessageInputState extends State<ChatMessageInput> {
Map<String, dynamic> encodeMessage(String content) {
return {
'value': content,
'value': content.trim(),
'keypair_id': null,
'algorithm': 'plain',
};
@ -103,9 +103,11 @@ class _ChatMessageInputState extends State<ChatMessageInput> {
senderId: sender.id,
);
message.isSending = true;
if (_editTo == null) {
message.isSending = true;
widget.onSent(message);
}
if (widget.edit == null) widget.onSent(message);
resetInput();
Response resp;
@ -131,6 +133,7 @@ class _ChatMessageInputState extends State<ChatMessageInput> {
_editTo = null;
_replyTo = null;
_textController.clear();
_attachments.clear();
setState(() {});
}
@ -161,70 +164,66 @@ class _ChatMessageInputState extends State<ChatMessageInput> {
)
];
return Material(
color: Theme.of(context).colorScheme.surface,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Divider(thickness: 0.3, height: 1),
if (_replyTo != null)
MaterialBanner(
leading: const FaIcon(FontAwesomeIcons.reply, size: 18),
dividerColor: Colors.transparent,
content: ChatMessage(
item: _replyTo!,
isContentPreviewing: true,
),
actions: notifyBannerActions,
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (_replyTo != null)
MaterialBanner(
leading: const FaIcon(FontAwesomeIcons.reply, size: 18),
dividerColor: Colors.transparent,
content: ChatMessage(
item: _replyTo!,
isContentPreviewing: true,
),
if (_editTo != null)
MaterialBanner(
leading: const Icon(Icons.edit),
dividerColor: Colors.transparent,
content: ChatMessage(
item: _editTo!,
isContentPreviewing: true,
),
actions: notifyBannerActions,
),
SizedBox(
height: 56,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: TextField(
controller: _textController,
focusNode: _focusNode,
maxLines: null,
autocorrect: true,
keyboardType: TextInputType.text,
decoration: InputDecoration.collapsed(
hintText: widget.placeholder ??
'messageInputPlaceholder'.trParams(
{'channel': '#${widget.channel.alias}'},
),
),
onSubmitted: (_) => sendMessage(),
onTapOutside: (_) =>
FocusManager.instance.primaryFocus?.unfocus(),
),
),
IconButton(
icon: const Icon(Icons.attach_file),
color: Colors.teal,
onPressed: () => showAttachments(),
),
IconButton(
icon: const Icon(Icons.send),
color: Theme.of(context).colorScheme.primary,
onPressed: () => sendMessage(),
)
],
).paddingOnly(left: 20, right: 16),
actions: notifyBannerActions,
),
],
),
if (_editTo != null)
MaterialBanner(
leading: const Icon(Icons.edit),
dividerColor: Colors.transparent,
content: ChatMessage(
item: _editTo!,
isContentPreviewing: true,
),
actions: notifyBannerActions,
),
SizedBox(
height: 56,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: TextField(
controller: _textController,
focusNode: _focusNode,
maxLines: null,
autocorrect: true,
keyboardType: TextInputType.text,
decoration: InputDecoration.collapsed(
hintText: widget.placeholder ??
'messageInputPlaceholder'.trParams(
{'channel': '#${widget.channel.alias}'},
),
),
onSubmitted: (_) => sendMessage(),
onTapOutside: (_) =>
FocusManager.instance.primaryFocus?.unfocus(),
),
),
IconButton(
icon: const Icon(Icons.attach_file),
color: Colors.teal,
onPressed: () => showAttachments(),
),
IconButton(
icon: const Icon(Icons.send),
color: Theme.of(context).colorScheme.primary,
onPressed: () => sendMessage(),
)
],
).paddingOnly(left: 20, right: 16),
),
],
);
}
}