feat(apps): 重构 UI 架构为 presentation 层并新增 l10n 国际化支持
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
|
||||
enum DockTab { todo, calendar }
|
||||
|
||||
class BottomDock extends StatelessWidget {
|
||||
final DockTab activeTab;
|
||||
final VoidCallback? onTodoTap;
|
||||
final VoidCallback? onCalendarTap;
|
||||
final VoidCallback? onHomeTap;
|
||||
|
||||
const BottomDock({
|
||||
super.key,
|
||||
required this.activeTab,
|
||||
this.onTodoTap,
|
||||
this.onCalendarTap,
|
||||
this.onHomeTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
height: 72,
|
||||
padding: const EdgeInsets.only(
|
||||
left: AppSpacing.xl,
|
||||
right: AppSpacing.xl,
|
||||
top: AppSpacing.md,
|
||||
bottom: AppSpacing.sm,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [_buildToggle(), _buildHomeBtn()],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildToggle() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.todoToggleBg,
|
||||
borderRadius: BorderRadius.circular(AppRadius.xxl),
|
||||
border: Border.all(color: AppColors.todoToggleBorder),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.slate200.withValues(alpha: 0.45),
|
||||
blurRadius: AppRadius.sm,
|
||||
offset: const Offset(0, AppSpacing.xs / 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
_buildToggleItem(
|
||||
icon: LucideIcons.listTodo,
|
||||
isActive: activeTab == DockTab.todo,
|
||||
onTap: onTodoTap,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
_buildToggleItem(
|
||||
icon: LucideIcons.calendar,
|
||||
isActive: activeTab == DockTab.calendar,
|
||||
onTap: onCalendarTap,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildToggleItem({
|
||||
required IconData icon,
|
||||
required bool isActive,
|
||||
VoidCallback? onTap,
|
||||
}) {
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 140),
|
||||
curve: Curves.easeOut,
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: isActive ? AppColors.todoToggleActiveBg : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
border: Border.all(
|
||||
color: isActive
|
||||
? AppColors.todoToggleActiveBorder
|
||||
: Colors.transparent,
|
||||
),
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
size: 20,
|
||||
color: isActive ? AppColors.blue600 : AppColors.slate700,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHomeBtn() {
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
key: const ValueKey('bottom_dock_home_button'),
|
||||
onTap: onHomeTap,
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
child: Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.todoToggleBg,
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
border: Border.all(color: AppColors.todoToggleBorder),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.slate200.withValues(alpha: 0.42),
|
||||
blurRadius: AppRadius.sm,
|
||||
offset: const Offset(0, AppSpacing.xs / 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
LucideIcons.home,
|
||||
size: 20,
|
||||
color: AppColors.slate700,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
import 'package:flutter/material.dart' hide BackButton;
|
||||
import 'package:social_app/core/l10n/l10n.dart';
|
||||
|
||||
import '../../../../app/di/injection.dart';
|
||||
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';
|
||||
import '../../data/calendar_api.dart';
|
||||
|
||||
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,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (context) => CalendarShareDialog(
|
||||
eventId: eventId,
|
||||
eventTitle: eventTitle,
|
||||
canInvite: canInvite,
|
||||
canEdit: canEdit,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
State<CalendarShareDialog> createState() => _CalendarShareDialogState();
|
||||
}
|
||||
|
||||
class _CalendarShareDialogState extends State<CalendarShareDialog> {
|
||||
final _phoneController = TextEditingController();
|
||||
final bool _permissionView = true;
|
||||
bool _permissionEdit = false;
|
||||
bool _permissionInvite = false;
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_phoneController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _handleShare() async {
|
||||
final l10n = context.l10n;
|
||||
final phone = _phoneController.text.trim();
|
||||
if (phone.isEmpty) {
|
||||
Toast.show(
|
||||
context,
|
||||
l10n.calendarSharePhoneRequired,
|
||||
type: ToastType.error,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
try {
|
||||
final api = sl<CalendarApi>();
|
||||
await api.share(
|
||||
widget.eventId,
|
||||
phone: phone,
|
||||
view: _permissionView,
|
||||
edit: _permissionEdit,
|
||||
invite: _permissionInvite,
|
||||
);
|
||||
if (mounted) {
|
||||
Toast.show(
|
||||
context,
|
||||
l10n.calendarShareInviteSent,
|
||||
type: ToastType.success,
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
Toast.show(
|
||||
context,
|
||||
l10n.calendarShareInviteFailed,
|
||||
type: ToastType.error,
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() => _isLoading = false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
|
||||
return Container(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context).viewInsets.bottom,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.background,
|
||||
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: [
|
||||
Text(
|
||||
l10n.calendarShareTitle,
|
||||
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(
|
||||
controller: _phoneController,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.calendarSharePhoneLabel,
|
||||
hintText: l10n.calendarSharePhoneHint,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
),
|
||||
),
|
||||
keyboardType: TextInputType.phone,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
Text(
|
||||
l10n.calendarSharePermissionTitle,
|
||||
style: const TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_buildPermissionSwitch(
|
||||
l10n.calendarSharePermissionView,
|
||||
l10n.calendarSharePermissionViewDesc,
|
||||
true,
|
||||
null,
|
||||
),
|
||||
_buildPermissionSwitch(
|
||||
l10n.calendarSharePermissionEdit,
|
||||
l10n.calendarSharePermissionEditDesc,
|
||||
_permissionEdit,
|
||||
widget.canEdit
|
||||
? (v) => setState(() => _permissionEdit = v)
|
||||
: null,
|
||||
),
|
||||
_buildPermissionSwitch(
|
||||
l10n.calendarSharePermissionInvite,
|
||||
l10n.calendarSharePermissionInviteDesc,
|
||||
_permissionInvite,
|
||||
widget.canInvite
|
||||
? (v) => setState(() => _permissionInvite = v)
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
AppButton(
|
||||
text: l10n.calendarShareSendInvite,
|
||||
onPressed: _isLoading ? null : _handleShare,
|
||||
isLoading: _isLoading,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPermissionSwitch(
|
||||
String title,
|
||||
String description,
|
||||
bool value,
|
||||
ValueChanged<bool>? onChanged,
|
||||
) {
|
||||
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,
|
||||
style: TextStyle(color: enabled ? null : Colors.grey),
|
||||
),
|
||||
Text(
|
||||
description,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: enabled ? Colors.grey : Colors.grey.shade400,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Switch(value: value, onChanged: enabled ? onChanged : null),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,809 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import 'package:social_app/core/l10n/l10n.dart';
|
||||
import '../../../../app/di/injection.dart';
|
||||
import '../../../../features/notification/data/services/local_notification_service.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../../../shared/widgets/app_loading_indicator.dart';
|
||||
import '../../../../shared/widgets/app_selection_sheet.dart';
|
||||
import '../../../../shared/widgets/app_sheet_input_field.dart';
|
||||
import '../../../../shared/widgets/back_title_page_header.dart';
|
||||
import '../../../../shared/widgets/toast/toast.dart';
|
||||
import '../../../../shared/widgets/toast/toast_type.dart';
|
||||
import 'date_time_picker_sheet.dart';
|
||||
import '../../data/models/schedule_item_model.dart';
|
||||
import '../../data/services/calendar_service.dart';
|
||||
|
||||
class CreateEventSheet extends StatefulWidget {
|
||||
final DateTime? initialDate;
|
||||
final ScheduleItemModel? editingEvent;
|
||||
final VoidCallback? onSaved;
|
||||
final bool pageMode;
|
||||
|
||||
const CreateEventSheet({
|
||||
super.key,
|
||||
this.initialDate,
|
||||
this.editingEvent,
|
||||
this.onSaved,
|
||||
this.pageMode = false,
|
||||
});
|
||||
|
||||
static Future<void> show(
|
||||
BuildContext context, {
|
||||
DateTime? initialDate,
|
||||
VoidCallback? onSaved,
|
||||
}) {
|
||||
return showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (context) =>
|
||||
CreateEventSheet(initialDate: initialDate, onSaved: onSaved),
|
||||
);
|
||||
}
|
||||
|
||||
static Future<void> edit(
|
||||
BuildContext context,
|
||||
ScheduleItemModel event, {
|
||||
VoidCallback? onSaved,
|
||||
}) {
|
||||
return showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (context) =>
|
||||
CreateEventSheet(editingEvent: event, onSaved: onSaved),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
State<CreateEventSheet> createState() => _CreateEventSheetState();
|
||||
}
|
||||
|
||||
class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
with SingleTickerProviderStateMixin {
|
||||
static const List<int?> _defaultReminderOptions = [
|
||||
null,
|
||||
0,
|
||||
5,
|
||||
10,
|
||||
15,
|
||||
30,
|
||||
60,
|
||||
120,
|
||||
];
|
||||
|
||||
late TabController _tabController;
|
||||
final _titleController = TextEditingController();
|
||||
final _descriptionController = TextEditingController();
|
||||
final _locationController = TextEditingController();
|
||||
final _notesController = TextEditingController();
|
||||
|
||||
late DateTime _startDate;
|
||||
late DateTime _startTime;
|
||||
DateTime? _endDate;
|
||||
DateTime? _endTime;
|
||||
String _selectedColor = '#3B82F6';
|
||||
int? _reminderMinutes = 15;
|
||||
bool _saving = false;
|
||||
|
||||
bool get _isEditing => widget.editingEvent != null;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: 2, vsync: this);
|
||||
|
||||
if (_isEditing) {
|
||||
final event = widget.editingEvent!;
|
||||
_titleController.text = event.title;
|
||||
_descriptionController.text = event.description ?? '';
|
||||
_locationController.text = event.metadata?.location ?? '';
|
||||
_notesController.text = event.metadata?.notes ?? '';
|
||||
_startDate = event.startAt;
|
||||
_startTime = event.startAt;
|
||||
_endDate = event.endAt;
|
||||
_endTime = event.endAt;
|
||||
_selectedColor = event.metadata?.color ?? '#3B82F6';
|
||||
_reminderMinutes = _sanitizeReminderMinutes(
|
||||
event.metadata?.reminderMinutes,
|
||||
);
|
||||
} else {
|
||||
final now = DateTime.now();
|
||||
final initial = widget.initialDate;
|
||||
final rounded = _roundToNearestMinute(now, 5);
|
||||
_startDate = initial != null
|
||||
? DateTime(
|
||||
initial.year,
|
||||
initial.month,
|
||||
initial.day,
|
||||
rounded.hour,
|
||||
rounded.minute,
|
||||
)
|
||||
: rounded;
|
||||
_startTime = _startDate;
|
||||
_endDate = _startDate;
|
||||
_endTime = _startDate.add(const Duration(hours: 1));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
_titleController.dispose();
|
||||
_descriptionController.dispose();
|
||||
_locationController.dispose();
|
||||
_notesController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
DateTime _roundToNearestMinute(DateTime dt, int interval) {
|
||||
final totalMinutes = dt.hour * 60 + dt.minute;
|
||||
final rounded = ((totalMinutes / interval).round() * interval);
|
||||
final hours = rounded ~/ 60;
|
||||
final minutes = rounded % 60;
|
||||
final dayOffset = hours >= 24 ? 1 : 0;
|
||||
final newHour = hours % 24;
|
||||
return DateTime(dt.year, dt.month, dt.day + dayOffset, newHour, minutes);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (widget.pageMode) {
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onTap: () => FocusScope.of(context).unfocus(),
|
||||
child: Container(
|
||||
color: AppColors.background,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildPageHeader(),
|
||||
_buildTabBar(),
|
||||
Expanded(child: _buildTabContent()),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return AnimatedPadding(
|
||||
duration: const Duration(milliseconds: 150),
|
||||
curve: Curves.easeOut,
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context).viewInsets.bottom,
|
||||
),
|
||||
child: Container(
|
||||
height: MediaQuery.of(context).size.height * 0.85,
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Center(
|
||||
child: Container(
|
||||
width: AppSpacing.xl + AppSpacing.sm,
|
||||
height: AppSpacing.xs,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.slate200,
|
||||
borderRadius: BorderRadius.circular(AppRadius.full),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_buildHeader(),
|
||||
_buildTabBar(),
|
||||
Expanded(child: _buildTabContent()),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPageHeader() {
|
||||
return BackTitlePageHeader(
|
||||
title: _isEditing
|
||||
? context.l10n.calendarCreateEditTitle
|
||||
: context.l10n.calendarCreateNewTitle,
|
||||
onBack: () => Navigator.of(context).pop(),
|
||||
trailing: ValueListenableBuilder<TextEditingValue>(
|
||||
valueListenable: _titleController,
|
||||
builder: (context, value, child) {
|
||||
final enabled = value.text.trim().isNotEmpty && !_saving;
|
||||
return SizedBox(
|
||||
height: AppSpacing.xxl * 2,
|
||||
child: TextButton(
|
||||
onPressed: enabled ? _saveEvent : null,
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.md),
|
||||
minimumSize: const Size(AppSpacing.none, AppSpacing.none),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
child: _saving
|
||||
? const AppLoadingIndicator(
|
||||
variant: AppLoadingVariant.button,
|
||||
size: 18,
|
||||
trackColor: AppColors.blue200,
|
||||
)
|
||||
: Text(
|
||||
context.l10n.commonSave,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: enabled ? AppColors.blue600 : AppColors.slate400,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeader() {
|
||||
return Container(
|
||||
height: 56,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: AppSpacing.xxl * 2,
|
||||
height: AppSpacing.xxl * 2,
|
||||
child: TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.all(AppSpacing.none),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(AppRadius.full),
|
||||
),
|
||||
),
|
||||
child: const Icon(
|
||||
LucideIcons.x,
|
||||
size: AppSpacing.xxl,
|
||||
color: AppColors.slate700,
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
_isEditing
|
||||
? context.l10n.calendarCreateEditTitle
|
||||
: context.l10n.calendarCreateNewTitle,
|
||||
style: const TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate900,
|
||||
),
|
||||
),
|
||||
ValueListenableBuilder<TextEditingValue>(
|
||||
valueListenable: _titleController,
|
||||
builder: (context, value, child) {
|
||||
final enabled = value.text.trim().isNotEmpty && !_saving;
|
||||
return SizedBox(
|
||||
height: AppSpacing.xxl * 2,
|
||||
child: TextButton(
|
||||
onPressed: enabled ? _saveEvent : null,
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
),
|
||||
minimumSize: const Size(AppSpacing.none, AppSpacing.none),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
child: _saving
|
||||
? const AppLoadingIndicator(
|
||||
variant: AppLoadingVariant.button,
|
||||
size: 18,
|
||||
trackColor: AppColors.blue200,
|
||||
)
|
||||
: Text(
|
||||
context.l10n.commonSave,
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: enabled
|
||||
? AppColors.blue600
|
||||
: AppColors.slate400,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTabBar() {
|
||||
return Container(
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: AppColors.border)),
|
||||
),
|
||||
child: TabBar(
|
||||
controller: _tabController,
|
||||
labelColor: AppColors.blue600,
|
||||
unselectedLabelColor: AppColors.slate600,
|
||||
indicatorColor: AppColors.blue600,
|
||||
tabs: [
|
||||
Tab(text: context.l10n.calendarCreateTabBasic),
|
||||
Tab(text: context.l10n.calendarCreateTabAdvanced),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTabContent() {
|
||||
return TabBarView(
|
||||
controller: _tabController,
|
||||
children: [_buildBasicTab(), _buildAdvancedTab()],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBasicTab() {
|
||||
return SingleChildScrollView(
|
||||
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildTextField(
|
||||
context.l10n.calendarCreateFieldTitle,
|
||||
_titleController,
|
||||
context.l10n.calendarCreateFieldTitleHint,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_buildDateTimePicker(
|
||||
context.l10n.calendarCreateFieldStart,
|
||||
_startDate,
|
||||
_startTime,
|
||||
(date, time) {
|
||||
setState(() {
|
||||
_startDate = date;
|
||||
_startTime = time;
|
||||
if (_endDate != null && _endTime != null) {
|
||||
final endDateTime = DateTime(
|
||||
_endDate!.year,
|
||||
_endDate!.month,
|
||||
_endDate!.day,
|
||||
_endTime!.hour,
|
||||
_endTime!.minute,
|
||||
);
|
||||
final startDateTime = DateTime(
|
||||
date.year,
|
||||
date.month,
|
||||
date.day,
|
||||
time.hour,
|
||||
time.minute,
|
||||
);
|
||||
if (endDateTime.isBefore(startDateTime) ||
|
||||
endDateTime.isAtSameMomentAs(startDateTime)) {
|
||||
_endDate = date;
|
||||
_endTime = time.add(const Duration(hours: 1));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_buildDateTimePicker(
|
||||
context.l10n.calendarCreateFieldEnd,
|
||||
_endDate ?? _startDate,
|
||||
_endTime ?? _startTime,
|
||||
(date, time) {
|
||||
setState(() {
|
||||
final startDateTime = DateTime(
|
||||
_startDate.year,
|
||||
_startDate.month,
|
||||
_startDate.day,
|
||||
_startTime.hour,
|
||||
_startTime.minute,
|
||||
);
|
||||
final endDateTime = DateTime(
|
||||
date.year,
|
||||
date.month,
|
||||
date.day,
|
||||
time.hour,
|
||||
time.minute,
|
||||
);
|
||||
if (endDateTime.isBefore(startDateTime) ||
|
||||
endDateTime.isAtSameMomentAs(startDateTime)) {
|
||||
_endDate = _startDate;
|
||||
_endTime = _startTime.add(const Duration(hours: 1));
|
||||
} else {
|
||||
_endDate = date;
|
||||
_endTime = time;
|
||||
}
|
||||
});
|
||||
},
|
||||
isOptional: true,
|
||||
minTime: DateTime(
|
||||
_startDate.year,
|
||||
_startDate.month,
|
||||
_startDate.day,
|
||||
_startTime.hour,
|
||||
_startTime.minute,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAdvancedTab() {
|
||||
return SingleChildScrollView(
|
||||
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildTextField(
|
||||
context.l10n.calendarCreateFieldDescription,
|
||||
_descriptionController,
|
||||
context.l10n.calendarCreateFieldDescriptionHint,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_buildTextField(
|
||||
context.l10n.calendarCreateFieldLocation,
|
||||
_locationController,
|
||||
context.l10n.calendarCreateFieldLocationHint,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_buildReminderPicker(),
|
||||
const SizedBox(height: 20),
|
||||
_buildColorPicker(),
|
||||
const SizedBox(height: 20),
|
||||
_buildTextField(
|
||||
context.l10n.calendarDetailNotes,
|
||||
_notesController,
|
||||
context.l10n.calendarCreateFieldNotesHint,
|
||||
maxLines: 3,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTextField(
|
||||
String label,
|
||||
TextEditingController controller,
|
||||
String hint, {
|
||||
int maxLines = 1,
|
||||
bool autofocus = false,
|
||||
}) {
|
||||
return AppSheetInputField(
|
||||
controller: controller,
|
||||
label: label,
|
||||
hint: hint,
|
||||
maxLines: maxLines,
|
||||
autofocus: autofocus,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDateTimePicker(
|
||||
String label,
|
||||
DateTime date,
|
||||
DateTime time,
|
||||
Function(DateTime, DateTime) onChanged, {
|
||||
bool isOptional = false,
|
||||
DateTime? minTime,
|
||||
}) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
isOptional ? context.l10n.calendarCreateOptionalField(label) : label,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
final picked = await _pickDateTime(date, time, minTime: minTime);
|
||||
if (picked == null) {
|
||||
return;
|
||||
}
|
||||
onChanged(picked.$1, picked.$2);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.slate50,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
LucideIcons.calendar,
|
||||
size: 16,
|
||||
color: AppColors.slate600,
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_formatDateTimeLabel(date, time),
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.slate900,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
LucideIcons.chevronRight,
|
||||
size: 16,
|
||||
color: AppColors.slate400,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String _formatDateTimeLabel(DateTime date, DateTime time) {
|
||||
return context.l10n.calendarCreateDateTimeLabel(
|
||||
date.year,
|
||||
date.month,
|
||||
date.day,
|
||||
time.hour.toString().padLeft(2, '0'),
|
||||
time.minute.toString().padLeft(2, '0'),
|
||||
);
|
||||
}
|
||||
|
||||
Future<(DateTime, DateTime)?> _pickDateTime(
|
||||
DateTime date,
|
||||
DateTime time, {
|
||||
DateTime? minTime,
|
||||
}) async {
|
||||
final result = await showModalBottomSheet<(DateTime, DateTime)>(
|
||||
context: context,
|
||||
backgroundColor: Colors.transparent,
|
||||
isScrollControlled: true,
|
||||
builder: (context) => DateTimePickerSheet(
|
||||
initialDate: date,
|
||||
initialTime: time,
|
||||
minTime: minTime,
|
||||
),
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
Widget _buildColorPicker() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
context.l10n.calendarDetailColor,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: defaultColors.map((color) {
|
||||
final colorHex =
|
||||
'#${color.toARGB32().toRadixString(16).substring(2).toUpperCase()}';
|
||||
final isSelected = _selectedColor == colorHex;
|
||||
return GestureDetector(
|
||||
onTap: () => setState(() => _selectedColor = colorHex),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(right: 12),
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
shape: BoxShape.circle,
|
||||
border: isSelected
|
||||
? Border.all(color: AppColors.slate900, width: 2)
|
||||
: null,
|
||||
),
|
||||
child: isSelected
|
||||
? const Icon(Icons.check, size: 16, color: Colors.white)
|
||||
: null,
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildReminderPicker() {
|
||||
String labelOf(int? value) {
|
||||
if (value == null) {
|
||||
return context.l10n.calendarCreateReminderNone;
|
||||
}
|
||||
if (value == 0) {
|
||||
return context.l10n.calendarDetailReminderOnTime;
|
||||
}
|
||||
return context.l10n.calendarDetailReminderBeforeMinutes(value);
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
context.l10n.calendarCreateReminderTime,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
final options = _buildReminderOptions();
|
||||
final selected = await showAppSelectionSheet<int?>(
|
||||
context,
|
||||
title: context.l10n.calendarCreatePickReminderTime,
|
||||
items: options
|
||||
.map((v) => AppSelectionItem(value: v, label: labelOf(v)))
|
||||
.toList(),
|
||||
selectedValue: _reminderMinutes,
|
||||
);
|
||||
if (selected != null) {
|
||||
setState(() {
|
||||
_reminderMinutes = selected;
|
||||
});
|
||||
}
|
||||
},
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.slate50,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
labelOf(_reminderMinutes),
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.slate900,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
LucideIcons.chevronRight,
|
||||
size: 16,
|
||||
color: AppColors.slate400,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
int? _sanitizeReminderMinutes(int? minutes) {
|
||||
return (minutes != null && minutes >= 0) ? minutes : null;
|
||||
}
|
||||
|
||||
List<int?> _buildReminderOptions() {
|
||||
final current = _sanitizeReminderMinutes(_reminderMinutes);
|
||||
final nonNull = _defaultReminderOptions.whereType<int>().toSet();
|
||||
if (current != null) {
|
||||
nonNull.add(current);
|
||||
}
|
||||
|
||||
final sorted = nonNull.toList()..sort();
|
||||
return [null, ...sorted];
|
||||
}
|
||||
|
||||
Future<void> _saveEvent() async {
|
||||
if (_titleController.text.trim().isEmpty || _saving) return;
|
||||
setState(() {
|
||||
_saving = true;
|
||||
});
|
||||
|
||||
final startAt = DateTime(
|
||||
_startDate.year,
|
||||
_startDate.month,
|
||||
_startDate.day,
|
||||
_startTime.hour,
|
||||
_startTime.minute,
|
||||
);
|
||||
|
||||
DateTime? endAt;
|
||||
if (_endDate != null && _endTime != null) {
|
||||
endAt = DateTime(
|
||||
_endDate!.year,
|
||||
_endDate!.month,
|
||||
_endDate!.day,
|
||||
_endTime!.hour,
|
||||
_endTime!.minute,
|
||||
);
|
||||
}
|
||||
|
||||
final metadata = ScheduleMetadata(
|
||||
color: _selectedColor,
|
||||
location: _locationController.text.trim().isNotEmpty
|
||||
? _locationController.text.trim()
|
||||
: null,
|
||||
notes: _notesController.text.trim().isNotEmpty
|
||||
? _notesController.text.trim()
|
||||
: null,
|
||||
reminderMinutes: _reminderMinutes,
|
||||
attachments: const [],
|
||||
version: widget.editingEvent?.metadata?.version ?? 1,
|
||||
);
|
||||
|
||||
final event = ScheduleItemModel(
|
||||
id: _isEditing
|
||||
? widget.editingEvent!.id
|
||||
: 'evt_${DateTime.now().millisecondsSinceEpoch}',
|
||||
ownerId: widget.editingEvent?.ownerId ?? '',
|
||||
title: _titleController.text.trim(),
|
||||
description: _descriptionController.text.trim().isNotEmpty
|
||||
? _descriptionController.text.trim()
|
||||
: null,
|
||||
startAt: startAt,
|
||||
endAt: endAt,
|
||||
metadata: metadata,
|
||||
);
|
||||
|
||||
try {
|
||||
final service = sl<CalendarService>();
|
||||
late final ScheduleItemModel saved;
|
||||
|
||||
if (_isEditing) {
|
||||
saved = await service.updateEvent(event);
|
||||
} else {
|
||||
saved = await service.addEvent(event);
|
||||
}
|
||||
|
||||
try {
|
||||
final notificationService = sl<LocalNotificationService>();
|
||||
await notificationService.upsertEventReminder(saved);
|
||||
} catch (_) {
|
||||
if (mounted) {
|
||||
Toast.show(
|
||||
context,
|
||||
context.l10n.calendarCreateReminderPermissionFailed,
|
||||
type: ToastType.warning,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
widget.onSaved?.call();
|
||||
if (mounted) {
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
Toast.show(
|
||||
context,
|
||||
context.l10n.todoSaveFailed('$e'),
|
||||
type: ToastType.error,
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_saving = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,388 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:social_app/core/l10n/l10n.dart';
|
||||
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
|
||||
class DateTimePickerSheet extends StatefulWidget {
|
||||
final DateTime initialDate;
|
||||
final DateTime initialTime;
|
||||
final DateTime? minTime;
|
||||
|
||||
const DateTimePickerSheet({
|
||||
super.key,
|
||||
required this.initialDate,
|
||||
required this.initialTime,
|
||||
this.minTime,
|
||||
});
|
||||
|
||||
@override
|
||||
State<DateTimePickerSheet> createState() => _DateTimePickerSheetState();
|
||||
}
|
||||
|
||||
class _DateTimePickerSheetState extends State<DateTimePickerSheet> {
|
||||
late int _selectedYear;
|
||||
late int _selectedMonth;
|
||||
late int _selectedDay;
|
||||
late int _selectedHour;
|
||||
late int _selectedMinute;
|
||||
|
||||
late FixedExtentScrollController _yearController;
|
||||
late FixedExtentScrollController _monthController;
|
||||
late FixedExtentScrollController _dayController;
|
||||
late FixedExtentScrollController _hourController;
|
||||
late FixedExtentScrollController _minuteController;
|
||||
|
||||
static final int _baseYear = DateTime.now().year;
|
||||
static final List<int> _years = List.generate(21, (i) => _baseYear - 10 + i);
|
||||
static final List<int> _months = List.generate(12, (i) => i + 1);
|
||||
static final List<int> _allHours = List.generate(24, (i) => i);
|
||||
static final List<int> _allMinutes = List.generate(60, (i) => i);
|
||||
|
||||
List<int> _days = [];
|
||||
late List<int> _filteredHours;
|
||||
late List<int> _filteredMinutes;
|
||||
|
||||
List<int> _getFilteredHours() {
|
||||
if (widget.minTime == null) return _allHours;
|
||||
final minDate = widget.minTime!;
|
||||
if (_selectedYear > minDate.year ||
|
||||
(_selectedYear == minDate.year && _selectedMonth > minDate.month) ||
|
||||
(_selectedYear == minDate.year &&
|
||||
_selectedMonth == minDate.month &&
|
||||
_selectedDay > minDate.day)) {
|
||||
return _allHours;
|
||||
}
|
||||
if (_selectedYear == minDate.year &&
|
||||
_selectedMonth == minDate.month &&
|
||||
_selectedDay == minDate.day) {
|
||||
return _allHours.where((h) => h >= minDate.hour).toList();
|
||||
}
|
||||
return _allHours;
|
||||
}
|
||||
|
||||
List<int> _getFilteredMinutes() {
|
||||
if (widget.minTime == null) return _allMinutes;
|
||||
final minDate = widget.minTime!;
|
||||
if (_selectedYear > minDate.year ||
|
||||
(_selectedYear == minDate.year && _selectedMonth > minDate.month) ||
|
||||
(_selectedYear == minDate.year &&
|
||||
_selectedMonth == minDate.month &&
|
||||
_selectedDay > minDate.day)) {
|
||||
return _allMinutes;
|
||||
}
|
||||
if (_selectedYear == minDate.year &&
|
||||
_selectedMonth == minDate.month &&
|
||||
_selectedDay == minDate.day &&
|
||||
_selectedHour == minDate.hour) {
|
||||
return _allMinutes.where((m) => m >= minDate.minute).toList();
|
||||
}
|
||||
return _allMinutes;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_selectedYear = widget.initialDate.year;
|
||||
_selectedMonth = widget.initialDate.month;
|
||||
_selectedDay = widget.initialDate.day;
|
||||
_selectedHour = widget.initialTime.hour;
|
||||
_selectedMinute = widget.initialTime.minute;
|
||||
_filteredHours = _getFilteredHours();
|
||||
_filteredMinutes = _getFilteredMinutes();
|
||||
_updateDays();
|
||||
|
||||
_yearController = FixedExtentScrollController(
|
||||
initialItem: _years.indexOf(_selectedYear),
|
||||
);
|
||||
_monthController = FixedExtentScrollController(
|
||||
initialItem: _selectedMonth - 1,
|
||||
);
|
||||
_dayController = FixedExtentScrollController(initialItem: _selectedDay - 1);
|
||||
_hourController = FixedExtentScrollController(
|
||||
initialItem: _filteredHours.indexOf(_selectedHour),
|
||||
);
|
||||
|
||||
if (_filteredMinutes.isEmpty) {
|
||||
_selectedMinute = 0;
|
||||
} else if (!_filteredMinutes.contains(_selectedMinute)) {
|
||||
_selectedMinute = _filteredMinutes.first;
|
||||
}
|
||||
_minuteController = FixedExtentScrollController(
|
||||
initialItem: _filteredMinutes.indexOf(_selectedMinute),
|
||||
);
|
||||
}
|
||||
|
||||
void _updateDays() {
|
||||
_days = List.generate(
|
||||
DateTime(_selectedYear, _selectedMonth + 1, 0).day,
|
||||
(i) => i + 1,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_yearController.dispose();
|
||||
_monthController.dispose();
|
||||
_dayController.dispose();
|
||||
_hourController.dispose();
|
||||
_minuteController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
|
||||
return Container(
|
||||
height: 420,
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildHeader(),
|
||||
Expanded(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildPickerLabel(l10n.calendarDateTimePickerDateLabel),
|
||||
Expanded(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildPicker(_years, _yearController, (v) {
|
||||
setState(() {
|
||||
_selectedYear = v;
|
||||
_updateDays();
|
||||
if (_selectedDay > _days.length) {
|
||||
_selectedDay = _days.length;
|
||||
_dayController.jumpToItem(_selectedDay - 1);
|
||||
}
|
||||
});
|
||||
}, (v) => '$v'),
|
||||
),
|
||||
Text(
|
||||
l10n.calendarDateTimePickerYearUnit,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.slate600,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: _buildPicker(_months, _monthController, (
|
||||
v,
|
||||
) {
|
||||
setState(() {
|
||||
_selectedMonth = v;
|
||||
_updateDays();
|
||||
if (_selectedDay > _days.length) {
|
||||
_selectedDay = _days.length;
|
||||
_dayController.jumpToItem(_selectedDay - 1);
|
||||
}
|
||||
});
|
||||
}, (v) => '$v'),
|
||||
),
|
||||
Text(
|
||||
l10n.calendarDateTimePickerMonthUnit,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.slate600,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: _buildPicker(
|
||||
_days,
|
||||
_dayController,
|
||||
(v) => setState(() => _selectedDay = v),
|
||||
(v) => '$v',
|
||||
),
|
||||
),
|
||||
Text(
|
||||
l10n.calendarDateTimePickerDayUnit,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.slate600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(width: 1, height: 180, color: AppColors.border),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildPickerLabel(l10n.calendarDateTimePickerTimeLabel),
|
||||
Expanded(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildPicker(
|
||||
_filteredHours,
|
||||
_hourController,
|
||||
(v) {
|
||||
setState(() {
|
||||
_selectedHour = v;
|
||||
_filteredMinutes = _getFilteredMinutes();
|
||||
if (_filteredMinutes.isEmpty) {
|
||||
_selectedMinute = 0;
|
||||
return;
|
||||
}
|
||||
if (_selectedMinute >
|
||||
_filteredMinutes.last) {
|
||||
_selectedMinute = _filteredMinutes.last;
|
||||
_minuteController.jumpToItem(
|
||||
_filteredMinutes.indexOf(
|
||||
_selectedMinute,
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
(v) => v.toString().padLeft(2, '0'),
|
||||
itemExtent: 50,
|
||||
),
|
||||
),
|
||||
const Text(
|
||||
' : ',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.slate600,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: _buildPicker(
|
||||
_filteredMinutes,
|
||||
_minuteController,
|
||||
(v) => setState(() => _selectedMinute = v),
|
||||
(v) => v.toString().padLeft(2, '0'),
|
||||
itemExtent: 50,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeader() {
|
||||
final l10n = context.l10n;
|
||||
|
||||
return Container(
|
||||
height: 56,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: AppColors.border)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.pop(context),
|
||||
child: Text(
|
||||
l10n.commonCancel,
|
||||
style: const TextStyle(fontSize: 17, color: AppColors.slate600),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
l10n.calendarDateTimePickerTitle,
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate900,
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.pop(context, (
|
||||
DateTime(_selectedYear, _selectedMonth, _selectedDay),
|
||||
DateTime(2000, 1, 1, _selectedHour, _selectedMinute),
|
||||
));
|
||||
},
|
||||
child: Text(
|
||||
l10n.commonConfirm,
|
||||
style: const TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.blue600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPickerLabel(String label) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate700,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPicker(
|
||||
List<int> items,
|
||||
FixedExtentScrollController controller,
|
||||
ValueChanged<int> onChanged,
|
||||
String Function(int) formatter, {
|
||||
double itemExtent = 40,
|
||||
}) {
|
||||
return CupertinoPicker(
|
||||
scrollController: controller,
|
||||
itemExtent: itemExtent,
|
||||
magnification: 1.2,
|
||||
squeeze: 0.8,
|
||||
useMagnifier: true,
|
||||
onSelectedItemChanged: (index) => onChanged(items[index]),
|
||||
selectionOverlay: Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.symmetric(
|
||||
horizontal: BorderSide(
|
||||
color: AppColors.blue100.withValues(alpha: 0.5),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
children: List<Widget>.generate(items.length, (index) {
|
||||
return Center(
|
||||
child: Text(
|
||||
formatter(items[index]),
|
||||
style: const TextStyle(fontSize: 18, color: AppColors.slate900),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user