I am trying to get images from a remote server. I keep getting this error:
Warning database has been locked for 0:00:10.000000.
Make sure you always use the transaction object for database operations during a transaction
And afterwards my application crash.
Widget carousel = new Container(
height: 200,
child: FutureBuilder<List<String>>(
future: getPropImgs(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return new Carousel(
boxFit: BoxFit.cover,
images: snapshot.data.map((f) {
return new CachedNetworkImage(
imageUrl: f.toString(),
imageBuilder: (context, imageProvider) => Container(
decoration: BoxDecoration(
image: DecorationImage(
image: imageProvider,
fit: BoxFit.cover,
colorFilter:
ColorFilter.mode(Colors.blue, BlendMode.dstIn)),
),
),
placeholder: (context, url) => Center(
child: Container(
height: 30,
width: 30,
child: CircularProgressIndicator())),
errorWidget: (context, url, error) =>
Image.asset("assets/images/icon.png"),
);
}).toList(),
autoplay: true,
animationCurve: Curves.fastOutSlowIn,
animationDuration: Duration(milliseconds: 1000),
indicatorBgPadding: 1.0,
dotColor: Colors.black,
);
I guess you are trying to perform huge amount of SQL queries. Once slow solution is to make sure you await every calls. In the second line here you are missing an await:
await db.transaction((txn) async {
However here it still create one transaction per insert so that will be super slow. One solution is to use batches (https://github.com/tekartik/sqflite/tree/master/sqflite#batch-support) and queue the insert statement (1000 by 1000 for example);
var batch = db.batch();
batch.rawInsert(statement1);
batch.rawInsert(statement2);
batch.rawInsert(statement3);
...
await db.commit(noResult: true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With