'Null check operator used on a null value - Flutter
I was trying to make a google drive app that lists files from the drive. but I got Null check operator used on a null value error. I got it what's happening. but I could not solve it.
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextButton(
onPressed: () {},
child: Text('UPLOAD'),
),
if (list != null)
SizedBox(
height: 300,
width: double.infinity,
child: ListView.builder(
shrinkWrap: true,
itemCount: list!.files?.length,
itemBuilder: (context, index) {
final title = list!.files![index].originalFilename;
return ListTile(
leading: Text(title!),
trailing: ElevatedButton(
child: Text('Download'),
onPressed: () {
},
),
);
},
),
)
],
),
),
floatingActionButton: Row(
children: [
FloatingActionButton(
onPressed: _listGoogleDriveFiles,
child: Icon(Icons.photo),
),
FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
],
),
);
}
}
When I run it upload text is showing and the error is showing below the text. So error must be due to list is null. but I just want to show the list only if it is not null.
What to do?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
