import '../models/activity_model.dart';
import 'package:flutter/foundation.dart';
class Trip {
String id;
String city;
String name;
List<Activity> ;
DateTime date;
Trip({
@required this.name,
@required this.city,
@required this.activities,
@required this.date,
}) : id = UniqueKey().toString();
}
trip_activityList.dart
import 'package:flutter/material.dart';
import '../../../models/activity_model.dart';
class TripActivityList extends StatelessWidget {
final List<Activity> activities;
TripActivityList({this.activities});
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: activities.length,
itemBuilder: (context, index) {
return Text(activities[index].name);
});
}
}
trip_activities.dart
import 'package:flutter/material.dart';
import 'package:uvs_voyage/views/trip/widgets/trip_activity_list.dart';
import '../../../models/activity_model.dart';
class TripActivities extends StatelessWidget {
final List<Activity> activities;
TripActivities({this.activities});
@override
Widget build(BuildContext context) {
return Container(
child: DefaultTabController(
length: 2,
child: Column(
children: <Widget>[
Container(
color: Colors.blue,
child: TabBar(
indicatorColor: Colors.blue[100],
tabs: <Widget>[
Tab(
text: 'En cours',
),
Tab(
text: 'Terminé',
),
],
),
),
Container(
height: 600,
child: TabBarView(
physics: NeverScrollableScrollPhysics(),
children: <Widget>[
TripActivityList(
activities: activities,
),
TripActivityList(
activities: activities,
),
],
),
),
],
),
),
);
}
}
这花费了很长时间。)/ I / flutter(15602):W小部件库引起的异常══╡ ══════════════════════════════════════ I / flutter(15602):构建TripActivityList(dirty)时引发了以下NoSuchMethodError: I / flutter(15602):在null上调用了setter'length ='。 I / flutter(15602):接收者:null I / flutter(15602):尝试致电:length = 0 I /颤振(15602): I / flutter(15602):相关的引起错误的小部件是: I / flutter(15602):TripActivityList I / flutter(15602):file:/// C:/Users/Mamadou%20Lamine%20Bouss/uvs_voyage/lib/views/trip/widgets/trip_activities.dart:35:19 I /颤振(15602): I / flutter(15602):引发异常时,这是堆栈: I /颤振(15602):#0 Object.noSuchMethod(dart:core-patch / object_patch.dart:51:5) I / flutter(15602):#1 TripActivityList.build(软件包:uvs_voyage / views / trip / widgets / trip_activity_list.dart:11:31) I / flutter(15602):#2 StatelessElement.build(软件包:flutter / src / widgets / framework.dart:4620:28) I / flutter(15602):#3 ComponentElement.performRebuild(软件包:flutter / src / widgets / framework.dart:4546:15) I / flutter(15602):#4 Element.rebuild(包:flutter / src / widgets / framework.dart:4262:5) I / flutter(15602):#5 StatelessElement.update(软件包:flutter / src / widgets / framework.dart:4627:5) I / flutter(15602):#6 Element.updateChild(软件包:flutter / src / widgets / framework.dart:3245:15) I / flutter(15602):#7 ComponentElement.performRebuild(包:flutter / src / widgets / framework.dart:4571:16) I / flutter(15602):#8 Element.rebuild(包:flutter / src / widgets / framework.dart:4262:5) I / flutter(15602):#9 StatelessElement.update(软件包:flutter / src / widgets / framework.dart:4627:5) I / flutter(15602):#10 Element.updateChild(软件包:flutter / src / widgets / framework.dart:3245:15) I / flutter(15602):#11 SingleChildRenderObjectElement.update(软件包:flutter / src / widgets / framework.dart:5881:14) I / flutter(15602):#12 Element.updateChild(程序包:flutter / src / widgets / framework.dart:3245:15) I / flutter(15602):#13 SingleChildRenderObjectElement.update(软件包:flutter / src / widgets / framework.dart:5881:14) I / flutter(15602):#14 Element.updateChild(软件包:flutter / src / widgets / framework.dart:3245:15) I / flutter(15602):#15 ComponentElement.performRebuild(包:flutter / src / widgets / framework.dart:4571:16) I / flutter(15602):#16 Element.rebuild(包:flutter / src / widgets / framework.dart:4262:5) I / flutter(15602):#17 StatelessElement.update(软件包:flutter / src / widgets / framework.dart:4627:5) I / flutter(15602):#18 Element.updateChild(软件包:flutter / src / widgets / framework.dart:3245:15) I / flutter(15602):#19 ComponentElement.performRebuild(程序包:flutter / src / widgets / framework.dart:4571:16) I / flutter(15602):#20 Element.rebuild(包:flutter / src / widgets / framework.dart:4262:5) I / flutter(15602):#21 ProxyElement.update(软件包:flutter / src / widgets / framework.dart:4906:5) I / flutter(15602):#22 Element.updateChild(包:flutter / src / widgets / framework.dart:3245:15) I / flutter(15602):#23 ComponentElement.performRebuild(package:flutter / src / widgets / framework.dart:4571:16)
答案 0 :(得分:1)
实例化窗口小部件时,列表activities
可能为空。
当data == null
itemCount: activities!= null ? activities.length : 0,