Ad and purchases enabled (still need actual testing)

This commit is contained in:
Courtney Arnold 2026-08-16 18:27:56 -05:00
parent 2fcc6dcab7
commit faf319322a
35 changed files with 1676 additions and 34 deletions

View file

@ -0,0 +1,108 @@
import 'package:flutter/material.dart';
import '../screens/data_settings_screen.dart';
import '../services/onboarding_keys.dart';
import 'onboarding_tour_overlay.dart';
/// Shown right after a fuel entry is saved (see
/// `ConfirmFuelEntryScreen._save`) when no cloud backup is configured yet —
/// nudges the user toward Settings > Data before they forget and eventually
/// lose everything to a lost, damaged, or replaced device. Returns true if
/// they chose to set one up now.
Future<bool> showBackupReminderDialog(BuildContext context) async {
final wantsSetup = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: const Text("Your Data Isn't Backed Up"),
content: const Text(
"Until you enable a backup method, everything you log — including this "
"receipt — only lives on this device. If it's lost, damaged, or "
"replaced, that data could be lost with it.\n\n"
'Would you like to set up a backup method now?',
),
actions: [
TextButton(onPressed: () => Navigator.of(context).pop(false), child: const Text('Not Now')),
FilledButton(onPressed: () => Navigator.of(context).pop(true), child: const Text('Set Up Backup')),
],
),
);
return wantsSetup ?? false;
}
/// Pushes Settings > Data with its cloud storage card spotlighted — the
/// same visual treatment the first-launch tour's "Back Up to the Cloud"
/// step uses (see [OnboardingTourOverlay] / `MainShell`), but as a one-off
/// standalone overlay rather than part of a multi-step tour.
Future<void> openCloudBackupSetup(BuildContext context) {
return Navigator.of(context).push(
MaterialPageRoute(builder: (_) => const _SpotlightedDataSettingsScreen()),
);
}
class _SpotlightedDataSettingsScreen extends StatefulWidget {
const _SpotlightedDataSettingsScreen();
@override
State<_SpotlightedDataSettingsScreen> createState() => _SpotlightedDataSettingsScreenState();
}
class _SpotlightedDataSettingsScreenState extends State<_SpotlightedDataSettingsScreen> {
OverlayEntry? _entry;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) => _showSpotlight());
}
@override
void dispose() {
_entry?.remove();
super.dispose();
}
/// Mirrors `MainShell._waitForTargets`/`_showTourStep` for this one
/// target — duplicated rather than shared because that logic is
/// entangled with the tour's multi-step sequencing, which doesn't apply
/// to this standalone spotlight.
Future<void> _showSpotlight() async {
final key = OnboardingKeys.cloudStorageCard;
for (var attempt = 0; attempt < 30; attempt++) {
if (!mounted) return;
final renderObject = key.currentContext?.findRenderObject();
if (renderObject is RenderBox && renderObject.hasSize) break;
await Future.delayed(const Duration(milliseconds: 16));
}
if (!mounted) return;
key.currentContext?.findRenderObject()?.showOnScreen(duration: Duration.zero);
for (var i = 0; i < 5; i++) {
if (!mounted) return;
await Future.delayed(const Duration(milliseconds: 16));
}
if (!mounted) return;
_entry = OverlayEntry(
builder: (_) => OnboardingTourOverlay(
targetKeys: [key],
title: 'Back Up to the Cloud',
description: 'Connect a cloud storage account here to back up every vehicle, receipt, '
"and photo you log — so nothing is lost if this device is lost, damaged, or "
'replaced.',
stepNumber: 1,
totalSteps: 1,
skipLabel: 'Close',
onNext: _dismiss,
onSkip: _dismiss,
),
);
Overlay.of(context, rootOverlay: true).insert(_entry!);
}
void _dismiss() {
_entry?.remove();
_entry = null;
}
@override
Widget build(BuildContext context) => const DataSettingsScreen();
}

View file

@ -24,6 +24,12 @@ class OnboardingTourOverlay extends StatelessWidget {
final VoidCallback onNext;
final VoidCallback onSkip;
/// Label for the [onSkip] button — defaults to the multi-step tour's own
/// wording. A standalone, single-step spotlight (e.g. the "back up your
/// data" reminder in lib/widgets/backup_reminder.dart) isn't a "tour", so
/// it passes something more fitting like 'Close' instead.
final String skipLabel;
const OnboardingTourOverlay({
super.key,
required this.targetKeys,
@ -33,6 +39,7 @@ class OnboardingTourOverlay extends StatelessWidget {
required this.totalSteps,
required this.onNext,
required this.onSkip,
this.skipLabel = 'Skip Tour',
});
List<Rect> _targetRects() {
@ -126,14 +133,16 @@ class OnboardingTourOverlay extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Step $stepNumber of $totalSteps',
style: Theme.of(context).textTheme.labelMedium?.copyWith(
color: colorScheme.primary,
fontWeight: FontWeight.w700,
),
),
const SizedBox(height: 6),
if (totalSteps > 1) ...[
Text(
'Step $stepNumber of $totalSteps',
style: Theme.of(context).textTheme.labelMedium?.copyWith(
color: colorScheme.primary,
fontWeight: FontWeight.w700,
),
),
const SizedBox(height: 6),
],
Text(title, style: Theme.of(context).textTheme.titleLarge),
const SizedBox(height: 8),
Text(description, style: Theme.of(context).textTheme.bodyMedium),
@ -141,7 +150,7 @@ class OnboardingTourOverlay extends StatelessWidget {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TextButton(onPressed: onSkip, child: const Text('Skip Tour')),
TextButton(onPressed: onSkip, child: Text(skipLabel)),
FilledButton(onPressed: onNext, child: Text(isLastStep ? 'Got It' : 'Next')),
],
),