小编Jon*_*nas的帖子

Flutter如何用背景图像创建卡片?

我正在尝试创建一个以图像为背景的卡片。问题是,图像溢出了卡,因此没有显示角落。

我需要将图像设置为卡的背景或将卡的溢出行为设置为无溢出。但是我找不到任何属性。

这是我的卡:

Widget _buildProgrammCard() {
  return Container(
    height: 250,
    child: Card(
      child: Image.asset(
        'assets/push.jpg',
        fit: BoxFit.cover,
      ),
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(10.0),
      ),
      elevation: 5,
      margin: EdgeInsets.all(10),
    ),
  );
Run Code Online (Sandbox Code Playgroud)

它看起来像这样:

在此处输入图片说明

在此处输入图片说明

dart flutter

11
推荐指数
2
解决办法
1万
查看次数

Flutter:根据当前子项调整PageView / Horizo​​ntal ListView的高度

我正在尝试创建高度可变的项目的轮播。将PageView或ListView与水平滚动一起使用时,我需要给它一个恒定的高度,如下所示:

class CarouselVariableHightState extends State<CarouselVariableHight> {
  double height = 200;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Carousel')),
      body: ListView(
        children: <Widget>[
          Text('My Carousel'),
          Container(
            height: height,
            child: PageView(
              children: <Widget>[
                _buildCarouselItem(),
                _buildCarouselItem(),
                _buildCarouselItem(),
                _buildCarouselItem(),
              ],
            ),
          ),
          Text('end of List')
        ],
      ),
    );
  }

  Widget _buildCarouselItem() {
    return Column(
      children: [
        Container(
          color: Colors.red,
          height: Random().nextInt(200).toDouble(),
          child: Text('Text with random length')
        )
      ]
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

但是我的物品包含文字,我不知道它的长度。我不想限制CarouselItem的高度,因为它可能会截断文本。我该如何使用PageView之类的东西,根据当前显示的项目调整其自身尺寸?

我认为解决方案可能是获取CarouselItem的高度,然后将其设置为PageView的高度。但是我想不出一种方法来增加我当前的轮播项目的高度。

有任何想法吗?

dart flutter

11
推荐指数
2
解决办法
743
查看次数

带有 &lt;= &amp; &gt;= 的 Firestore 复合查询

我需要在 Firestore 集合中查询开始时间(这是一个数字)是>= slot.startand 的条目<= slot.end

像这样:

.collection('Entries', ref => ref.where('timeStart', '>=', slot.timeStart).where('timeEnd', '<=', slot.timeEnd))
Run Code Online (Sandbox Code Playgroud)

但我收到此错误:

Invalid query. All where filters with an inequality (<, <=, >, or >=) must be on the same field.

我认为这个查询可以与复合索引一起使用,但正如错误所说,这不起作用。

当我将查询更改为:

.collection('Entries', ref => ref.where('timeStart', '==', slot.timeStart).where('timeEnd', '<=', slot.timeEnd))
Run Code Online (Sandbox Code Playgroud)

我可以为它创建一个索引。此外,当我将第二个 '<=' 更改为 '==' 时,我什至不需要它的索引。

我不认为我的查询那么高级,我对 firestore 无法执行此查询感到有些失望。那么我的问题的最佳解决方案是什么?像这样省略第二个查询语句是下一个最好的选择

.collection('Entries', ref => ref.where('timeStart', '>=', slot.timeStart))
Run Code Online (Sandbox Code Playgroud)

然后遍历结果并检查是否timeEnd <= entry.timeEnd“手动”?这对我来说似乎是一个非常糟糕的解决方案,因为那时我可能需要加载大量数据。

firebase google-cloud-firestore

10
推荐指数
1
解决办法
8585
查看次数

Dart DevTools 显示“连接到正在运行的应用程序”

我无法在 VS Code 中启动 Dart Dev Tools,当我在调试模式下启动时,它会打开一个 chrome 窗口说 Connect to a running app Enter a port or URL to a running Dart or Flutter application.

当我将鼠标悬停在Dart DevTools按钮上时,它会显示一个端口,但我仍然无法连接到它。

有任何想法吗?

debugging dart flutter

10
推荐指数
3
解决办法
4666
查看次数

Strapi delete files related to an entry

I have implemented the functionality to upload files related to an entry.

For example I have a collection type Articles, which has the field photos.

When uploading a file, I can specify the collection, the entry of the collection and the filed to add the media data to.

Now I want to implement the same for deleting a file.

How would I implement this. As far as I know there is no similar method where I delete …

strapi

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

Firestore:使用未解析的标识符'Firestore'

我想实现Firestore数据库.在我的Podfile中,我添加pod 'Firebase/Firestore'并做了pod install.当trying to use let db = Firestore.firestore()我得到错误:Use of unresolved identifier 'Firestore'.我也试过pod更新,它也说,Using FirebaseFirestore (0.12.2)但它soll不起作用.我该怎么办?

ios firebase google-cloud-firestore

7
推荐指数
3
解决办法
3860
查看次数

Dart JsonSerialized 与抽象类

我正在尝试为一个对象生成 json 辅助函数,该函数包含一个具有抽象类类型的列表,如下所示:

\n
import 'package:json_annotation/json_annotation.dart';\n\nimport 'exercise-variations.a.dart';\n\npart 'routine.model.g.dart';\n\n@JsonSerializable()\nclass Routine {\n\n  List<ExerciseRoutine> exercises;\n\n  Routine();\n\n  factory Routine.fromJson(Map<String, dynamic> json) => _$RoutineFromJson(json);\n\n  Map<String, dynamic> toJson() => _$RoutineToJson(this);\n}\n
Run Code Online (Sandbox Code Playgroud)\n
\n\n    import 'package:json_annotation/json_annotation.dart';\n    import 'exercise-variations.a.dart';\n\n    part 'base-exercise-routine.g.dart';\n\n    @JsonSerializable()\n    class BaseExerciseRoutine implements ExerciseRoutine {\n      int sets;\n\n      BaseExerciseRoutine();\n\n      factory BaseExerciseRoutine.fromJson(Map<String, dynamic> json) => _$BaseExerciseRoutineFromJson(json);\n\n      Map<String, dynamic> toJson() => _$BaseExerciseRoutineToJson(this);\n    }\n\n
Run Code Online (Sandbox Code Playgroud)\n
abstract class ExerciseRoutine {}\n
Run Code Online (Sandbox Code Playgroud)\n

这样我得到这个错误:

\n
[INFO] Running build...\n[SEVERE] json_serializable:json_serializable on lib/test/routine.model.dart:\nError running JsonSerializableGenerator\nCould not generate `fromJson` code for `exercises` because of type `ExerciseRoutine`.\nNone of …
Run Code Online (Sandbox Code Playgroud)

dart flutter json-serialization

7
推荐指数
1
解决办法
5762
查看次数

Firestore whereEqualTo,orderBy和limit(1)不起作用

我想从常规查询我的锻炼集合中的最新锻炼.这意味着我使用whereEqualTo我的routineKey进行查询,按照开始时间顺序按降序排序,然后限制为1,然后取出锻炼的第一个键/ Id.

但这不起作用.whereEqualToorderBy单独工作但不合并.我究竟做错了什么?

fm.getColRefWorkout().whereEqualTo("routineKey", routineKey).orderBy("startTimeStamp", Query.Direction.DESCENDING).limit(1).get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() { 
                @Override
                public void onSuccess(QuerySnapshot documentSnapshots) {
                    workoutKey = documentSnapshots.getDocuments().get(0).getId();
                    //To stuff with this workoutKey
                }
            });
Run Code Online (Sandbox Code Playgroud)

java android firebase google-cloud-firestore

6
推荐指数
1
解决办法
2675
查看次数

卡片底部有白条

我的卡底部有一条白线,我不知道如何摆脱它。

在此处输入图片说明

这是我的代码:

return Card(
  margin: EdgeInsets.all(10),
  elevation: 8,
  semanticContainer: true,
  clipBehavior: Clip.antiAliasWithSaveLayer,
  child: Stack(
    alignment: Alignment.bottomCenter,
    children: <Widget>[
      Image.asset(
        'assets/push.jpg',
        fit: BoxFit.cover,
      ),
      LinearProgressIndicator(
        value: 0.8,
      ),
    ],
  ),
  shape: RoundedRectangleBorder(
    borderRadius: BorderRadius.circular(10)
  ),
);
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

编辑:我发现这个问题与堆栈的高度有关。我也有这个问题,下面的代码:

return Card(
  margin: EdgeInsets.all(10),
  elevation: 10,
  semanticContainer: true,
  clipBehavior: Clip.antiAliasWithSaveLayer,
  child: Column(
    children: <Widget>[
      Container(
        color: Colors.red,
        height: 270,
      ),
      LinearProgressIndicator(
        value: 0.8,
      ),
    ]
  ),
  shape: RoundedRectangleBorder(
    borderRadius: BorderRadius.circular(10)
  ),
);
Run Code Online (Sandbox Code Playgroud)

但奇怪的是,当我将容器的高度更改为 200 时...

编辑 2:使用 diegoveloper 代码,它看起来像这样:

在此处输入图片说明

flutter

6
推荐指数
1
解决办法
266
查看次数

Flutter Google Charts 更改 TextStyleSpec 的 fontWeight

我正在为我的 flutter 应用程序使用谷歌图表库,并且我正在尝试自定义标签的样式。

但是我怎样才能改变 a 的字体粗细呢TextStyleSpec?该参数fontWeight要求提供 a String,我尝试提供Bold, bold, 500w500但没有任何效果。

charts flutter

6
推荐指数
2
解决办法
1791
查看次数