如果您的地图通过地图的键字符串有多个视频列表,您可以使用以下代码获取所有长度:
Map<String, List<Video>> mapName = {
'video1': [Video(),Video()],
'video2': [Video()],
'video3': [Video(),Video(),Video()],
}; //Init
int total = 0;
mapName.keys.forEach((key){
List<Video> video = mapName[key];
int length = video.length;
print('$key: $length');
total += length;
});
print('total: $total');
颤振示例:
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class Video {
final String name;
final String url;
final bool isDone;
Video(this.name, this.url, this.isDone);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
Map<String, List<Video>> mapName = {
'video1': [
Video('Bunny', 'http://????', false),
Video('Bunny10', 'http://????', true),
],
'video2': [
Video('Bunny2', 'http://????', false),
],
'video3': [
Video('BunnyX', 'http://????', false),
Video('Bunny12', 'http://????', true),
Video('BunnyZZ', 'http://????', false),
],
}; //Init
List<Video> mVideos = [];
mapName.values.forEach((videos) {
videos.forEach((video) {
mVideos.add(video);
});
});
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: ListView.builder(
itemCount: mVideos.length,
itemBuilder: (context, index) {
Video video = mVideos[index];
String name = video.name;
String url = video.url;
bool isDone = video.isDone;
return ListTile(
tileColor: isDone ? Colors.green : null,
title: Text(name),
subtitle: Text(url),
);
},
),
),
);
}
}
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Text('Hello, World!', style: Theme.of(context).textTheme.headline4);
}
}