【无标题】

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

Dart 基础语法

List数组操作

firstWhere 方法

Dart 官网 示例

复制代码
void main() {
  const items = ['Salad', 'Popcorn', 'Toast', 'Lasagne'];

  // You can find with a simple expression:
  var foundItem1 = items.firstWhere((item) => item.length > 5);
  print(foundItem1);

  // Or try using a function block:
  var foundItem2 = items.firstWhere((item) {
    return item.length > 5;
  });
  print(foundItem2);

  // Or even pass in a function reference:
  var foundItem3 = items.firstWhere(predicate);
  print(foundItem3);

  // You can also use an `orElse` function in case no value is found!
  var foundItem4 = items.firstWhere(
    (item) => item.length > 10,
    orElse: () => 'None!',
  );

every、 any方法

复制代码
void main() {
  const items = ['Salad', 'Popcorn', 'Toast'];

  if (items.any((item) => item.contains('a'))) {
    print('At least one item contains "a"');
  }

  if (items.every((item) => item.length >= 5)) {
    print('All items have length >= 5');
  }
}
相关推荐
用户093 小时前
Flutter插件与包的本质差异
android·flutter·面试
浅蓝色4 小时前
flutter平台判断,这次应该没问题了。支持鸿蒙,插件已发布
flutter·harmonyos
怀君5 小时前
Flutter——打印之PdfPreview功能详细教程
flutter
唔6616 小时前
flutter实现web端实现效果
前端·flutter
sunly_20 小时前
Flutter:启动动画Lottie
flutter
柿蒂1 天前
聊聊SliverPersistentHeader优先消费滑动的设计
android·flutter
fishofeyes1 天前
Riverpod使用
flutter
消失的旧时光-19432 天前
iFlutter --> Flutter 开发者 的 IntelliJ IDEA / Android Studio 插件
flutter·android studio·intellij-idea
马拉萨的春天2 天前
block的样式有哪些?如果copy的话分别会有啥样式
flutter·性能优化·ios的block
Rattenking2 天前
【CSS】---- 图形函数详解
笔记·学习·flutter