Keep path in sqflite like 'assets/images/1.png' and access with rootBundle
You do not need absolute path such as /sdcard0/....
Keep only assets path
ByteData imageData1 = await rootBundle.load('assets/images/1.png');
Use List of ByteData to keep images
List<ByteData> imageList = [];
With ListView display image with Image.memory
return Image.memory(imageList[index].buffer.asUint8List());
full code
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
List<ByteData> imageList = [];
void _incrementCounter() async{
ByteData imageData1 = await rootBundle.load('assets/images/1.png');
ByteData imageData2 = await rootBundle.load('assets/images/2.png');
print(imageData1.toString());
imageList.add(imageData1);
imageList.add(imageData2);
setState(() {
_counter++;
print(imageList.length.toString());
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: ListView.builder(
itemCount: imageList.length,
itemBuilder: (context, index) {
return Image.memory(imageList[index].buffer.asUint8List());
},
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
