前提
flutterで線グラフを作成しようとしています
実現したいこと
本日の日付を横軸の一番右した線グラフを作成したいです
発生している問題・エラーメッセージ
下記4つのエラーが出ています In a const constructor, a value of type 'Null' can't be assigned to the field 'x', which has type 'double'. Try using a subtype, or removing the keyword 'const'. A value of type 'Null' can't be assigned to a parameter of type 'double' in a const constructor. (Documentation) Try using a subtype, or removing the keyword 'const'. Arguments of a constant creation must be constant expressions. (Documentation) Try making the argument a valid constant, or use 'new' to call the constructor. The values in a const list literal must be constants. (Documentation) Try removing the keyword 'const' from the list literal.
該当のソースコード
dart
1import 'package:flutter/material.dart'; 2import 'package:flutter/cupertino.dart'; 3import 'package:fl_chart/fl_chart.dart'; 4 5void main() { 6 runApp(const MyApp()); 7} 8 9class MyApp extends StatelessWidget { 10 const MyApp({Key? key}) : super(key: key); 11 12 // This widget is the root of your application. 13 14 Widget build(BuildContext context) { 15 return MaterialApp( 16 title: 'Flutter Demo', 17 theme: ThemeData( 18 19 primarySwatch: Colors.blue, 20 ), 21 home: const MyHomePage(title: 'Flutter Demo Home Page'), 22 ); 23 } 24} 25 26class MyHomePage extends StatefulWidget { 27 const MyHomePage({Key? key, required this.title}) : super(key: key); 28 29 final String title; 30 31 32 State<MyHomePage> createState() => _MyHomePageState(); 33} 34 35class _MyHomePageState extends State<MyHomePage> { 36 37 DateTime a = DateTime.now(); 38 String b = DateTime.now().toString(); 39 String c = DateTime.now().toString().substring(8,10); 40 double daysubstring = double.parse(DateTime.now().toString().substring(8,10)); 41 42 43 Widget build(BuildContext context) { 44 45 return Scaffold( 46 appBar: AppBar( 47 48 title: Text(widget.title), 49 ), 50 body: Center( 51 child: Column( 52 mainAxisAlignment: MainAxisAlignment.center, 53 children: [ 54 Container( 55 padding: const EdgeInsets.only(left: 8, right: 32), 56 height: 300, 57 width: double.infinity, 58 child: LineChart(LineChartData( 59 backgroundColor: Colors.grey[200], 60 // titlesData: _titles, 61 minX: 1, 62 maxX: 12, 63 minY: 0, 64 maxY: 30, 65 lineBarsData: [ 66 LineChartBarData( 67 isCurved: true, 68 color: Colors.red[400], 69 barWidth: 4, 70 dotData: FlDotData(show: true), 71 spots: const [ 72 FlSpot(1, 5.4), 73 FlSpot(2, 8.5), 74 FlSpot(3, 12.8), 75 FlSpot(4, 15.1), 76 FlSpot(5, 19.6), 77 FlSpot(6, 22.7), 78 FlSpot(7, 25.9), 79 FlSpot(8, 27.4), 80 FlSpot(9, 22.3), 81 FlSpot(10, 18.2), 82 FlSpot(11, 13.7), 83 FlSpot(daysubstring, 7.9), 84 ], 85 ), 86 ])), 87 ), 88 ], 89 ), 90 ), 91 ); 92 } 93} 94
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。