I'm trying to build a ListView.builder from a list like that:
final List<myData> user1 = [
user1(
"name",
"username",
[user2.elementAt(0)]),
),
And at first I didn't have any problem, the problem appeared when I created another list like this one:
final List<otherData> user2 = [
user2(
"name",
"username",
[user1.elementAt(0)]),
),
because I need to access to some information from both list, I need to use a list of both classes in both list (in user1 information of user2, and in user2 information about user1), however doesn't seems to be that Flutter like this kind of actions.
Anyway, after I did that, this error appeared. Any idea about where is the problem? here is my list builder:
Expanded(
child: ListView.builder(
padding: EdgeInsets.only(
top: 10.0,
),
itemCount: user1.length,
itemBuilder: (context, index) {
final pokemon = user1[index];
return GestureDetector(
I have also to say that I have another list view but with the other list as you can see bellow:
Expanded(
child: ListView.builder(
padding: EdgeInsets.only(
top: 10.0,
),
itemCount: user2.length,
itemBuilder: (context, index) {
final pokemon = user2[index];
return GestureDetector(
UPDATE:
I added a demo showing when is occurring this error, here is my code:
this is where I defined one of the two list:
import 'otherDara.dart';
class myData {
String name;
String username;
List<otherData> user2;
myData(
this.name,
this.username,
this.user2
);
}
final List<myData> user1 = [
myData("JUAN", "PALOMO", [user2.elementAt(0)])
];
here is my second list
import 'package:temporal/myData.dart';
class otherData {
String name;
String username;
List<myData> user1;
otherData(this.name, this.username, this.user1);
}
final List<otherData> user2 = [
//ESTO VA MUCHO MAS DESPUES
otherData("MARCO", "POLO", [user1.elementAt(0)])
];
here is where I use the info of the list builded
// ignore_for_file: prefer_const_constructors
import 'package:flutter/material.dart';
import 'package:temporal/myData.dart';
class userDetail extends StatefulWidget {
final myData user1;
final List<myData> list;
const userDetail({key, this.title, this.user1, this.list}) : super(key: key);
final String title;
@override
State<userDetail> createState() => _userDetailtate();
}
class _userDetailtate extends State<userDetail> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: ListView.builder(
// ignore: prefer_const_constructors
padding: EdgeInsets.only(
top: 10.0,
),
itemCount: widget.user1.username.length,
itemBuilder: (context, index) {
final userData = widget.user1.user2[index];
return GestureDetector(
child: Text(
userData.name, //NOOOOOOMBRE
style: TextStyle(
fontSize: 22.0,
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
);
}));
}
}
and finally, here is my main page:
import 'package:flutter/material.dart';
import 'myData.dart';
import 'userDetail.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({key, this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<myData> list;
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return SizedBox(
height: 500,
child: Container(
//color: Colors.grey.shade300,
child: Stack(children: [
Column(
children: <Widget>[
// ignore: prefer_const_constructors
SizedBox(
height: 30,
),
Expanded(
child: ListView.builder(
// ignore: prefer_const_constructors
padding: EdgeInsets.only(
top: 10.0,
),
itemCount: user1.length,
itemBuilder: (context, index) {
final userData = user1[index];
return GestureDetector(
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) {
return userDetail(user1: userData, list: user1);
}));
},
child: Padding(
// ignore: prefer_const_constructors
padding: EdgeInsets.only(
bottom: 10.0,
right: 20.0,
left: 20.0,
),
child: Container(),
),
);
}),
)
],
),
//floatButton(),
]),
),
);
}
}