小编Sam*_*ari的帖子

如何在卡片顶部叠加圆形图像(一半在卡片中,一半在卡片外)?

我是 flutter 新手,最近我尝试设计一个页面,我必须将图像放在卡片的顶部,一半在卡片上,一半在卡片外,我尝试了 Stack 但无法设计我想要什么!这是我正在尝试设计的一个例子。

这是没有给出预期结果的代码,如下图所示:

class ContainerWithCircle extends StatelessWidget {
final double circleRadius = 100.0;
final double circleBorderWidth = 8.0;
@override
Widget build(BuildContext context) {
   return Stack(
  alignment: Alignment.topCenter,
  children: <Widget>[

    Container(
      width: circleRadius,
      height: circleRadius,
      decoration:
          ShapeDecoration(shape: CircleBorder(), color: Colors.white),
      child: Padding(
        padding: EdgeInsets.all(circleBorderWidth),
        child: DecoratedBox(
          decoration: ShapeDecoration(
              shape: CircleBorder(),
              image: DecorationImage(
                  fit: BoxFit.cover,
                  image: NetworkImage(
                    'https://upload.wikimedia.org/wikipedia/commons/a/a0/Bill_Gates_2018.jpg',
                  ))),
        ),
      ),
    ),
    Padding(
      padding: EdgeInsets.only(top: circleRadius / 2.0),
      child: Container(
        // Some content
      ),
    ),
  ],
);
Run Code Online (Sandbox Code Playgroud)

} }

在此处输入图片说明

flutter

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

如何知道 Firestore 查询快照中是否存在数据?

这是我想获取数据并知道数据是否存在的代码。问题是,如果数据存在,它会运行,{ if(task.isSuccessful() }但如果数据不存在,它什么都不做!

我怎么知道数据不存在?我添加了其他{ else }语句,但没有用。

CollectionReference reference = firestore.collection("Carts").document(FirebaseAuth.getInstance().getCurrentUser().getUid())
            .collection("Carts");
    reference.whereEqualTo("ordered",false).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()) {
                for (QueryDocumentSnapshot document : task.getResult()) {
                    if(document.exists()){
                        Toast.makeText(ListProducts.this, "Exists", Toast.LENGTH_SHORT).show();
                    }
                    else {
                        // This part is not running even if there is no data
                        Toast.makeText(ListProducts.this, "NOPE", Toast.LENGTH_SHORT).show();
                    }
                }
            }
        }
    });
Run Code Online (Sandbox Code Playgroud)

java android firebase google-cloud-firestore

5
推荐指数
1
解决办法
7142
查看次数