2026-03-11 20:51:56 +08:00
|
|
|
import 'package:flutter/material.dart' hide BackButton;
|
2026-03-27 14:05:03 +08:00
|
|
|
import 'package:social_app/core/l10n/l10n.dart';
|
2026-03-11 20:51:56 +08:00
|
|
|
|
2026-03-27 14:05:03 +08:00
|
|
|
import '../../../../app/di/injection.dart';
|
2026-03-11 20:51:56 +08:00
|
|
|
import '../../../../core/theme/design_tokens.dart';
|
|
|
|
|
import '../../../../shared/widgets/app_button.dart';
|
|
|
|
|
import '../../../../shared/widgets/toast/toast.dart';
|
|
|
|
|
import '../../../../shared/widgets/toast/toast_type.dart';
|
2026-03-29 20:26:30 +08:00
|
|
|
import '../../data/apis/calendar_api.dart';
|
2026-03-11 20:51:56 +08:00
|
|
|
|
|
|
|
|
class CalendarShareDialog extends StatefulWidget {
|
|
|
|
|
final String eventId;
|
|
|
|
|
final String eventTitle;
|
|
|
|
|
final bool canInvite;
|
|
|
|
|
final bool canEdit;
|
|
|
|
|
|
|
|
|
|
const CalendarShareDialog({
|
|
|
|
|
super.key,
|
|
|
|
|
required this.eventId,
|
|
|
|
|
required this.eventTitle,
|
|
|
|
|
this.canInvite = false,
|
|
|
|
|
this.canEdit = false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
static Future<void> show(
|
|
|
|
|
BuildContext context,
|
|
|
|
|
String eventId,
|
|
|
|
|
String eventTitle, {
|
|
|
|
|
bool canInvite = false,
|
|
|
|
|
bool canEdit = false,
|
|
|
|
|
}) {
|
|
|
|
|
return showModalBottomSheet(
|
|
|
|
|
context: context,
|
|
|
|
|
isScrollControlled: true,
|
2026-03-27 19:07:39 +08:00
|
|
|
backgroundColor: Theme.of(
|
|
|
|
|
context,
|
|
|
|
|
).colorScheme.surface.withValues(alpha: 0),
|
2026-03-11 20:51:56 +08:00
|
|
|
builder: (context) => CalendarShareDialog(
|
|
|
|
|
eventId: eventId,
|
|
|
|
|
eventTitle: eventTitle,
|
|
|
|
|
canInvite: canInvite,
|
|
|
|
|
canEdit: canEdit,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<CalendarShareDialog> createState() => _CalendarShareDialogState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _CalendarShareDialogState extends State<CalendarShareDialog> {
|
2026-03-19 18:43:08 +08:00
|
|
|
final _phoneController = TextEditingController();
|
2026-03-27 14:05:03 +08:00
|
|
|
final bool _permissionView = true;
|
2026-03-11 20:51:56 +08:00
|
|
|
bool _permissionEdit = false;
|
|
|
|
|
bool _permissionInvite = false;
|
|
|
|
|
bool _isLoading = false;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
2026-03-19 18:43:08 +08:00
|
|
|
_phoneController.dispose();
|
2026-03-11 20:51:56 +08:00
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _handleShare() async {
|
2026-03-27 14:05:03 +08:00
|
|
|
final l10n = context.l10n;
|
2026-03-19 18:43:08 +08:00
|
|
|
final phone = _phoneController.text.trim();
|
|
|
|
|
if (phone.isEmpty) {
|
2026-03-27 14:05:03 +08:00
|
|
|
Toast.show(
|
|
|
|
|
context,
|
|
|
|
|
l10n.calendarSharePhoneRequired,
|
|
|
|
|
type: ToastType.error,
|
|
|
|
|
);
|
2026-03-11 20:51:56 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setState(() => _isLoading = true);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
final api = sl<CalendarApi>();
|
|
|
|
|
await api.share(
|
|
|
|
|
widget.eventId,
|
2026-03-19 18:43:08 +08:00
|
|
|
phone: phone,
|
2026-03-11 20:51:56 +08:00
|
|
|
view: _permissionView,
|
|
|
|
|
edit: _permissionEdit,
|
|
|
|
|
invite: _permissionInvite,
|
|
|
|
|
);
|
|
|
|
|
if (mounted) {
|
2026-03-27 14:05:03 +08:00
|
|
|
Toast.show(
|
|
|
|
|
context,
|
|
|
|
|
l10n.calendarShareInviteSent,
|
|
|
|
|
type: ToastType.success,
|
|
|
|
|
);
|
2026-03-11 20:51:56 +08:00
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
if (mounted) {
|
2026-03-27 14:05:03 +08:00
|
|
|
Toast.show(
|
|
|
|
|
context,
|
|
|
|
|
l10n.calendarShareInviteFailed,
|
|
|
|
|
type: ToastType.error,
|
|
|
|
|
);
|
2026-03-11 20:51:56 +08:00
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
if (mounted) {
|
|
|
|
|
setState(() => _isLoading = false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2026-03-27 14:05:03 +08:00
|
|
|
final l10n = context.l10n;
|
2026-03-27 19:07:39 +08:00
|
|
|
final colorScheme = Theme.of(context).colorScheme;
|
2026-03-27 14:05:03 +08:00
|
|
|
|
2026-03-11 20:51:56 +08:00
|
|
|
return Container(
|
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
|
bottom: MediaQuery.of(context).viewInsets.bottom,
|
|
|
|
|
),
|
|
|
|
|
decoration: BoxDecoration(
|
2026-03-27 19:07:39 +08:00
|
|
|
color: colorScheme.surface,
|
2026-03-11 20:51:56 +08:00
|
|
|
borderRadius: const BorderRadius.vertical(
|
|
|
|
|
top: Radius.circular(AppRadius.lg),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: SafeArea(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(AppSpacing.lg),
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
2026-03-27 14:05:03 +08:00
|
|
|
Text(
|
|
|
|
|
l10n.calendarShareTitle,
|
2026-03-11 20:51:56 +08:00
|
|
|
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
|
|
|
|
|
),
|
|
|
|
|
IconButton(
|
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
|
icon: const Icon(Icons.close),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: AppSpacing.md),
|
|
|
|
|
Text(widget.eventTitle, style: const TextStyle(fontSize: 16)),
|
|
|
|
|
const SizedBox(height: AppSpacing.lg),
|
|
|
|
|
TextField(
|
2026-03-19 18:43:08 +08:00
|
|
|
controller: _phoneController,
|
2026-03-11 20:51:56 +08:00
|
|
|
decoration: InputDecoration(
|
2026-03-27 14:05:03 +08:00
|
|
|
labelText: l10n.calendarSharePhoneLabel,
|
|
|
|
|
hintText: l10n.calendarSharePhoneHint,
|
2026-03-11 20:51:56 +08:00
|
|
|
border: OutlineInputBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(AppRadius.md),
|
|
|
|
|
),
|
|
|
|
|
),
|
2026-03-19 18:43:08 +08:00
|
|
|
keyboardType: TextInputType.phone,
|
2026-03-11 20:51:56 +08:00
|
|
|
),
|
|
|
|
|
const SizedBox(height: AppSpacing.lg),
|
2026-03-27 14:05:03 +08:00
|
|
|
Text(
|
|
|
|
|
l10n.calendarSharePermissionTitle,
|
|
|
|
|
style: const TextStyle(fontWeight: FontWeight.w600),
|
|
|
|
|
),
|
2026-03-11 20:51:56 +08:00
|
|
|
const SizedBox(height: AppSpacing.sm),
|
|
|
|
|
_buildPermissionSwitch(
|
2026-03-27 14:05:03 +08:00
|
|
|
l10n.calendarSharePermissionView,
|
|
|
|
|
l10n.calendarSharePermissionViewDesc,
|
|
|
|
|
true,
|
|
|
|
|
null,
|
|
|
|
|
),
|
|
|
|
|
_buildPermissionSwitch(
|
|
|
|
|
l10n.calendarSharePermissionEdit,
|
|
|
|
|
l10n.calendarSharePermissionEditDesc,
|
2026-03-11 20:51:56 +08:00
|
|
|
_permissionEdit,
|
|
|
|
|
widget.canEdit
|
|
|
|
|
? (v) => setState(() => _permissionEdit = v)
|
|
|
|
|
: null,
|
|
|
|
|
),
|
|
|
|
|
_buildPermissionSwitch(
|
2026-03-27 14:05:03 +08:00
|
|
|
l10n.calendarSharePermissionInvite,
|
|
|
|
|
l10n.calendarSharePermissionInviteDesc,
|
2026-03-11 20:51:56 +08:00
|
|
|
_permissionInvite,
|
|
|
|
|
widget.canInvite
|
|
|
|
|
? (v) => setState(() => _permissionInvite = v)
|
|
|
|
|
: null,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: AppSpacing.lg),
|
|
|
|
|
AppButton(
|
2026-03-27 14:05:03 +08:00
|
|
|
text: l10n.calendarShareSendInvite,
|
2026-03-11 20:51:56 +08:00
|
|
|
onPressed: _isLoading ? null : _handleShare,
|
|
|
|
|
isLoading: _isLoading,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildPermissionSwitch(
|
|
|
|
|
String title,
|
|
|
|
|
String description,
|
|
|
|
|
bool value,
|
|
|
|
|
ValueChanged<bool>? onChanged,
|
|
|
|
|
) {
|
2026-03-27 19:07:39 +08:00
|
|
|
final colorScheme = Theme.of(context).colorScheme;
|
2026-03-11 20:51:56 +08:00
|
|
|
final enabled = onChanged != null;
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: AppSpacing.xs),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
title,
|
2026-03-27 19:07:39 +08:00
|
|
|
style: TextStyle(
|
|
|
|
|
color: enabled
|
|
|
|
|
? colorScheme.onSurface
|
|
|
|
|
: colorScheme.onSurfaceVariant,
|
|
|
|
|
),
|
2026-03-11 20:51:56 +08:00
|
|
|
),
|
|
|
|
|
Text(
|
|
|
|
|
description,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 12,
|
2026-03-27 19:07:39 +08:00
|
|
|
color: colorScheme.onSurfaceVariant,
|
2026-03-11 20:51:56 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Switch(value: value, onChanged: enabled ? onChanged : null),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|