![](/img/trans.png)
[英]Unhandled Exception NoSuchMethodError: The method '[]' was called on null in flutter
[英]Unhandled Exception: NoSuchMethodError: The method '[]' was called on null on flutter
當我將其更改為列表時,出現此錯誤:
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,
),
],
),
);
},
),
),
),
);
}
}
For API, Model and other function, you can check my another post in Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Iterable<dynamic>' flutter
確保您收到的部分數據不是 null。 應該收到“興趣”的部分是 null 並且因為它是您嘗試使用的數據的第一部分,所以其他部分也可能是 null
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.