flutter-test - 方法 '_subFromInteger' 在 null 上被调用
问题描述
我已经从教程中编写了这段代码,但是那个大师没有回答我。
this is my code
import 'package:persian_date/persian_date.dart';
import 'dart:convert' as convert;
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
class ShowInfo extends StatefulWidget {
final country;
ShowInfo({this.country});
@override
_ShowInfoState createState() => _ShowInfoState();
}
class _ShowInfoState extends State<ShowInfo> {
List more_info = List();
bool loading = true;
PersianDate persianDate = PersianDate();
var toDate;
var fromDate;
var date = DateTime.now();
@override
void initState() {
// TODO: implement initState
super.initState();
toDate = date.toString().split(' ')[0];
fromDate =
DateTime(date.year, date.month - 1, date.day).toString().split(' ')[0];
_setData();
}
@override
Widget build(BuildContext context) {
return Directionality(
textDirection: TextDirection.rtl,
child: Scaffold(
body: NestedScrollView(
headerSliverBuilder:
(BuildContext context, bool innerBoxIsScrolled) {
return [
SliverAppBar(
backgroundColor: Colors.indigo[600],
centerTitle: true,
actions: [
Image.asset('assets/flags/${widget.country['ISO2']}.png'
.toLowerCase()),
],
title: Text(
'${widget.country['Slug']}'.toUpperCase(),
style: TextStyle(
fontFamily: 'Yekan',
color: Colors.white,
),
),
elevation: 7,
brightness: Brightness.dark,
)
];
},
body: _biuldBody()),
),
);
}
Widget _biuldBody() {
return Column(children: [
Expanded(
child: ListView.builder(
padding: EdgeInsets.zero,
itemCount: more_info.length,
itemBuilder: (BuildContext context, int index) {
var showinfo = more_info[index];
if (index == 0) {
print('has done');
return Container();
}
;
return Container(
padding: EdgeInsets.symmetric(horizontal: 5, vertical: 5),
child: Material(
elevation: 3,
child: ListTile(
title: Row(
children: [
Text(
'مبتلایان جدید :${more_info[index]['Confirmed'] - more_info[index - 1]['Comfirmeds']}',
style: TextStyle(
fontFamily: 'Tekan',
fontWeight: FontWeight.bold),
)
],
),
subtitle: Text(
'${persianDate.gregorianToJalali(showinfo['Date'], "yyyy\/m\/d ")}'),
),
),
);
}))
]);
}
void _setData() async {
var url =
'https://api.covid19api.com/country/${widget.country['Slug']}?from=${fromDate}T00:00:00Z&to=${toDate}T00:00:00Z';
print(url);
var responce = await http.get(url);
if (responce.statusCode == 200) {
var jsonResponc = convert.jsonDecode(responce.body);
more_info.addAll(jsonResponc);
}
setState(() {
loading = false;
});
}
}
这是错误:
The following NoSuchMethodError was thrown building:
The method '_subFromInteger' was called on null.
Receiver: null
Tried calling: _subFromInteger(5374)
我犯了这个错误,我不知道该怎么办