feat: 添加日历事件订阅者功能及权限重构
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import 'package:flutter/material.dart' hide BackButton;
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:social_app/core/l10n/l10n.dart';
|
||||
|
||||
import '../../../../app/di/injection.dart';
|
||||
import '../../../../data/models/dial_codes.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../../../shared/widgets/app_button.dart';
|
||||
import '../../../../shared/widgets/phone_prefix_selector.dart';
|
||||
import '../../../../shared/widgets/toast/toast.dart';
|
||||
import '../../../../shared/widgets/toast/toast_type.dart';
|
||||
import '../../data/apis/calendar_api.dart';
|
||||
@@ -50,6 +53,7 @@ class CalendarShareDialog extends StatefulWidget {
|
||||
|
||||
class _CalendarShareDialogState extends State<CalendarShareDialog> {
|
||||
final _phoneController = TextEditingController();
|
||||
String _dialCode = kDialCodes.first.value;
|
||||
final bool _permissionView = true;
|
||||
bool _permissionEdit = false;
|
||||
bool _permissionInvite = false;
|
||||
@@ -73,13 +77,14 @@ class _CalendarShareDialogState extends State<CalendarShareDialog> {
|
||||
return;
|
||||
}
|
||||
|
||||
final fullPhone = '$_dialCode$phone';
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
try {
|
||||
final api = sl<CalendarApi>();
|
||||
await api.share(
|
||||
widget.eventId,
|
||||
phone: phone,
|
||||
phone: fullPhone,
|
||||
view: _permissionView,
|
||||
edit: _permissionEdit,
|
||||
invite: _permissionInvite,
|
||||
@@ -147,14 +152,37 @@ class _CalendarShareDialogState extends State<CalendarShareDialog> {
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
TextField(
|
||||
controller: _phoneController,
|
||||
keyboardType: TextInputType.phone,
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.digitsOnly,
|
||||
LengthLimitingTextInputFormatter(14),
|
||||
],
|
||||
style: TextStyle(fontSize: 16, color: colorScheme.onSurface),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.calendarSharePhoneLabel,
|
||||
hintText: l10n.calendarSharePhoneHint,
|
||||
filled: true,
|
||||
fillColor: colorScheme.surface,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.lg,
|
||||
vertical: AppSpacing.lg,
|
||||
),
|
||||
prefixIcon: PhonePrefixSelector(
|
||||
value: _dialCode,
|
||||
onChanged: (value) => setState(() => _dialCode = value),
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||
borderSide: BorderSide(color: colorScheme.outlineVariant),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||
borderSide: BorderSide(color: colorScheme.primary),
|
||||
),
|
||||
),
|
||||
keyboardType: TextInputType.phone,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
Text(
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import 'package:social_app/core/l10n/l10n.dart';
|
||||
import '../../../../app/di/injection.dart';
|
||||
import '../../../../app/router/app_routes.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../../../shared/widgets/app_loading_indicator.dart';
|
||||
import '../../../../shared/widgets/app_selection_sheet.dart';
|
||||
@@ -215,7 +217,7 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
title: _isEditing
|
||||
? context.l10n.calendarCreateEditTitle
|
||||
: context.l10n.calendarCreateNewTitle,
|
||||
onBack: () => Navigator.of(context).pop(),
|
||||
onBack: () => _closeSheet(),
|
||||
trailing: ValueListenableBuilder<TextEditingValue>(
|
||||
valueListenable: _titleController,
|
||||
builder: (context, value, child) {
|
||||
@@ -264,7 +266,7 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
width: AppSpacing.xxl * 2,
|
||||
height: AppSpacing.xxl * 2,
|
||||
child: TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
onPressed: _closeSheet,
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.all(AppSpacing.none),
|
||||
shape: RoundedRectangleBorder(
|
||||
@@ -783,6 +785,8 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
metadata: metadata,
|
||||
);
|
||||
|
||||
var saved = false;
|
||||
|
||||
try {
|
||||
final service = sl<CalendarService>();
|
||||
|
||||
@@ -792,10 +796,9 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
await service.addEvent(event);
|
||||
}
|
||||
|
||||
saved = true;
|
||||
|
||||
widget.onSaved?.call();
|
||||
if (mounted) {
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
Toast.show(
|
||||
@@ -811,5 +814,29 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (saved && mounted) {
|
||||
_closeSheet(result: true);
|
||||
}
|
||||
}
|
||||
|
||||
void _closeSheet({Object? result}) {
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
final navigator = Navigator.of(context);
|
||||
if (navigator.canPop()) {
|
||||
navigator.pop(result);
|
||||
return;
|
||||
}
|
||||
|
||||
final router = GoRouter.of(context);
|
||||
if (router.canPop()) {
|
||||
context.pop(result);
|
||||
return;
|
||||
}
|
||||
|
||||
context.go(AppRoutes.homeMain);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user