小编Lep*_*yte的帖子

Flutter:Image BoxFit.cover 在 Stack 中不起作用

我想要两个图像在 gridview 中相互堆叠,并且都显示一个

图像女巫覆盖整个瓷砖。

但是当我添加 stackwidget 时,图像的行为就像没有

适合:BoxFit.cover

在其构建方法中。

我的 GridView 的构建方法:

@override
Widget build(BuildContext context) {
    if (widgetsList.length != 0) {
      return new GridView.count(
        primary: false,
        crossAxisCount: 2,
        children: widgetsList,
      );
    } else {
      return Container();
    }   
} 
Run Code Online (Sandbox Code Playgroud)

Gridtile(widgetsList 中的小部件):

@override
  Widget build(BuildContext context) {
    return new Stack(
      children: <Widget>[
        new CustomImage(compareTime: lastUpdatedPictureTime),
        new CustomImage(compareTime: lastUpdatedIconTime)
      ],
    );
  }
Run Code Online (Sandbox Code Playgroud)

我的 CustomImage 的构建方法:

@override
  Widget build(BuildContext context) {
    var img = imageBytes != null
        ? Image.memory(
            imageBytes,
            fit: BoxFit.cover,
          ) …
Run Code Online (Sandbox Code Playgroud)

android ios firebase flutter

9
推荐指数
1
解决办法
5035
查看次数

dart 有状态小部件将数据传递给状态错误:小部件为空

我想从 firebase 存储下载图像并缓存它们。但是当我将路径从有状态小部件传递到状态时,我遇到了问题。

class FirebaseCachedImage extends StatefulWidget{
  final String mPath;

  FirebaseCachedImage({ Key key, this.mPath }) : super(key: key);

  @override
  State<StatefulWidget> createState() => _FirebaseCachedImage();
}

class _FirebaseCachedImage extends State<FirebaseCachedImage> {
  final FirebaseStorage storage = FirebaseStorage(app: Firestore.instance.app, storageBucket: 'gs://fluttertest-b7c52.appspot.com/');
  Uint8List imageBytes;
  String errorMsg;

  _FirebaseCachedImage() {
    String path = widget.mPath;
    storage.ref().child(path).getData(10000000).then((data) =>
        setState(() {
          imageBytes = data;
        })
    ).catchError((e) =>
        setState(() {
          errorMsg = e.error;
        })
    );
  }

  @override
  Widget build(BuildContext context) {
    var img = imageBytes != null ? Image.memory(imageBytes, fit: BoxFit.cover,) …
Run Code Online (Sandbox Code Playgroud)

android ios flutter

0
推荐指数
1
解决办法
1422
查看次数

标签 统计

android ×2

flutter ×2

ios ×2

firebase ×1