I am getting this exception I searched on stackoverflow but the solutions I found didn’t work for me.
I faced this error:
Unhandled exception:
Crash when compiling:
RangeError (index): Invalid value: Only valid value is 0: 1
#0 List.[] (dart:core-patch/growable_array.dart:264:36)
#1 Class._computeOnClause (package:kernel/ast.dart:1156:73)
#2 Class.onClause (package:kernel/ast.dart:1139:49)
#3 SourceClassBuilder.checkMixinApplication (package:front_end/src/fasta/source/source_class_builder.dart:908:52)
#4 SourceLoader.checkMixins (package:front_end/src/fasta/source/source_loader.dart:2714:19)
#5 KernelTarget.buildOutlines.<anonymous closure> (package:front_end/src/fasta/kernel/kernel_target.dart:532:14)
<asynchronous suspension>
#6 withCrashReporting (package:front_end/src/fasta/crash.dart:133:12)
<asynchronous suspension>
#7 KernelTarget.buildOutlines (package:front_end/src/fasta/kernel/kernel_target.dart:404:12)
<asynchronous suspension>
#8 IncrementalCompiler.computeDelta.<anonymous closure> (package:front_end/src/fasta/incremental_compiler.dart:408:33)
<asynchronous suspension>
#9 IncrementalCompiler.compile (package:vm/incremental_compiler.dart:75:50)
<asynchronous suspension>
#10 FrontendCompiler.compile (package:frontend_server/frontend_server.dart:604:11)
<asynchronous suspension>
#11 listenAndCompile.<anonymous closure> (package:frontend_server/frontend_server.dart:1316:11)
<asynchronous suspension>
the Dart compiler exited unexpectedly.
Here are my pages:
https://i.stack.imgur.com/5N8mr.png
class stream extends StatefulWidget {
stream({super.key});
@override
State<stream> createState() => _streamState();
}
class _streamState extends State<stream> {
@override
Widget build(BuildContext context) {
return StreamBuilder<User?>(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (context, userSnapshot) {
if (userSnapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
}
final User? currentUser = userSnapshot.data;
return StreamBuilder<List<Task>>(
stream: FirestoreDataSource().streamTasks(currentUser?.uid ?? ''),
builder: (context, tasksSnapshot) {
if (tasksSnapshot.connectionState == ConnectionState.waiting) {
return const Center(
child: CircularProgressIndicator(strokeWidth: 0.9),
);
}
final List<Task> tasksList = tasksSnapshot.data ?? [];
if (tasksList.isEmpty) {
return const Center(
child: Text(
'No tasks available.',
style: TextStyle(fontSize: 16, color: textColor),
),
);
}
return ListView.builder(
shrinkWrap: true,
itemCount: tasksList.length,
itemBuilder: (context, index) {
final task = tasksList[index];
return Dismissible(
key: UniqueKey(),
onDismissed: ((direction) {
FirestoreDataSource().deleteTask(task.id);
}),
child: Task_wdgts(task),
);
},
);
},
);
},
);
}
}
Don’t worry if there is some unused code, it’s a work in progress and this error just stopped me from continuing what I was doing.
https://i.stack.imgur.com/YqrM6.png
class Home extends StatefulWidget {
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
bool show = true;
@override
Widget build(BuildContext context) {
return Column(
children: [
Expanded(
child: whatsapp(),
),
Expanded(
child: stream(),
)
],
);
}
}
Do you have any idea about the solution?
Thanks in advance
Can you confirm that
tasksSnapshot.data
returns non-empty data?