Open mini0555555 opened 11 months ago
Can you explain a bit more what you're trying to achieve and if you can, give an example? I don't understand what you're asking. I would expect you get an image url from your api?
import 'dart:convert';
import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; import 'package:http/http.dart' as http; import 'package:signinwithmobileno/utility/api_urls.dart'; import 'modal/banner_modal.dart';
class StaggeredGridViewPage extends StatefulWidget { const StaggeredGridViewPage({Key? key}) : super(key: key);
@override _StaggeredGridViewPageState createState() => _StaggeredGridViewPageState(); }
class _StaggeredGridViewPageState extends State
fetchBannerImages() async { try { final Map<String, String> formData = { 'company_id': '2', }; final response = await http.post( Uri.parse(ApiUrls.bannerlist), body: formData, );
if (response.statusCode == 200) {
bannerResponse = BannerResponse.fromJson(json.decode(response.body));
bannerlist.addAll(bannerResponse!.result as List<Baner>);
print(response.body);
}
} catch (e) {
print('Error: $e');
}
}
@override Widget build(BuildContext context) { return Scaffold( body: SafeArea( child: MasonryGridView.builder( itemCount: imageList.length, gridDelegate: SliverSimpleGridDelegateWithFixedCrossAxisCount( crossAxisCount: 2, ), itemBuilder: (BuildContext context, int index) { return CachedNetworkImage( imageUrl: imageList[index],); // it display perfectly // return CachedNetworkImage(imageUrl: bannerlist[index].bannerImage!); // it not display images }, ), ), ); } }
here is my code in which when i display static url's of image list then it display images even if i am offline but when i display url's of bannerlist which is not static url's but it get from http request then it don't display images when i am offline . so all i want is if my phone is in offline mode still it display images.
🔙 Regression
Old (and correct) behavior
Current behavior
Reproduction steps
Configuration
Version: 1.x
Platform: