new UI + new targets.
This commit is contained in:
+441
-336
@@ -1,13 +1,18 @@
|
||||
import 'package:flutter/foundation.dart' show kDebugMode;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../models/holiday_theme.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../models/target_style.dart';
|
||||
import '../services/app_settings.dart';
|
||||
import '../utils/translations.dart';
|
||||
import '../services/notification_service.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
import '../utils/target_colors.dart';
|
||||
import '../widgets/section.dart';
|
||||
import '../widgets/target_face.dart';
|
||||
import '../widgets/text_prompt.dart';
|
||||
import '../widgets/ui.dart';
|
||||
import 'camera_settings_screen.dart';
|
||||
|
||||
class SettingsScreen extends StatelessWidget {
|
||||
@@ -24,127 +29,152 @@ class SettingsScreen extends StatelessWidget {
|
||||
builder: (context, _) {
|
||||
final s = AppSettings.instance;
|
||||
final t = s.t;
|
||||
final language = AppSettings.languages.firstWhere(
|
||||
(l) => l['name'] == s.language,
|
||||
orElse: () => AppSettings.languages.first,
|
||||
);
|
||||
final c = Palette.current;
|
||||
|
||||
return ListView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 24),
|
||||
padding: EdgeInsets.zero,
|
||||
children: [
|
||||
SectionHeader(t('Language')),
|
||||
GroupCard(children: [
|
||||
SettingsTile(
|
||||
title: t(language['name']!),
|
||||
onTap: () => _pickLanguage(context),
|
||||
),
|
||||
]),
|
||||
|
||||
SectionHeader(t('Appearance')),
|
||||
GroupCard(children: [
|
||||
SettingsTile(
|
||||
title: t('Bullet color'),
|
||||
valueLeading: _ColorDot(s.bulletColor, size: 18),
|
||||
value: t(s.bulletColorName),
|
||||
onTap: () => _pickBulletColor(context),
|
||||
),
|
||||
SettingsTile(
|
||||
title: t('Target'),
|
||||
valueLeading: _TargetThumb(s.selectedTarget, size: 30),
|
||||
value: s.targetName(s.selectedTarget),
|
||||
onTap: () => _pickTarget(context),
|
||||
),
|
||||
]),
|
||||
|
||||
SectionHeader(t('Club')),
|
||||
GroupCard(children: [
|
||||
if (s.clubUnlocked)
|
||||
SettingsTile(
|
||||
leading: const Icon(Icons.verified_rounded, color: Colors.green),
|
||||
title: t('Member access'),
|
||||
subtitle: t('Calendar and contacts unlocked'),
|
||||
value: t('Remove'),
|
||||
onTap: () => _confirmLock(context),
|
||||
)
|
||||
else
|
||||
SettingsTile(
|
||||
leading: Icon(Icons.lock_outline_rounded, color: Surfaces.current.textSecondary),
|
||||
title: t('Club code'),
|
||||
subtitle: t('Unlocks calendar and contacts'),
|
||||
onTap: () => _enterClubCode(context),
|
||||
),
|
||||
]),
|
||||
PageHeader(title: t('Settings')),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(4, 8, 4, 0),
|
||||
child: Text(
|
||||
t('Member access is currently available only for SD Kovinar Muta. Support for other clubs may be added in the future.'),
|
||||
style: TextStyle(fontSize: 12, color: Surfaces.current.textSecondary),
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.fromLTRB(AppTheme.edge, 0, AppTheme.edge, 28),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
SectionHeader(t('Language')),
|
||||
GroupCard(children: [
|
||||
SettingsTile(
|
||||
icon: Icons.language_rounded,
|
||||
title: t('Language'),
|
||||
value: t(s.language),
|
||||
onTap: () => _pickLanguage(context),
|
||||
),
|
||||
]),
|
||||
|
||||
if (s.clubUnlocked) ...[
|
||||
SectionHeader(t('Notifications')),
|
||||
GroupCard(children: [
|
||||
SettingsSwitchTile(
|
||||
title: t('Dežuranje'),
|
||||
value: s.notifyDezuranje,
|
||||
activeColor: s.bulletColor,
|
||||
onChanged: (v) => s.setNotifyDezuranje(v).then((_) => _reschedule()),
|
||||
),
|
||||
SettingsSwitchTile(
|
||||
title: t('Sestanek'),
|
||||
value: s.notifySestanek,
|
||||
activeColor: s.bulletColor,
|
||||
onChanged: (v) => s.setNotifySestanek(v).then((_) => _reschedule()),
|
||||
),
|
||||
SettingsSwitchTile(
|
||||
title: t('Tekma'),
|
||||
value: s.notifyTekma,
|
||||
activeColor: s.bulletColor,
|
||||
onChanged: (v) => s.setNotifyTekma(v).then((_) => _reschedule()),
|
||||
),
|
||||
SettingsTile(
|
||||
title: t('Remind me'),
|
||||
value: _hoursBefore(s.reminderHours),
|
||||
onTap: () => _pickReminder(context),
|
||||
),
|
||||
]),
|
||||
],
|
||||
SectionHeader(t('Appearance')),
|
||||
GroupCard(children: [
|
||||
SettingsTile(
|
||||
icon: Icons.dark_mode_outlined,
|
||||
title: t('Theme'),
|
||||
trailing: SizedBox(
|
||||
width: 196,
|
||||
child: SegmentedTabs(
|
||||
height: 36,
|
||||
accentSelected: true,
|
||||
items: [SegmentItem(t('System')), SegmentItem(t('Light')), SegmentItem(t('Dark'))],
|
||||
selected: AppSettings.themeModes.indexOf(s.themeMode),
|
||||
onSelect: (i) => s.setThemeMode(AppSettings.themeModes[i]),
|
||||
),
|
||||
),
|
||||
),
|
||||
// Hit colour and target design are picked in one sheet
|
||||
SettingsTile(
|
||||
icon: Icons.track_changes_rounded,
|
||||
title: t('Hits and target'),
|
||||
valueLeading: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_ColorDot(s.bulletColor, size: 16),
|
||||
const SizedBox(width: 8),
|
||||
TargetThumb(s.target, size: 26),
|
||||
],
|
||||
),
|
||||
value: s.target.name(s.language),
|
||||
onTap: () => showAppearanceSheet(context),
|
||||
),
|
||||
]),
|
||||
|
||||
SectionHeader(t('Cameras')),
|
||||
GroupCard(children: [
|
||||
SettingsTile(
|
||||
title: t('Camera Settings'),
|
||||
value: _camerasSummary(s),
|
||||
onTap: () => Navigator.of(context).push(
|
||||
MaterialPageRoute(builder: (_) => const CameraSettingsScreen()),
|
||||
),
|
||||
),
|
||||
]),
|
||||
SectionHeader('${t('Club')} · SD Kovinar Muta'),
|
||||
GroupCard(children: [
|
||||
if (s.clubUnlocked)
|
||||
SettingsTile(
|
||||
icon: Icons.verified_user_outlined,
|
||||
title: t('Member access'),
|
||||
value: t('Unlocked'),
|
||||
valueColor: c.pos,
|
||||
showChevron: false,
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(t('Unlocked'), style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: c.pos)),
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
width: 22,
|
||||
height: 22,
|
||||
decoration: BoxDecoration(color: c.pos, shape: BoxShape.circle),
|
||||
child: Icon(Icons.check_rounded, size: 15, color: Palette.onColor(c.pos)),
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () => _confirmLock(context),
|
||||
)
|
||||
else
|
||||
SettingsTile(
|
||||
icon: Icons.lock_outline_rounded,
|
||||
title: t('Club code'),
|
||||
subtitle: t('Unlocks calendar and contacts'),
|
||||
onTap: () => _enterClubCode(context),
|
||||
),
|
||||
]),
|
||||
if (!s.clubUnlocked)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(4, 10, 4, 0),
|
||||
child: Text(
|
||||
t('Member access is currently available only for SD Kovinar Muta. Support for other clubs may be added in the future.'),
|
||||
style: TextStyle(fontSize: 12, height: 1.35, color: c.muted),
|
||||
),
|
||||
),
|
||||
|
||||
SectionHeader(t('About')),
|
||||
GroupCard(children: [
|
||||
SettingsTile(
|
||||
title: t('Privacy policy'),
|
||||
onTap: () => launchUrl(
|
||||
Uri.parse(_privacyPolicyUrl),
|
||||
mode: LaunchMode.externalApplication,
|
||||
),
|
||||
),
|
||||
]),
|
||||
if (s.clubUnlocked) ...[
|
||||
SectionHeader(t('Notifications')),
|
||||
GroupCard(children: notificationTiles(context)),
|
||||
],
|
||||
|
||||
const SizedBox(height: 28),
|
||||
FutureBuilder<PackageInfo>(
|
||||
future: _packageInfo,
|
||||
builder: (context, snap) {
|
||||
final info = snap.data;
|
||||
if (info == null) return const SizedBox.shrink();
|
||||
return Text(
|
||||
'${info.appName} ${info.version}',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 12, color: Surfaces.current.textSecondary),
|
||||
);
|
||||
},
|
||||
SectionHeader(t('Cameras')),
|
||||
GroupCard(children: [
|
||||
SettingsTile(
|
||||
icon: Icons.videocam_outlined,
|
||||
title: t('Camera Settings'),
|
||||
value: _camerasSummary(s),
|
||||
onTap: () => Navigator.of(context).push(
|
||||
MaterialPageRoute(builder: (_) => const CameraSettingsScreen()),
|
||||
),
|
||||
),
|
||||
]),
|
||||
|
||||
SectionHeader(t('About')),
|
||||
GroupCard(children: [
|
||||
SettingsTile(
|
||||
icon: Icons.shield_outlined,
|
||||
title: t('Privacy policy'),
|
||||
chevron: Icons.open_in_new_rounded,
|
||||
onTap: () => launchUrl(Uri.parse(_privacyPolicyUrl), mode: LaunchMode.externalApplication),
|
||||
),
|
||||
FutureBuilder<PackageInfo>(
|
||||
future: _packageInfo,
|
||||
// Debug builds: long press previews a holiday
|
||||
builder: (context, snap) => SettingsTile(
|
||||
icon: Icons.info_outline_rounded,
|
||||
title: t('Version'),
|
||||
value: snap.data?.version ?? '',
|
||||
),
|
||||
),
|
||||
]),
|
||||
|
||||
// Debug builds only (never in a release): check the holiday looks
|
||||
if (kDebugMode) ...[
|
||||
const SectionHeader('Debug'),
|
||||
GroupCard(children: [
|
||||
SettingsTile(
|
||||
icon: Icons.celebration_outlined,
|
||||
title: 'Holiday preview',
|
||||
subtitle: 'Shows the app as on a day of the holiday',
|
||||
value: s.debugToday == null ? 'Today' : (s.holiday?.name ?? 'Today'),
|
||||
onTap: () => _previewHoliday(context),
|
||||
),
|
||||
]),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -154,13 +184,91 @@ class SettingsScreen extends StatelessWidget {
|
||||
|
||||
static void _reschedule() => NotificationService().rescheduleFromCalendar();
|
||||
|
||||
// Debug: see the app as on a day of each holiday (Nastavitve → Debug)
|
||||
static void _previewHoliday(BuildContext context) {
|
||||
final s = AppSettings.instance;
|
||||
final year = DateTime.now().year;
|
||||
showAppSheet(
|
||||
context,
|
||||
title: 'Holiday preview (debug)',
|
||||
builder: (sheet) => Column(
|
||||
children: [
|
||||
SheetOption(
|
||||
label: 'Today',
|
||||
selected: s.debugToday == null,
|
||||
showDivider: false,
|
||||
onTap: () {
|
||||
s.previewDay(null);
|
||||
Navigator.pop(sheet);
|
||||
},
|
||||
),
|
||||
for (final h in HolidayTheme.all)
|
||||
Builder(builder: (_) {
|
||||
// First day of the holiday this year
|
||||
final day = h.easter != null
|
||||
? HolidayTheme.easterDay(year, h.easter!.$1)
|
||||
: DateTime(year, h.from!.$1, h.from!.$2);
|
||||
final (start, end) = h.window(day);
|
||||
return SheetOption(
|
||||
label: h.name,
|
||||
subtitle: '${DateFormat('d. M.').format(start)} – ${DateFormat('d. M.').format(end)}',
|
||||
leading: TargetThumb(TargetStyle.byId(h.targetId), size: 32),
|
||||
selected: s.holiday == h && s.debugToday != null,
|
||||
onTap: () {
|
||||
s.previewDay(day);
|
||||
Navigator.pop(sheet);
|
||||
},
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Dežuranje, Sestanki, Tekme and "Opomni me"; also shown from the calendar's bell.
|
||||
static List<Widget> notificationTiles(BuildContext context) {
|
||||
final s = AppSettings.instance;
|
||||
final t = s.t;
|
||||
return [
|
||||
SettingsSwitchTile(
|
||||
icon: Icons.shield_outlined,
|
||||
title: t('Dežuranje'),
|
||||
value: s.notifyDezuranje,
|
||||
onChanged: (v) => s.setNotifyDezuranje(v).then((_) => _reschedule()),
|
||||
),
|
||||
SettingsSwitchTile(
|
||||
icon: Icons.person_add_alt_outlined,
|
||||
title: t('Sestanek'),
|
||||
value: s.notifySestanek,
|
||||
onChanged: (v) => s.setNotifySestanek(v).then((_) => _reschedule()),
|
||||
),
|
||||
SettingsSwitchTile(
|
||||
icon: Icons.emoji_events_outlined,
|
||||
title: t('Tekma'),
|
||||
value: s.notifyTekma,
|
||||
onChanged: (v) => s.setNotifyTekma(v).then((_) => _reschedule()),
|
||||
),
|
||||
SettingsTile(
|
||||
icon: Icons.notifications_none_rounded,
|
||||
title: t('Remind me'),
|
||||
value: hoursBefore(s.reminderHours),
|
||||
onTap: () => pickReminder(context),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
Future<void> _enterClubCode(BuildContext context) async {
|
||||
final s = AppSettings.instance;
|
||||
final code = await showTextPrompt(
|
||||
context,
|
||||
title: s.t('Club code'),
|
||||
message: s.t('Unlocks calendar and contacts'),
|
||||
message: s.t('Unlocks calendar and contacts.'),
|
||||
titleIcon: Icons.lock_outline_rounded,
|
||||
fieldIcon: Icons.key_rounded,
|
||||
mono: true,
|
||||
note: s.t('Member access is currently available only for SD Kovinar Muta.'),
|
||||
confirmLabel: s.t('Unlock'),
|
||||
confirmIcon: Icons.key_rounded,
|
||||
);
|
||||
if (code == null || code.isEmpty || !context.mounted) return;
|
||||
|
||||
@@ -175,222 +283,245 @@ class SettingsScreen extends StatelessWidget {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
if (ok) _reschedule();
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(s.t(ok ? 'Club access unlocked' : 'Wrong club code')),
|
||||
backgroundColor: ok ? Colors.green[700] : Colors.red[700],
|
||||
));
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(s.t(ok ? 'Club access unlocked' : 'Wrong club code'))));
|
||||
}
|
||||
|
||||
Future<void> _confirmLock(BuildContext context) async {
|
||||
final s = AppSettings.instance;
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialog) => AlertDialog(
|
||||
title: Text(s.t('Member access')),
|
||||
content: Text(s.t('Remove club access from this phone?')),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialog, false),
|
||||
child: Text(s.t('Cancel'), style: const TextStyle(color: Colors.white70)),
|
||||
),
|
||||
FilledButton(
|
||||
style: FilledButton.styleFrom(backgroundColor: Colors.red[700]),
|
||||
onPressed: () => Navigator.pop(dialog, true),
|
||||
child: Text(s.t('Remove')),
|
||||
),
|
||||
],
|
||||
),
|
||||
final confirmed = await confirmDialog(
|
||||
context,
|
||||
title: s.t('Member access'),
|
||||
message: s.t('Remove club access from this phone?'),
|
||||
confirm: s.t('Remove'),
|
||||
);
|
||||
if (confirmed == true) {
|
||||
if (confirmed) {
|
||||
await s.lockClub();
|
||||
_reschedule(); // cancels reminders
|
||||
}
|
||||
}
|
||||
|
||||
static String _hoursBefore(int hours) =>
|
||||
AppSettings.instance.t('{n} h before').replaceAll('{n}', '$hours');
|
||||
static String hoursBefore(int hours) => AppSettings.instance.t('{n} h before').replaceAll('{n}', '$hours');
|
||||
|
||||
// Location names (e.g. "Kovinar · Doma"), or a hint when nothing is set up yet.
|
||||
// "2 strelišči", or a hint when nothing is set up yet.
|
||||
static String _camerasSummary(AppSettings s) {
|
||||
final locations = s.cameras.locations;
|
||||
return locations.isEmpty ? s.t('Not set up') : locations.join(' · ');
|
||||
final n = s.cameras.locations.length;
|
||||
if (n == 0) return s.t('Not set up');
|
||||
if (s.language == 'Slovenian') {
|
||||
final mod = n % 100;
|
||||
return '$n ${mod == 1 ? 'strelišče' : mod == 2 ? 'strelišči' : (mod == 3 || mod == 4) ? 'strelišča' : 'strelišč'}';
|
||||
}
|
||||
return s.cameras.locations.join(' · ');
|
||||
}
|
||||
|
||||
void _pickLanguage(BuildContext context) {
|
||||
final s = AppSettings.instance;
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (sheet) => SafeArea(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_SheetTitle(s.t('Select Language')),
|
||||
// Each language in its own name, so it can be found from any language
|
||||
for (final lang in AppSettings.languages)
|
||||
SheetOption(
|
||||
label: AppTranslations.translate(lang['name']!, lang['name']!),
|
||||
selected: lang['name'] == s.language,
|
||||
selectedColor: s.bulletColor,
|
||||
onTap: () {
|
||||
s.setLanguage(lang['name']!);
|
||||
Navigator.pop(sheet);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _pickReminder(BuildContext context) {
|
||||
final s = AppSettings.instance;
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
// 7 options exceed the default 9/16 height cap on smaller phones
|
||||
isScrollControlled: true,
|
||||
builder: (sheet) => SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_SheetTitle(s.t('Remind me')),
|
||||
for (final h in AppSettings.reminderHourOptions)
|
||||
SheetOption(
|
||||
label: _hoursBefore(h),
|
||||
selected: h == s.reminderHours,
|
||||
selectedColor: s.bulletColor,
|
||||
onTap: () {
|
||||
s.setReminderHours(h).then((_) => _reschedule());
|
||||
Navigator.pop(sheet);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _pickBulletColor(BuildContext context) {
|
||||
final s = AppSettings.instance;
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (sheet) => SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_SheetTitle(s.t('Bullet color')),
|
||||
Wrap(
|
||||
spacing: 16,
|
||||
runSpacing: 16,
|
||||
alignment: WrapAlignment.center,
|
||||
children: [
|
||||
for (final entry in AppSettings.bulletColors.entries)
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
s.setBulletColor(entry.key);
|
||||
Navigator.pop(sheet);
|
||||
},
|
||||
child: _ColorDot(
|
||||
entry.value,
|
||||
size: 48,
|
||||
selected: entry.key == s.bulletColorName,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _pickTarget(BuildContext context) {
|
||||
final s = AppSettings.instance;
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
builder: (sheet) => DraggableScrollableSheet(
|
||||
expand: false,
|
||||
initialChildSize: 0.75,
|
||||
maxChildSize: 0.95,
|
||||
builder: (context, scroll) => Column(
|
||||
children: [
|
||||
_SheetTitle(s.t('Target')),
|
||||
Expanded(
|
||||
child: GridView.builder(
|
||||
controller: scroll,
|
||||
padding: EdgeInsets.fromLTRB(16, 0, 16, 24 + MediaQuery.paddingOf(context).bottom),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 3,
|
||||
mainAxisSpacing: 12,
|
||||
crossAxisSpacing: 12,
|
||||
childAspectRatio: 0.8,
|
||||
),
|
||||
itemCount: AppSettings.targets.length,
|
||||
itemBuilder: (context, i) {
|
||||
final path = AppSettings.targets[i];
|
||||
final selected = path == s.selectedTarget;
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
s.setTarget(path);
|
||||
Navigator.pop(sheet);
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: selected ? s.bulletColor : Colors.transparent,
|
||||
width: 3,
|
||||
),
|
||||
),
|
||||
child: _TargetThumb(path, radius: 9),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
s.targetName(path),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: selected ? Colors.white : Colors.white70,
|
||||
fontWeight: selected ? FontWeight.bold : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
showAppSheet(
|
||||
context,
|
||||
title: s.t('Select Language'),
|
||||
builder: (sheet) => Column(
|
||||
children: [
|
||||
// Each language in its own name, so it can be found from any language
|
||||
for (final lang in AppSettings.languages)
|
||||
SheetOption(
|
||||
label: AppTranslations.translate(lang['name']!, lang['name']!),
|
||||
leading: Text(lang['flag']!, style: const TextStyle(fontSize: 22)),
|
||||
selected: lang['name'] == s.language,
|
||||
onTap: () {
|
||||
s.setLanguage(lang['name']!);
|
||||
Navigator.pop(sheet);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static void pickReminder(BuildContext context) {
|
||||
final s = AppSettings.instance;
|
||||
showAppSheet(
|
||||
context,
|
||||
title: s.t('Remind me'),
|
||||
builder: (sheet) => Column(
|
||||
children: [
|
||||
for (final h in AppSettings.reminderHourOptions)
|
||||
SheetOption(
|
||||
label: hoursBefore(h),
|
||||
selected: h == s.reminderHours,
|
||||
onTap: () {
|
||||
s.setReminderHours(h).then((_) => _reschedule());
|
||||
Navigator.pop(sheet);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SheetTitle extends StatelessWidget {
|
||||
final String text;
|
||||
/// Videz: hit colour (the accent of the whole app) and the target design.
|
||||
void showAppearanceSheet(BuildContext context) {
|
||||
final s = AppSettings.instance;
|
||||
showAppSheet(
|
||||
context,
|
||||
builder: (sheet) => ListenableBuilder(
|
||||
listenable: s,
|
||||
builder: (context, _) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
SheetTitle(s.t('Appearance'), trailing: TargetThumb(s.target, size: 52)),
|
||||
Kicker(s.t('Bullet color'), padding: const EdgeInsets.only(bottom: 12)),
|
||||
LayoutBuilder(builder: (context, box) {
|
||||
const perRow = 8;
|
||||
final size = ((box.maxWidth - (perRow - 1) * 10) / perRow).clamp(28.0, 40.0);
|
||||
return Wrap(
|
||||
spacing: 10,
|
||||
runSpacing: 12,
|
||||
children: [
|
||||
// During a holiday its colour comes first (and is the one in use)
|
||||
if (s.holiday != null)
|
||||
GestureDetector(
|
||||
onTap: s.useHolidayColor,
|
||||
child: Tooltip(
|
||||
message: s.holiday!.name,
|
||||
child: _ColorDot(s.holiday!.color, size: size, selected: s.holidayColorActive),
|
||||
),
|
||||
),
|
||||
for (final name in AppSettings.bulletColors.keys)
|
||||
GestureDetector(
|
||||
onTap: () => s.setBulletColor(name),
|
||||
child: Tooltip(
|
||||
message: s.t(name),
|
||||
child: _ColorDot(s.colorFor(name), size: size,
|
||||
selected: !s.holidayColorActive && name == s.bulletColorName),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
Kicker(s.t('Target style'), padding: const EdgeInsets.only(top: 22, bottom: 12)),
|
||||
if (s.holiday != null) _HolidayCard(holiday: s.holiday!) else const _TargetGrid(styles: TargetStyle.all),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
const _SheetTitle(this.text);
|
||||
/// Three target designs per row; the chosen one has an accent border and a check.
|
||||
class _TargetGrid extends StatelessWidget {
|
||||
final List<TargetStyle> styles;
|
||||
const _TargetGrid({required this.styles});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Text(
|
||||
text,
|
||||
style: const TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
|
||||
final s = AppSettings.instance;
|
||||
final c = Palette.current;
|
||||
return LayoutBuilder(builder: (context, box) {
|
||||
final w = (box.maxWidth - 2 * 10) / 3;
|
||||
return Wrap(
|
||||
spacing: 10,
|
||||
runSpacing: 14,
|
||||
children: [
|
||||
for (final style in styles)
|
||||
SizedBox(
|
||||
width: w,
|
||||
child: GestureDetector(
|
||||
onTap: () => s.setTarget(style),
|
||||
child: Column(
|
||||
children: [
|
||||
Stack(
|
||||
children: [
|
||||
Container(
|
||||
height: w * 0.92,
|
||||
width: w,
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: c.isDark ? c.card2 : c.tile,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: style == s.target ? c.accent : Colors.transparent, width: 2),
|
||||
),
|
||||
child: Center(child: TargetThumb(style, size: w * 0.92 - 16)),
|
||||
),
|
||||
if (style == s.target)
|
||||
Positioned(
|
||||
top: 6,
|
||||
right: 6,
|
||||
child: Container(
|
||||
width: 20,
|
||||
height: 20,
|
||||
decoration: BoxDecoration(color: c.accent, shape: BoxShape.circle),
|
||||
child: Icon(Icons.check_rounded, size: 14, color: c.onAccent),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
style.name(s.language),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: style == s.target ? FontWeight.w700 : FontWeight.w500,
|
||||
color: style == s.target ? c.ink : c.muted,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// In the Videz sheet during a holiday: its target, locked until the holiday ends.
|
||||
class _HolidayCard extends StatelessWidget {
|
||||
final HolidayTheme holiday;
|
||||
const _HolidayCard({required this.holiday});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = AppSettings.instance;
|
||||
final c = Palette.current;
|
||||
final (_, end) = holiday.window(s.today);
|
||||
return AppCard(
|
||||
color: c.isDark ? c.card2 : c.card,
|
||||
borderColor: holiday.color.withValues(alpha: 0.5),
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: Row(
|
||||
children: [
|
||||
TargetThumb(TargetStyle.byId(holiday.targetId), size: 72),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.celebration_outlined, size: 18, color: holiday.color),
|
||||
const SizedBox(width: 6),
|
||||
Flexible(
|
||||
child: Text(holiday.name,
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700, color: c.ink)),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'${s.t('Holiday target until')} ${DateFormat('d. M.').format(end)}',
|
||||
style: TextStyle(fontSize: 12.5, height: 1.35, fontWeight: FontWeight.w600, color: c.ink2),
|
||||
),
|
||||
Text(s.t('You can still change the hit colour.'),
|
||||
style: TextStyle(fontSize: 12.5, height: 1.35, color: c.muted)),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Icon(Icons.lock_outline_rounded, size: 18, color: c.faint),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -405,44 +536,18 @@ class _ColorDot extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final c = Palette.current;
|
||||
return Container(
|
||||
width: size,
|
||||
height: size,
|
||||
padding: EdgeInsets.all(selected ? 3 : 0),
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: selected ? Colors.white : Colors.black26,
|
||||
width: selected ? 3 : 1,
|
||||
),
|
||||
border: selected ? Border.all(color: c.ink, width: 2) : null,
|
||||
),
|
||||
child: selected ? const Icon(Icons.check_rounded, color: Colors.white) : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TargetThumb extends StatelessWidget {
|
||||
final String path;
|
||||
final double? size;
|
||||
final double radius;
|
||||
|
||||
const _TargetThumb(this.path, {this.size, this.radius = 6});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(radius),
|
||||
child: Container(
|
||||
width: size,
|
||||
height: size,
|
||||
color: TargetColors.getBackgroundColor(path),
|
||||
padding: const EdgeInsets.all(2),
|
||||
child: Image.asset(
|
||||
path,
|
||||
fit: BoxFit.contain,
|
||||
cacheWidth: 300,
|
||||
errorBuilder: (_, __, ___) => const Icon(Icons.image_not_supported, color: Colors.white54),
|
||||
),
|
||||
decoration: BoxDecoration(color: color, shape: BoxShape.circle),
|
||||
child: selected ? Icon(Icons.check_rounded, size: size * 0.5, color: Palette.onColor(color)) : null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user