This commit is contained in:
2026-02-15 15:47:39 +09:00
parent adb6c2d20b
commit 0420e23939
4 changed files with 152 additions and 5 deletions
+17 -5
View File
@@ -1,5 +1,7 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../providers/settings_provider.dart';
class ShakeWidget extends StatefulWidget {
final Widget child;
@@ -10,7 +12,7 @@ class ShakeWidget extends StatefulWidget {
const ShakeWidget({
super.key,
required this.child,
this.shakeOffset = 10.0,
this.shakeOffset = 30.0,
this.shakeCount = 3,
this.duration = const Duration(milliseconds: 400),
});
@@ -46,14 +48,24 @@ class ShakeWidgetState extends State<ShakeWidget>
@override
Widget build(BuildContext context) {
// Read settings from provider (listen: false because we only read in build,
// actually we want to listen to updates if settings change while looking at it?
// But usually ShakeWidget is in BattleScreen.
// However, the previous implementation used `widget.shakeCount` and `widget.shakeOffset`.
// We should prefer provider values if available, or allow overrides?
// The prompt says "shakeWidget에서 shakeCount, shakeOffset을 settings에서 설정할 수 있게 globalOption으로 설정해야해."
// So we use Provider values.
final settings = context.watch<SettingsProvider>();
final shakeCount = settings.shakeCount;
final shakeOffset = settings.shakeOffset;
return AnimatedBuilder(
animation: _controller,
builder: (context, child) {
final double sineValue = sin(
widget.shakeCount * 2 * pi * _controller.value,
);
final double sineValue = sin(shakeCount * 2 * pi * _controller.value);
return Transform.translate(
offset: Offset(sineValue * widget.shakeOffset, 0),
offset: Offset(sineValue * shakeOffset, 0),
child: child,
);
},