Files
hash-wallet/lib/new-ui/widgets/charts_page/chart_view.dart
T
b88fbf32ae charts (#3162)
* charts (wip)

* charts (wip)

* wip

* add asset grid

* split files

* logic wip

* proper getPrices logic

* viewmodel (wip)

* charts

* remove unused import

* remove restricted import...?

* fix background gradient when scrolling

* add safeguards for broken db

* save new pin on removal

* add safeguards for concurrency

* add haptic feedback

* fix haptic feedback

* fix fiat ticker

* reduce chart padding

* add line touch indicator

* improve touch target size on range selector

* add date/time display when viewing past amount

* merge

* remove iconSvgPath reference

* merge

* fix state for date display

* merge

* auto-reformat

* only load charts when page is opened

* merge

* reformat and apply lints

* refactor to use `Money` instead of storing amount in `String`

* add slop comment

* fix exception on division by zero

* ci

* workaround toDouble being removed

* disable strict parsing and rounding

* fix abs()

* use new currency picker sheet

* safeguard for max flutter-supported decimals

* fix amount precision

* adjust to new buy/sell

* Update lib/new-ui/pages/charts_page.dart

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>

* adjust buy/sell di

* replace -> ignore

* reformat

---------

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2026-09-22 21:32:38 +03:00

71 lines
2.3 KiB
Dart

import "package:cake_wallet/new-ui/model/charts/price_data.dart";
import "package:cake_wallet/new-ui/model/charts/util/price_change_direction.dart";
import "package:fl_chart/fl_chart.dart";
import "package:flutter/material.dart";
class PriceChart extends StatelessWidget {
const PriceChart({
super.key,
required this.height,
required this.prices,
required this.direction,
required this.touchCallback,
});
final List<PriceData> prices;
final double height;
final PriceChangeDirection direction;
final Function(FlTouchEvent, LineTouchResponse?) touchCallback;
@override
Widget build(BuildContext context) {
final chartPoints = prices.map((entry) {
final x = entry.time.millisecondsSinceEpoch.toDouble();
final y = double.parse(entry.quote.toString());
return FlSpot(x, y);
}).toList();
return SizedBox(
height: height,
child: LineChart(
LineChartData(
gridData: const FlGridData(show: false),
titlesData: const FlTitlesData(show: false),
borderData: FlBorderData(show: false),
lineBarsData: [
LineChartBarData(
spots: chartPoints,
gradient: LinearGradient(colors: [direction.color.withAlpha(25), direction.color]),
barWidth: 1.5,
isStrokeCapRound: true,
dotData: const FlDotData(show: false),
belowBarData: BarAreaData(show: false),
),
],
lineTouchData: LineTouchData(
enabled: true,
getTouchLineStart: (barData, spotIndex) => -double.infinity,
getTouchLineEnd: (barData, spotIndex) => double.infinity,
getTouchedSpotIndicator: (barData, spotIndexes) => spotIndexes
.map(
(index) => TouchedSpotIndicatorData(
FlLine(
strokeWidth: 1,
color: direction.color.withAlpha(80),
dashArray: [4, 4],
),
const FlDotData(),
),
)
.toList(),
touchTooltipData: LineTouchTooltipData(
getTooltipItems: (touchedSpots) => touchedSpots.map((spot) => null).toList(),
),
touchCallback: touchCallback,
),
),
),
);
}
}