feat(juice): button press feedback + fade screen transitions
Adds PressableScale (0.94 squish on tap-down) around the Adventure FilledButton, Classic OutlinedButton, and each season-map stage node. Replaces all in-app MaterialPageRoute pushes with a gentle fade+scale PageRouteBuilder (320ms in, 240ms out) via a new fadeRoute helper.
This commit is contained in:
@@ -6,6 +6,8 @@ import '../../game/models/stage.dart';
|
|||||||
import '../../l10n/gen/app_localizations.dart';
|
import '../../l10n/gen/app_localizations.dart';
|
||||||
import '../../state/providers.dart';
|
import '../../state/providers.dart';
|
||||||
import '../widgets/banner_ad_slot.dart';
|
import '../widgets/banner_ad_slot.dart';
|
||||||
|
import '../widgets/fade_route.dart';
|
||||||
|
import '../widgets/pressable_scale.dart';
|
||||||
import '../widgets/season_background.dart';
|
import '../widgets/season_background.dart';
|
||||||
import 'game_screen.dart';
|
import 'game_screen.dart';
|
||||||
import 'season_map_screen.dart';
|
import 'season_map_screen.dart';
|
||||||
@@ -67,43 +69,45 @@ class HomeScreen extends ConsumerWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
const SizedBox(height: 44),
|
const SizedBox(height: 44),
|
||||||
FilledButton(
|
PressableScale(
|
||||||
style: FilledButton.styleFrom(
|
child: FilledButton(
|
||||||
padding: const EdgeInsets.symmetric(
|
style: FilledButton.styleFrom(
|
||||||
horizontal: 56, vertical: 18),
|
padding: const EdgeInsets.symmetric(
|
||||||
textStyle: Theme.of(context).textTheme.titleLarge,
|
horizontal: 56, vertical: 18),
|
||||||
|
textStyle: Theme.of(context).textTheme.titleLarge,
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
if (!(ModalRoute.of(context)?.isCurrent ?? true)) return;
|
||||||
|
Navigator.of(context).push(
|
||||||
|
fadeRoute(const SeasonMapScreen()),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: Text(l10n.adventure),
|
||||||
),
|
),
|
||||||
onPressed: () {
|
|
||||||
if (!(ModalRoute.of(context)?.isCurrent ?? true)) return;
|
|
||||||
Navigator.of(context).push(
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (_) => const SeasonMapScreen()),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: Text(l10n.adventure),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 14),
|
const SizedBox(height: 14),
|
||||||
OutlinedButton(
|
PressableScale(
|
||||||
style: OutlinedButton.styleFrom(
|
child: OutlinedButton(
|
||||||
padding: const EdgeInsets.symmetric(
|
style: OutlinedButton.styleFrom(
|
||||||
horizontal: 40, vertical: 14),
|
padding: const EdgeInsets.symmetric(
|
||||||
textStyle: Theme.of(context).textTheme.titleMedium,
|
horizontal: 40, vertical: 14),
|
||||||
|
textStyle: Theme.of(context).textTheme.titleMedium,
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
if (!(ModalRoute.of(context)?.isCurrent ?? true)) return;
|
||||||
|
ref.read(seasonFlowProvider.notifier).clear();
|
||||||
|
ref.read(analyticsProvider).endlessStart();
|
||||||
|
ref.read(gameSessionProvider.notifier).startStage(
|
||||||
|
StageConfig.endless(
|
||||||
|
seed: DateTime.now().millisecondsSinceEpoch,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
Navigator.of(context).push(
|
||||||
|
fadeRoute(const GameScreen()),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: Text(l10n.classic),
|
||||||
),
|
),
|
||||||
onPressed: () {
|
|
||||||
if (!(ModalRoute.of(context)?.isCurrent ?? true)) return;
|
|
||||||
ref.read(seasonFlowProvider.notifier).clear();
|
|
||||||
ref.read(analyticsProvider).endlessStart();
|
|
||||||
ref.read(gameSessionProvider.notifier).startStage(
|
|
||||||
StageConfig.endless(
|
|
||||||
seed: DateTime.now().millisecondsSinceEpoch,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
Navigator.of(context).push(
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (_) => const GameScreen()),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: Text(l10n.classic),
|
|
||||||
),
|
),
|
||||||
if (best > 0) ...[
|
if (best > 0) ...[
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
@@ -127,7 +131,7 @@ class HomeScreen extends ConsumerWidget {
|
|||||||
child: IconButton(
|
child: IconButton(
|
||||||
icon: const Icon(Icons.settings, color: Colors.white70),
|
icon: const Icon(Icons.settings, color: Colors.white70),
|
||||||
onPressed: () => Navigator.of(context).push(
|
onPressed: () => Navigator.of(context).push(
|
||||||
MaterialPageRoute(builder: (_) => const SettingsScreen()),
|
fadeRoute(const SettingsScreen()),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import '../../game/models/season.dart';
|
|||||||
import '../../state/providers.dart';
|
import '../../state/providers.dart';
|
||||||
import '../theme/palette.dart';
|
import '../theme/palette.dart';
|
||||||
import '../widgets/banner_ad_slot.dart';
|
import '../widgets/banner_ad_slot.dart';
|
||||||
|
import '../widgets/fade_route.dart';
|
||||||
import '../widgets/map_layout.dart';
|
import '../widgets/map_layout.dart';
|
||||||
|
import '../widgets/pressable_scale.dart';
|
||||||
import '../widgets/season_background.dart';
|
import '../widgets/season_background.dart';
|
||||||
import '../widgets/tile_painter.dart';
|
import '../widgets/tile_painter.dart';
|
||||||
import 'game_screen.dart';
|
import 'game_screen.dart';
|
||||||
@@ -193,79 +195,81 @@ class _JourneyMapState extends ConsumerState<_JourneyMap> {
|
|||||||
key: Key('stage_node_$i'),
|
key: Key('stage_node_$i'),
|
||||||
left: center.dx - size / 2,
|
left: center.dx - size / 2,
|
||||||
top: center.dy - size / 2,
|
top: center.dy - size / 2,
|
||||||
child: GestureDetector(
|
child: PressableScale(
|
||||||
onTap: !isUnlocked
|
child: GestureDetector(
|
||||||
? null
|
onTap: !isUnlocked
|
||||||
: () {
|
? null
|
||||||
ref
|
: () {
|
||||||
.read(seasonFlowProvider.notifier)
|
ref
|
||||||
.startSeasonStage(widget.pack, i);
|
.read(seasonFlowProvider.notifier)
|
||||||
Navigator.of(context).push(
|
.startSeasonStage(widget.pack, i);
|
||||||
MaterialPageRoute(builder: (_) => const GameScreen()),
|
Navigator.of(context).push(
|
||||||
);
|
fadeRoute(const GameScreen()),
|
||||||
},
|
);
|
||||||
child: Column(
|
},
|
||||||
mainAxisSize: MainAxisSize.min,
|
child: Column(
|
||||||
children: [
|
mainAxisSize: MainAxisSize.min,
|
||||||
Container(
|
children: [
|
||||||
width: size,
|
Container(
|
||||||
height: size,
|
width: size,
|
||||||
alignment: Alignment.center,
|
height: size,
|
||||||
decoration: BoxDecoration(
|
alignment: Alignment.center,
|
||||||
shape: BoxShape.circle,
|
decoration: BoxDecoration(
|
||||||
gradient: isUnlocked
|
shape: BoxShape.circle,
|
||||||
? LinearGradient(
|
gradient: isUnlocked
|
||||||
begin: Alignment.topLeft,
|
? LinearGradient(
|
||||||
end: Alignment.bottomRight,
|
begin: Alignment.topLeft,
|
||||||
colors: isCurrent
|
end: Alignment.bottomRight,
|
||||||
? [
|
colors: isCurrent
|
||||||
lighten(colors.accent, 0.25),
|
? [
|
||||||
colors.accent,
|
lighten(colors.accent, 0.25),
|
||||||
darken(colors.accent, 0.2),
|
colors.accent,
|
||||||
]
|
darken(colors.accent, 0.2),
|
||||||
: [
|
]
|
||||||
const Color(0xFFFFE9A8),
|
: [
|
||||||
const Color(0xFFFFD166),
|
const Color(0xFFFFE9A8),
|
||||||
const Color(0xFFE0AC3B),
|
const Color(0xFFFFD166),
|
||||||
],
|
const Color(0xFFE0AC3B),
|
||||||
)
|
],
|
||||||
: null,
|
)
|
||||||
color: isUnlocked ? null : GamePalette.lockedNode,
|
: null,
|
||||||
boxShadow: isCurrent
|
color: isUnlocked ? null : GamePalette.lockedNode,
|
||||||
? [
|
boxShadow: isCurrent
|
||||||
BoxShadow(
|
? [
|
||||||
color: colors.accent.withValues(alpha: 0.7),
|
BoxShadow(
|
||||||
blurRadius: 22,
|
color: colors.accent.withValues(alpha: 0.7),
|
||||||
|
blurRadius: 22,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
child: isUnlocked
|
||||||
|
? Text(
|
||||||
|
'${i + 1}',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: isCurrent ? 22 : 17,
|
||||||
|
fontWeight: FontWeight.w900,
|
||||||
|
color: isCurrent
|
||||||
|
? Colors.white
|
||||||
|
: const Color(0xFF5A4200),
|
||||||
),
|
),
|
||||||
]
|
)
|
||||||
: null,
|
: const Icon(Icons.lock, color: Colors.white24, size: 20),
|
||||||
),
|
),
|
||||||
child: isUnlocked
|
if (isUnlocked && !isCurrent)
|
||||||
? Text(
|
Row(
|
||||||
'${i + 1}',
|
mainAxisSize: MainAxisSize.min,
|
||||||
style: TextStyle(
|
children: [
|
||||||
fontSize: isCurrent ? 22 : 17,
|
for (var s = 0; s < 3; s++)
|
||||||
fontWeight: FontWeight.w900,
|
Icon(
|
||||||
color: isCurrent
|
Icons.star,
|
||||||
? Colors.white
|
size: 13,
|
||||||
: const Color(0xFF5A4200),
|
color: s < stars ? Colors.amber : Colors.white24,
|
||||||
),
|
),
|
||||||
)
|
],
|
||||||
: const Icon(Icons.lock, color: Colors.white24, size: 20),
|
),
|
||||||
),
|
],
|
||||||
if (isUnlocked && !isCurrent)
|
),
|
||||||
Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
for (var s = 0; s < 3; s++)
|
|
||||||
Icon(
|
|
||||||
Icons.star,
|
|
||||||
size: 13,
|
|
||||||
color: s < stars ? Colors.amber : Colors.white24,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
// lib/ui/widgets/fade_route.dart
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
/// A gentle fade(+slight scale) page transition for in-app navigation.
|
||||||
|
Route<T> fadeRoute<T>(Widget page) {
|
||||||
|
return PageRouteBuilder<T>(
|
||||||
|
transitionDuration: const Duration(milliseconds: 320),
|
||||||
|
reverseTransitionDuration: const Duration(milliseconds: 240),
|
||||||
|
pageBuilder: (_, _, _) => page,
|
||||||
|
transitionsBuilder: (_, animation, _, child) {
|
||||||
|
final curved =
|
||||||
|
CurvedAnimation(parent: animation, curve: Curves.easeOutCubic);
|
||||||
|
return FadeTransition(
|
||||||
|
opacity: curved,
|
||||||
|
child: ScaleTransition(
|
||||||
|
scale: Tween(begin: 0.98, end: 1.0).animate(curved),
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// lib/ui/widgets/pressable_scale.dart
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
/// Wraps a tappable child with a quick scale-down on press for tactile feel.
|
||||||
|
/// If [onTap] is provided it handles the tap; otherwise the child's own
|
||||||
|
/// gesture/button handles it and this only adds the visual squish.
|
||||||
|
class PressableScale extends StatefulWidget {
|
||||||
|
const PressableScale({super.key, required this.child, this.onTap});
|
||||||
|
|
||||||
|
final Widget child;
|
||||||
|
final VoidCallback? onTap;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<PressableScale> createState() => _PressableScaleState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PressableScaleState extends State<PressableScale> {
|
||||||
|
bool _down = false;
|
||||||
|
void _set(bool v) => setState(() => _down = v);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return GestureDetector(
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
onTapDown: (_) => _set(true),
|
||||||
|
onTapUp: (_) => _set(false),
|
||||||
|
onTapCancel: () => _set(false),
|
||||||
|
onTap: widget.onTap,
|
||||||
|
child: AnimatedScale(
|
||||||
|
scale: _down ? 0.94 : 1.0,
|
||||||
|
duration: const Duration(milliseconds: 90),
|
||||||
|
curve: Curves.easeOut,
|
||||||
|
child: widget.child,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user