我想从数据库中的“ Commande”表中列出数据时遇到问题,我不知道问题出在哪里,通常idCommande是数据库中的自动增量,但是在这里它仍然显示为空,有人可以帮我吗,这是我为了列出订单而实现的代码,我注释了出现错误的行
StreamBuilder<List<CommandeWithClient>> _buildCommandeList(
BuildContext context) {
final dao = Provider.of<CommandeDao>(context);
return StreamBuilder(
stream: showCompleted ? dao.watchCompletedCommandes() : dao
.watchAllCommandes(),
builder: (context, AsyncSnapshot<List<CommandeWithClient>> snapshot) {
final commandes = snapshot.data ?? List();
return ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: commandes.length,
itemBuilder: (_, index) {
final itemCommande = commandes[index];
return _buildListItem(itemCommande, dao);//the line that gives me the error
},
);
},
);
}
Widget _buildListItem(CommandeWithClient itemCommande, CommandeDao dao) {
return Slidable(
actionPane: SlidableDrawerActionPane(),
secondaryActions: <Widget>[
new IconSlideAction(
caption: 'Delete',
color: Colors.red,
icon: Icons.delete,
onTap: () => dao.deleteCommande(itemCommande.commande),
)
],
child: CheckboxListTile(
title: Text(itemCommande.commande.idCommande.toString()), //here too
value: itemCommande.commande.completed,
onChanged: (newValue) {
dao.updateCommande(
itemCommande.commande.copyWith(completed: newValue));
},
),
);
}
这是错误:
/flutter (21715): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (21715): The following NoSuchMethodError was thrown building:
I/flutter (21715): The getter 'idCommande' was called on null.
I/flutter (21715): Receiver: null
I/flutter (21715): Tried calling: idCommande
I/flutter (21715):
I/flutter (21715): When the exception was thrown, this was the stack:
I/flutter (21715): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5)
I/flutter (21715): #1 HomePage._buildListItem (package:inwi_app/HomePage.dart:617:43)
I/flutter (21715): #2 HomePage._buildCommandeList.<anonymous closure>.<anonymous closure> (package:inwi_app/HomePage.dart:597:20)
I/flutter (21715): #3 SliverChildBuilderDelegate.build (package:flutter/src/widgets/sliver.dart:442:15)
I/flutter (21715): #4 SliverMultiBoxAdaptorElement._build.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1153:67)
I/flutter (21715): #5 _HashMap.putIfAbsent (dart:collection-patch/collection_patch.dart:137:29)
I/flutter (21715): #6 SliverMultiBoxAdaptorElement._build (package:flutter/src/widgets/sliver.dart:1153:26)
I/flutter (21715): #7 SliverMultiBoxAdaptorElement.createChild.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1166:55)
I/flutter (21715): #8 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2320:19)
I/flutter (21715): #9 SliverMultiBoxAdaptorElement.createChild (package:flutter/src/widgets/sliver.dart:1159:11)
I/flutter (21715): #10 RenderSliverMultiBoxAdaptor._createOrObtainChild.<anonymous closure> (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:354:23)
I/flutter (21715): #11 RenderObject.invokeLayoutCallback.<anonymous closure> (package:flutter/src/rendering/object.dart:1715:58)
I/flutter (21715): #12 PipelineOwner._enableMutationsToDirtySubtrees (package:flutter/src/rendering/object.dart:796:15)
I/flutter (21715): #13 RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:1715:13)
I/flutter (21715): #14 RenderSliverMultiBoxAdaptor._createOrObtainChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:343:5)
I/flutter (21715): #15 RenderSliverMultiBoxAdaptor.addInitialChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:427:5)
I/flutter (21715): #16 RenderSliverList.performLayout (package:flutter/src/rendering/sliver_list.dart:78:12)
I/flutter (21715): #17 RenderObject.layout (package:flutter/src/rendering/object.dart:1619:7)
I/flutter (21715): #18 RenderSliverPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:181:11)
I/flutter (21715): #19 RenderObject.layout (package:flutter/src/rendering/object.dart:1619:7)
I/flutter (21715): #20 RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:406:13)
I/flutter (21715): #21 RenderShrinkWrappingViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1663:12)
I/flutter (21715): #22 RenderShrinkWrappingViewport.performLayout (package:flutter/src/rendering/viewport.dart:1626:20)
I/flutter (21715): #23 RenderObject.layout (package:flutter/src/rendering/object.dart:1619:7)