【发布时间】:2021-08-06 12:34:32
【问题描述】:
当我将其更改为列表时,出现此错误:
E/flutter ( 6925): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: NoSuchMethodError: The method '[]' was called on null.
E/flutter ( 6925): Receiver: null
E/flutter ( 6925): Tried calling: []("interest")
这是我的小部件构建:
@override
Widget build(BuildContext context) {
timeDilation = 2.0;
return WillPopScope(
onWillPop: () async => false,
child: Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: kYellow,
appBar: AppBar(
leading: Hero(
tag: 'animasilogo',
child: Container(
margin: EdgeInsets.all(5.0),
child: Image.asset('assets/img/lemonlime.png'),
),
),
title: Text('Simulator'),
actions: [
IconButton(
icon: const Icon(Icons.exit_to_app),
onPressed: () {
SharedPref.signOut();
Navigator.pushNamed(context, LoginScreen.id);
},
)
],
),
body: RefreshIndicator(
onRefresh: () => _fetchData(),
child: loading
? Center(child: CircularProgressIndicator())
: ListView.builder(
itemCount: _loanmodel.length,
itemBuilder: (context, i) {
final data =_loanmodel[i];
return Container(
alignment: Alignment.topLeft,
margin: const EdgeInsets.only(top: 15.0),
padding: EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("Interest : " + data.interest , style: DefaultTextStyle.of(context).style.apply(fontSizeFactor: 1.5), textAlign: TextAlign.justify),
Text("Balance : " + data.balance, style: DefaultTextStyle.of(context).style.apply(fontSizeFactor: 1.5),textAlign: TextAlign.justify),
Text("Principal : " + data.principal, style: DefaultTextStyle.of(context).style.apply(fontSizeFactor: 1.5),textAlign: TextAlign.justify),
Text("Installment :" + data.installment, style: DefaultTextStyle.of(context).style.apply(fontSizeFactor: 1.5),textAlign: TextAlign.justify),
Divider(
color: Colors.black,
),
],
),
);
},
),
),
),
);
}
}
API、Model等功能可以查看我在Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Iterable<dynamic>' flutter的另一篇文章
【问题讨论】:
-
数据好像是空的。所以你应该验证
data不为空。 -
数据来自value periodtime、interestpermonth和loanamountrequest。输入该值时,将显示 [{"No":0,"interest":"0.00","balance":"15,000,000.00","principal":"0.00","Installment":"0.00","状态":true},
标签: flutter