我想在颤振中建立一个同步融合图表。我从 firebase 实时数据库中检索数据。数据将显示在图表中。我在这里遇到了问题。他们说'毫秒自纪元'。但我的代码中没有它。但是有一个问题。这是我的代码:
import 'dart:async';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
class Chart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: HolyChart(),
),
);
}
}
class HolyChart extends StatefulWidget {
@override
_HolyChartState createState() => _HolyChartState();
}
class _HolyChartState extends State<HolyChart> {
Timer _timer;
int _count = 0;
ChartSeriesController _seriesController;
final _dbReference = FirebaseDatabase.instance.reference();
List _chartData = <ChartData>[];
int _values;
@override
void dispose() {
_timer?.cancel();
super.dispose();
}
_updateData(Timer timer) {
_chartData.add(ChartData(_count, _values));
if (_chartData.length == 20) {
_chartData.removeAt(0);
_seriesController.updateDataSource(
addedDataIndexes: <int>[_chartData.length - 1],
removedDataIndexes: <int>[0]);
}
_count = _count + 1;
}
@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: _dbReference.child("Data").onValue,
builder: (context, snapshot) {
Widget widget;
if (snapshot.hasData &&
!snapshot.hasError &&
snapshot.data.snapshot.value != null) {
_values = snapshot.data.snapshot.value["Moisture"];
if (_values != null) {
_timer = Timer.periodic(Duration(seconds: 3), _updateData(_timer));
}
widget = Container(
child: SfCartesianChart(
tooltipBehavior: TooltipBehavior(enable: true),
primaryXAxis: DateTimeAxis(),
series: <LineSeries<ChartData, int>>[
LineSeries<ChartData, int>(
dataSource: _chartData,
xValueMapper: (ChartData data, _) => data.xAxisValue,
yValueMapper: (ChartData data, _) => data.yAxisValue,
)
],
),
);
} else {
widget = Center(child: CircularProgressIndicator());
}
return widget;
},
);
}
}
class ChartData {
ChartData(this.xAxisValue, this.yAxisValue);
ChartData.fromMap(this.xAxisValue, this.yAxisValue);
final int xAxisValue;
final int yAxisValue;
}
这就是我的代码的问题。函数'millisecondsSinceEpoch'是什么意思?b
The following NoSuchMethodError was thrown building LayoutBuilder:
Class 'int' has no instance getter 'millisecondsSinceEpoch'.
Receiver: 0
Tried calling: millisecondsSinceEpoch
谁能帮我??非常感谢你的帮助...