After correcting the bug for candle for mobile version

This commit is contained in:
Your Name 2026-11-04 17:55:24 +02:00
parent dff2730edc
commit 0b4ebee7d8
5 changed files with 72 additions and 5 deletions

View File

@ -344,6 +344,9 @@ class PredictionBloc extends Bloc<PredictionEvent, PredictionState> {
add(const PredictionRefreshTick(forceGameState: true));
add(const PredictionBalancesRefreshRequested());
add(const PredictionHistoryPageRequested(1));
// Missed candle.append frames leave price cliffs until a full reload;
// replace the local series from HTTP after every reconnect.
add(const PredictionCandlesReloadRequested());
}
}
@ -1212,6 +1215,7 @@ class PredictionBloc extends Bloc<PredictionEvent, PredictionState> {
add(const PredictionBalancesRefreshRequested());
add(const PredictionHistoryPageRequested(1));
add(const PredictionRefreshTick(forceGameState: true));
add(const PredictionCandlesReloadRequested());
}
break;
case 'multi.updated':
@ -1246,7 +1250,18 @@ class PredictionBloc extends Bloc<PredictionEvent, PredictionState> {
final candle = msg['candle'];
if (candle is Map<String, dynamic>) {
final c = OhlcCandleModel.fromJson(candle);
emit(state.copyWith(candles: _mergeCandles(state.candles, [c])));
final existing = state.candles;
if (existing.isNotEmpty) {
final last = existing.last;
final intervalMs =
state.selectedIntervalMinutes * 60 * 1000;
// More than ~1.5 intervals between bars ⇒ we missed WS frames.
if (c.openMs - last.openMs > (intervalMs * 3) ~/ 2) {
add(const PredictionCandlesReloadRequested());
break;
}
}
emit(state.copyWith(candles: _mergeCandles(existing, [c])));
}
break;
case 'bet.accepted':
@ -1439,7 +1454,7 @@ class PredictionBloc extends Bloc<PredictionEvent, PredictionState> {
Emitter<PredictionState> emit,
) async {
emit(state.copyWith(
isLoadingOlderCandles: state.candles.isEmpty,
isLoadingOlderCandles: true,
clearCandlesError: true,
));
try {

View File

@ -291,6 +291,9 @@ class _PredictionScreenState extends State<PredictionScreen> with WidgetsBinding
hasMoreOlder: state.hasMoreOlderCandles,
instrument: gs?.config.instrument ??
defaultCandlePredictInstrument,
onRefresh: () => context
.read<PredictionBloc>()
.add(const PredictionCandlesReloadRequested()),
),
),
if (context.watch<AuthBloc>().state.isAdmin &&

View File

@ -16,12 +16,15 @@ class CandleChartWidget extends StatefulWidget {
this.isLoadingOlder = false,
this.hasMoreOlder = true,
this.instrument = defaultCandlePredictInstrument,
this.onRefresh,
});
final List<OhlcCandleModel> candles;
final bool isLoadingOlder;
final bool hasMoreOlder;
final CandlePredictInstrument instrument;
/// Targeted reload of candle history (avoids full page refresh).
final VoidCallback? onRefresh;
static const double candleSlot = 14;
static const double chartHeight = 240;
@ -152,6 +155,35 @@ class _CandleChartWidgetState extends State<CandleChartWidget> {
return (start, end);
}
Widget _refreshControl(BuildContext context) {
final onRefresh = widget.onRefresh;
if (onRefresh == null) return const SizedBox.shrink();
if (widget.isLoadingOlder) {
return const SizedBox(
width: 36,
height: 36,
child: Padding(
padding: EdgeInsets.all(8),
child: CircularProgressIndicator(strokeWidth: 2),
),
);
}
return IconButton(
key: const Key('candle_chart_refresh'),
tooltip: context.strings.refreshCandles,
visualDensity: VisualDensity.compact,
padding: EdgeInsets.zero,
constraints: const BoxConstraints(minWidth: 36, minHeight: 36),
onPressed: onRefresh,
icon: Icon(
Icons.refresh_rounded,
size: 22,
color: Colors.white.withValues(alpha: 0.92),
shadows: const [Shadow(blurRadius: 8, color: Colors.black54)],
),
);
}
@override
Widget build(BuildContext context) {
final s = context.strings;
@ -165,7 +197,17 @@ class _CandleChartWidgetState extends State<CandleChartWidget> {
height: CandleChartWidget.chartHeight,
borderRadius: 12,
)
: Center(child: Text(s.chartNoData)),
: Stack(
children: [
Center(child: Text(s.chartNoData)),
if (widget.onRefresh != null)
Positioned(
right: 0,
top: 0,
child: _refreshControl(context),
),
],
),
);
}
@ -217,7 +259,13 @@ class _CandleChartWidgetState extends State<CandleChartWidget> {
),
),
),
if (widget.isLoadingOlder)
if (widget.onRefresh != null)
Positioned(
right: 4,
top: 2,
child: _refreshControl(context),
)
else if (widget.isLoadingOlder)
const Positioned(
right: 8,
top: 8,

View File

@ -463,6 +463,7 @@ class AppStrings {
String get walletBonus => t('Bonus', 'Bonus');
String get walletTest => t('Test', 'Test');
String get chartNoData => t('No chart data', 'Pas de données de graphique');
String get refreshCandles => t('Refresh candles', 'Actualiser les bougies');
String get chartScrollHint => t(
'Swipe horizontally to browse candle history',
'Faites glisser horizontalement pour parcourir l’historique',

View File

@ -1,7 +1,7 @@
name: prediqo_mobile
description: "Tloto mobile app - prediction games and crypto wallet."
publish_to: 'none'
version: 2.0.2+12
version: 2.0.2+13
environment:
sdk: ^3.9.2