Skip to content

Commit

Permalink
refactor: Make file dialog adaptive and adjust design
Browse files Browse the repository at this point in the history
  • Loading branch information
krille-chan committed Oct 29, 2023
1 parent 3ef9854 commit d1ce1e3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 40 deletions.
14 changes: 7 additions & 7 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class ChatController extends State<ChatPageWithRoom> {
);
}

await showDialog(
await showAdaptiveDialog(
context: context,
useRootNavigator: false,
builder: (c) => SendFileDialog(
Expand Down Expand Up @@ -490,7 +490,7 @@ class ChatController extends State<ChatPageWithRoom> {
),
);
if (result == null || result.files.isEmpty) return;
await showDialog(
await showAdaptiveDialog(
context: context,
useRootNavigator: false,
builder: (c) => SendFileDialog(
Expand All @@ -508,7 +508,7 @@ class ChatController extends State<ChatPageWithRoom> {
}

void sendImageFromClipBoard(Uint8List? image) async {
await showDialog(
await showAdaptiveDialog(
context: context,
useRootNavigator: false,
builder: (c) => SendFileDialog(
Expand All @@ -533,7 +533,7 @@ class ChatController extends State<ChatPageWithRoom> {
);
if (result == null || result.files.isEmpty) return;

await showDialog(
await showAdaptiveDialog(
context: context,
useRootNavigator: false,
builder: (c) => SendFileDialog(
Expand All @@ -556,7 +556,7 @@ class ChatController extends State<ChatPageWithRoom> {
final file = await ImagePicker().pickImage(source: ImageSource.camera);
if (file == null) return;
final bytes = await file.readAsBytes();
await showDialog(
await showAdaptiveDialog(
context: context,
useRootNavigator: false,
builder: (c) => SendFileDialog(
Expand All @@ -580,7 +580,7 @@ class ChatController extends State<ChatPageWithRoom> {
);
if (file == null) return;
final bytes = await file.readAsBytes();
await showDialog(
await showAdaptiveDialog(
context: context,
useRootNavigator: false,
builder: (c) => SendFileDialog(
Expand Down Expand Up @@ -688,7 +688,7 @@ class ChatController extends State<ChatPageWithRoom> {
}

void sendLocationAction() async {
await showDialog(
await showAdaptiveDialog(
context: context,
useRootNavigator: false,
builder: (c) => SendLocationDialog(room: room),
Expand Down
33 changes: 18 additions & 15 deletions lib/pages/chat/send_file_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:matrix/matrix.dart';

import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/utils/localized_exception_extension.dart';
import 'package:fluffychat/utils/size_string.dart';
import '../../utils/resize_image.dart';
Expand Down Expand Up @@ -84,29 +85,31 @@ class SendFileDialogState extends State<SendFileDialog> {
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Flexible(
child: Image.memory(
widget.files.first.bytes,
fit: BoxFit.contain,
child: Material(
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
elevation:
Theme.of(context).appBarTheme.scrolledUnderElevation ?? 4,
shadowColor: Theme.of(context).appBarTheme.shadowColor,
child: Image.memory(
widget.files.first.bytes,
fit: BoxFit.contain,
height: 256,
),
),
),
Row(
children: <Widget>[
Checkbox(
value: origImage,
onChanged: (v) => setState(() => origImage = v ?? false),
),
InkWell(
onTap: () => setState(() => origImage = !origImage),
child: Text('${L10n.of(context)!.sendOriginal} ($sizeString)'),
),
],
SwitchListTile.adaptive(
value: origImage,
contentPadding: EdgeInsets.zero,
onChanged: (v) => setState(() => origImage = v),
title: Text(L10n.of(context)!.sendOriginal),
subtitle: Text(sizeString),
),
],
);
} else {
contentWidget = Text('$fileName ($sizeString)');
}
return AlertDialog(
return AlertDialog.adaptive(
title: Text(sendStr),
content: contentWidget,
actions: <Widget>[
Expand Down
19 changes: 1 addition & 18 deletions lib/pages/chat/send_location_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:geolocator/geolocator.dart';
import 'package:matrix/matrix.dart';

import 'package:fluffychat/pages/chat/events/map_bubble.dart';
import 'package:fluffychat/utils/platform_infos.dart';

class SendLocationDialog extends StatefulWidget {
final Room room;
Expand Down Expand Up @@ -111,23 +110,7 @@ class SendLocationDialogState extends State<SendLocationDialog> {
],
);
}
if (PlatformInfos.isCupertinoStyle) {
return CupertinoAlertDialog(
title: Text(L10n.of(context)!.shareLocation),
content: contentWidget,
actions: [
CupertinoDialogAction(
onPressed: Navigator.of(context, rootNavigator: false).pop,
child: Text(L10n.of(context)!.cancel),
),
CupertinoDialogAction(
onPressed: isSending ? null : sendAction,
child: Text(L10n.of(context)!.send),
),
],
);
}
return AlertDialog(
return AlertDialog.adaptive(
title: Text(L10n.of(context)!.shareLocation),
content: contentWidget,
actions: [
Expand Down

0 comments on commit d1ce1e3

Please sign in to comment.