91 lines
3.5 KiB
Dart
91 lines
3.5 KiB
Dart
import 'package:cupertino_ui/cupertino_ui.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:material_ui/material_ui.dart' show SelectableText;
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:ttstd_family_care/core/widgets/cupertino_hint.dart';
|
|
import 'share_thumbnail.dart';
|
|
import '../../../core/widgets/app_page_scaffold.dart';
|
|
import '../../../l10n/app_localizations.dart';
|
|
import 'sharing_controller.dart';
|
|
|
|
class ReceivedSharePage extends ConsumerWidget {
|
|
const ReceivedSharePage({super.key});
|
|
Future<void> _open(BuildContext context, WidgetRef ref, String path) async {
|
|
final opened = await ref
|
|
.read(sharingControllerProvider.notifier)
|
|
.open(path);
|
|
if (!opened && context.mounted) {
|
|
final l10n = AppLocalizations.of(context);
|
|
showCupertinoHint(context, l10n.filesOpenFailed);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final inbox = ref.watch(sharingControllerProvider);
|
|
final l10n = AppLocalizations.of(context);
|
|
return AppPageScaffold(
|
|
navigationBar: CupertinoNavigationBar(
|
|
middle: Text(l10n.shareReceivedTitle),
|
|
),
|
|
child: SafeArea(
|
|
child: ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
Text(l10n.shareSavedHint),
|
|
if (inbox.importing)
|
|
const Padding(
|
|
padding: EdgeInsets.all(16),
|
|
child: CupertinoActivityIndicator(),
|
|
),
|
|
if (inbox.failed)
|
|
Text(
|
|
l10n.shareReceiveFailed,
|
|
style: const TextStyle(color: CupertinoColors.systemRed),
|
|
),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
for (final item in inbox.items.reversed)
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
if (item.type == 'image') shareThumbnail(item.path),
|
|
if (item.type == 'file' ||
|
|
item.type == 'video' ||
|
|
item.type == 'image')
|
|
Text(
|
|
Uri.file(item.path).pathSegments.last,
|
|
style: const TextStyle(fontWeight: FontWeight.w600),
|
|
),
|
|
if (item.type == 'text' || item.type == 'url')
|
|
SelectableText(item.path),
|
|
if (item.type != 'text' && item.type != 'url')
|
|
CupertinoButton(
|
|
onPressed: () => _open(context, ref, item.path),
|
|
child: Text(l10n.shareOpen),
|
|
),
|
|
if (item.message?.isNotEmpty == true)
|
|
SelectableText(item.message!),
|
|
if (item.type == 'text' || item.type == 'url')
|
|
CupertinoButton(
|
|
padding: EdgeInsets.zero,
|
|
onPressed: () => Clipboard.setData(
|
|
ClipboardData(text: item.path),
|
|
),
|
|
child: Text(l10n.shareCopy),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|