File tree Expand file tree Collapse file tree 3 files changed +13
-10
lines changed Expand file tree Collapse file tree 3 files changed +13
-10
lines changed Original file line number Diff line number Diff line change 11org.gradle.jvmargs =-Xmx1536M
2- org.gradle.java.home =C:\\Program Files\\Java\\jdk1.8.0_144
3- android.enableR8 =true
42android.useAndroidX =true
53android.enableJetifier =true
Original file line number Diff line number Diff line change 11[
22 {
3- "year " : " Jan" ,
3+ "month " : " Jan" ,
44 "sales" : 35.0
55 },
66 {
7- "year " : " Feb" ,
7+ "month " : " Feb" ,
88 "sales" : 28.0
99 },
1010 {
11- "year " : " Mar" ,
11+ "month " : " Mar" ,
1212 "sales" : 34.0
1313 },
1414 {
15- "year " : " Apr" ,
15+ "month " : " Apr" ,
1616 "sales" : 32.0
1717 },
1818 {
19- "year " : " May" ,
19+ "month " : " May" ,
2020 "sales" : 40.0
2121 }
2222]
Original file line number Diff line number Diff line change @@ -30,15 +30,20 @@ class _MyHomePageState extends State<MyHomePage> {
3030 List <SalesData > chartData = [];
3131
3232 Future loadSalesData () async {
33- String jsonString = await rootBundle. loadString ( 'assets/data.json' );
33+ final String jsonString = await getJsonFromAssets ( );
3434 final dynamic jsonResponse = json.decode (jsonString);
3535 for (Map <String , dynamic > i in jsonResponse) {
3636 chartData.add (SalesData .fromJson (i));
3737 }
3838 }
3939
40+ Future <String > getJsonFromAssets () async {
41+ return await rootBundle.loadString ('assets/data.json' );
42+ }
43+
4044 @override
4145 void initState () {
46+ loadSalesData ();
4247 super .initState ();
4348 }
4449
@@ -50,9 +55,9 @@ class _MyHomePageState extends State<MyHomePage> {
5055 ),
5156 body: Center (
5257 child: FutureBuilder (
53- future: loadSalesData (),
58+ future: getJsonFromAssets (),
5459 builder: (context, snapshot) {
55- if (chartData.isNotEmpty ) {
60+ if (snapshot.hasData ) {
5661 return SfCartesianChart (
5762 primaryXAxis: CategoryAxis (),
5863 // Chart title
You can’t perform that action at this time.
0 commit comments