flutter - 更改图标颜色或删除它

标签 flutter dart

我有这些容器来选择一些图像。当用户选择图像时,它会覆盖整个容器,所以我希望子项(图标)在选择图像后是透明的。

InkWell(
                          onTap: () async {
                            XFile? image3 = await _picker.pickImage(
                                source: ImageSource.gallery);

                            if (image3 == null) {
                              debugPrint("got null");
                              return;
                            }
                            final image =
                                Image.memory(await image3.readAsBytes());
                            decorationImage3 = DecorationImage(
                              fit: BoxFit.cover,
                              image: image.image,
                            );
                            setState(() {});
                          },
                          child: Container(
                            height: MediaQuery.of(context).size.width / 4 - 25,
                            width: MediaQuery.of(context).size.width / 4 - 25,
                            decoration: BoxDecoration(
                              color: Colors.blue.shade900,
                              borderRadius: BorderRadius.circular(5),
                              image: decorationImage3,
                            ),
                            child: const Icon(Icons.add, color: Colors.white),
                          ),
                        ),

最佳答案

改用这个

child: (image3 == null)?Icon(Icons.add, color: Colors.white):Sizedbox.shrink();

关于flutter - 更改图标颜色或删除它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72760885/

相关文章:

flutter - 行中小部件的动态高度波动

firebase - 如何在 Flutter 中不使用 FutureBuilder 或 StreamBuilder 从 Firebase 获取单个数据

dart - Dart-展平列表,同时删除重复的值

flutter - 在一段时间内更改按钮颜色

flutter - List<Map<String, dynamic>> - 删除重复项但堆栈号

android - 尝试安装 flutter 时如何修复 "Error: The Flutter directory is not a clone of the GitHub project."错误?

swift - Flutter 未构建 iOS 应用程序,这是一个快速错误吗?

flutter - 无法从方法返回类型值,因为它的返回类型为

flutter | Dart - NoSuchMethodError : The method 'map' was called on null

flutter - 如何在 flutter 中将 child 定位在堆栈中?