我想要对List<Food>我得到的搜索请求。我使用了这样的查询方法:
_foodList.where((food) => food.name == userInputValue).toList();
但是,搜索要求我使用完整的文本和正确的文本大小写进行搜索。
如果我想处理 的汇编"dish",那么所有带有该词的食物名称都"dish"将显示在其中List?
我有一个案例要检查商店的营业时间和休息时间。我使用下面的代码解决这个问题:
final _openHours = 09;
final _openMinute = 00;
final _closeHours = 15;
final _closeMinute = 00;
var now = DateTime.now();
print(now);
var _open = new DateTime(now.year, now.month, now.day, _openHours, _openMinute, now.second);
var _close = new DateTime(now.year, now.month, now.day, _closeHours, _closeMinute, now.second);
now.isAfter(_open) && now.isBefore(_close) {
print("online");
} else {
print("offline");
}
Run Code Online (Sandbox Code Playgroud)
但是当我打印时DateTime.now(),这个时间与当前时间不匹配?我已经尝试使用手动输入当前时间来确保代码检查开放和关闭时间及其工作情况。
-- 之前,我尝试以另一种形式解析 json 并且它起作用了,当我尝试为上面的 json 制作结构时,如下所示:
class HomeTeam {
final int id, legacyId, name, countryId;
final bool nationalTeam;
final String logoPath;
HomeTeam({this.id, this.legacyId, this.name, this.countryId, this.nationalTeam, this.logoPath});
factory HomeTeam.fromJson(Map<String, dynamic> json){
return HomeTeam(
id: json['id'],
legacyId: json['legacy_id'],
name: json['name'],
nationalTeam: json['national_team'],
logoPath: json['logo_path']
);
}
}
Run Code Online (Sandbox Code Playgroud)
.
homeTeam: HomeTeam.fromJson(json['localTeam']['data']),
Run Code Online (Sandbox Code Playgroud)
然后结果出现错误..
NoSuchMethodError: 在 null 上调用了方法“[]”。E/flutter(220):接收器:null E/flutter:尝试调用:
如何解决这个问题呢?
我有一个List<Comment>关于用户的食物。看起来像这样:
[
{userId: 1,
rating: 4.5
},
{userId: 2,
rating: 4.0
},
{userId: 3,
rating: 3.5
},
{userId: 4,
rating: 3.0
}
...
];
Run Code Online (Sandbox Code Playgroud)
我想获得平均评分。AVERAGE = Number of ratings : total user,我该如何在飞镖中应用它?
我有一个案例,当用户想要将产品添加到购物车时,在此之前我想检查id/name产品是否在购物车中。
如果没有,那么我会将它添加到购物车,如果它已经存在,我将进行编辑(添加数量和价格)
我尝试使用以下代码:
Future checkIfProductHasAdded(String uid) async {
for (var i = 0; i < _checkoutList.length; i++) {
print(_checkoutList[i].name);
if (_checkoutList[i].productName == getSelectedProduct.name) {
selectedProductCheckout(i);
print(getSelectedProduct.name +
"PRODUCT CHECKOUT HAS ADDED" +
_checkoutList[i].productName);
// await updateProductCheckout(uid);
break;
} else {
print(getSelectedProduct.name + "NOT FOUND AT PRODUCT CHECKOUT");
//await addProductToCheckout(uid);
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
当 Iprint()值i不指定位置时List,而是停留在位置上0。如何使它工作?
任何答案将不胜感激。
我有一个List<Comment>来自所有食物。
[
{
comment_id: '...'
food_id: '...'
comment: '...'
},
{
comment_id: '...'
food_id: '...'
comment: '...'
},
....
]
Run Code Online (Sandbox Code Playgroud)
我想知道如何计算基于food_idFlutter的评论数?任何答案都非常有帮助。
我有一个“过滤器”,下面是足球比赛列表。我用ListView包装“ Filter and” listview builder”(以便解决blablabla下的重载问题)。但是,当您正常滚动时,会有一些奇怪的事情。滚动到无效的列表。只有一个“发光效果”,但是我从上面的“过滤器菜单”滚动,该滚动有效。如何使滚动正常运行?
我的代码片段:
Widget _buildListView(FixtureModel model, BuildContext context) {
return Container(
child: model.getFixturesCount() == 0
? Center(child: Text('No fixtures found'))
: ListView(
shrinkWrap: true,
children: <Widget>[
Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 10.0),
child: InkWell(
onTap: () => _onTap(context),
child: Container(
margin:
EdgeInsets.only(top: 5.0, bottom: 5.0),
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 5.0),
child:
Icon(FontAwesomeIcons.github)),
Container(
padding: EdgeInsets.only(left: 15.0),
child: Text(
'Liga Premier Inggris',
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.w500),
), …Run Code Online (Sandbox Code Playgroud)