在BoxDecoration图像上强制裁剪

时间:2020-11-06 19:07:26

标签: flutter dart flutter-layout

我正在尝试使我的图像变圆,但是作为背景。问题是,ClipRRect并未按照我的预期去做。我会喜欢使用Stack之外的解决方案,因为那样会导致按列调整图像大小的问题,因为图像比列大。非常感谢。

编辑:所以,我非常抱歉。我的同事给我的图像似乎被无意地填充了,因此边界不起作用。目前,我和我的同事已经修复了该图像,并且现在一切正常。我通过在合适的情况下使用BoxFit.fill 来实现这一点,因此,如果有人偶然发现此问题,他们可能想尝试Boxfit.first检查图像。
enter image description here

LoginFragment

1 个答案:

答案 0 :(得分:1)

删除您的cliprect。 BorderRadius中的DecoratedBox足以实现这一目标。

尝试一下:

import 'package:flutter/material.dart';

final Color darkBlue = Color.fromARGB(255, 18, 32, 47);

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: MyWidget(),
        ),
      ),
    );
  }
}

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: DecoratedBox(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(30),
          image: DecorationImage(
            image: AssetImage(
              'images/ic_blackbackground.png',
            ),
            fit: BoxFit.cover,
          ),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
              padding: const EdgeInsets.only(
                top: 24,
                bottom: 16,
                left: 24,
              ),
              child: Text(
                "Info Kios",
                style: TextStyle(
                  color: Colors.white,
                  fontWeight: FontWeight.w700,
                  fontSize: 16,
                ),
              ),
            ),
            Container(
              width: double.infinity,
              height: 1,
              color: Colors.white,
            ),
            Padding(
              padding: const EdgeInsets.only(top: 20, bottom: 24),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  Column(
                    children: [
                      Text(
                        'Nama Kios',
                        style: TextStyle(
                          fontSize: 14,
                          fontWeight: FontWeight.w400,
                          color: Colors.white,
                        ),
                      ),
                      Text(
                        widget._kurirPengambilanModel.pedagang.namaKios,
                        style: TextStyle(
                          fontSize: 16,
                          fontWeight: FontWeight.w700,
                          color: Colors.white,
                        ),
                      ),
                    ],
                  ),
                  Column(
                    children: [
                      Text(
                        'Nomor Kios',
                        style: TextStyle(
                          fontSize: 14,
                          fontWeight: FontWeight.w400,
                          color: Colors.white,
                        ),
                      ),
                      Text(
                        widget._kurirPengambilanModel.pedagang.nomorKios,
                        style: TextStyle(
                          fontSize: 16,
                          fontWeight: FontWeight.w700,
                          color: Colors.white,
                        ),
                      ),
                    ],
                  )
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}