代码之家  ›  专栏  ›  技术社区  ›  melearning

背景封面

  •  0
  • melearning  · 技术社区  · 10 月前

    我试图覆盖滑块中充满图像的红色区域。试着合身: BoxFit.fill,但运气不好,有人能帮我解决这个问题吗。谢谢你的帮助,上帝保佑你,我不知道该多发什么短信了,它一直要求我多发短信。 enter image description here

    // ignore_for_file: public_member_api_docs, sort_constructors_first
    import 'package:flutter/material.dart';
    
    class HomeSliderItem extends StatelessWidget {
      final bool isActive;
      final String imageAssetPath;
      const HomeSliderItem({
        super.key,
        required this.isActive,
        required this.imageAssetPath,
      });
    
      @override
      Widget build(BuildContext context) {
        return FractionallySizedBox(
          widthFactor: 20,
          child: AnimatedScale(
            duration: const Duration(milliseconds: 2500),
            scale: isActive ? 1 : 1,
            child: ClipRRect(
              //borderRadius: BorderRadius.circular(0),
              child: Stack(
                children: [
                  Image.asset(imageAssetPath),
                  Container(
                    color: Colors.red,
                  ),
                  Image.asset(imageAssetPath, fit: BoxFit.fill),
                ],
              ),
            ),
          ),
        );
      }
    }
    
    
    1 回复  |  直到 10 月前
        1
  •  0
  •   Ravindra S. Patil    10 月前

    尝试以下代码并添加 width: double.infinity, 图像

    注: 只需使用我的网络映像更改您的资产映像

      Stack(
          children: [
            Container(
              color: Colors.red,
            ),
            Image.network(
                'https://images.pexels.com/photos/3225517/pexels-photo-3225517.jpeg?auto=compress&cs=tinysrgb&w=800',
                fit: BoxFit.cover,
              width: double.infinity,
            ),
          ],
        ),
    

    Output Screen