Firebase存储的图像链接返回null-Flutter

时间:2020-09-23 18:35:53

标签: image flutter google-cloud-firestore firebase-storage flutter-web

在显示图像的fiorebase存储链接时,出现此错误 network_image_web.dart:26:16 url!= null不正确

下面是示例。是的,提供商可以将除图片之外的所有其他字段都很好

pd.concat([df1, df2])['Category'].value_counts()
1.0    14
2.0     8
3.0     4
5.0     3
4.0     2
Name: Category, dtype: int64
class AddAlreadyExistingProductsView extends StatefulWidget {
  @override
  _AddAlreadyExistingProductsViewState createState() =>
      _AddAlreadyExistingProductsViewState();
}

class _AddAlreadyExistingProductsViewState
    extends State<AddAlreadyExistingProductsView> {
@override
  Widget build(BuildContext context) {
final _productsList = Provider.of<List<Product>>(context);

return Scaffold(
............
    child: 
       SearchableDropdown.single(
       ............
            items: _productsList.map((value) {
               print("---> pic : " + value.pic.toString()); // <--- NULL HERE
          ..........        
       child: ListTile(
             leading: CircleAvatar(
               backgroundImage: NetworkImage(value.pic),
            ),
           subtitle: Text(value.name)
.............
                                ) 
                             )
                            }

在打印图像时,我还尝试打印它,并将其设置为null。检索所有其他领域都可以。我给出了存储在网络映像内的firebase数据库中的该映像的静态值,并且它工作正常。但是在动态获取数据时,它无法正常工作。我不知道为什么我在移动设备上以相同的方式获得了数据,并且可以正常工作,但对于颤动的网络却无法正常工作。

这是产品型号代码

class MainDataProvider extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
       StreamProvider<List<Product>>.value(
        value: DatabaseService().getAllProducts,
........
      ],
      child: MaterialApp(
        home: AddAlreadyExistingProductsView (),
      ),
    );
  }
}

enter image description here

1 个答案:

答案 0 :(得分:1)

在for循环的_productDataFromSnapshot函数中,您没有初始化pic字段。

为防止此类错误,请对此类字段使用@required