简体   繁体   English

颤振的 clipRRect 小部件现在显示在屏幕上

[英]flutter's clipRRect widget is now showing on the screen

I am currently implementing my page using the flutter.我目前正在使用 flutter 实现我的页面。

The state management library is using GetX. state 管理库正在使用 GetX。

In this situation, I created MyPageView, which is dependent on MyPageController, and each controller and view are as follows.在这种情况下,我创建了MyPageView,它依赖于MyPageController,每个controller和视图如下。

// mypage_view
class MyPageView extends BaseView<MyPageController> {
  @override
  Widget body(BuildContext context) {
    return SingleChildScrollView(
      child: Column(
        children: [
          _buildUserProfileContainer(),
          Container(
            height: AppValues.margin_12,
            color: AppColors.containerBackgroundGreyColor,
          ),
        ],
      ),
    );
  }

  Widget _buildUserProfileContainer() {
    return Padding(
      padding: EdgeInsets.only(
        left: AppValues.margin,
        right: AppValues.margin,
        top: AppValues.margin_32,
        bottom: AppValues.margin_32,
      ),
      child: Obx(
        () => Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            ClipRRect(
              borderRadius: BorderRadius.circular(50),
              child: (() {
                if (controller.userUiModel == null ||
                    controller.userUiModel!.photo == null) {
                  Container(
                    color: AppColors.buttonBgColor,
                    height: 88,
                    width: 88,
                  );
                } else {
                  NetworkImage(controller.userUiModel!.photo!);
                }
              }()),
            ),
          ],
        ),
      ),
    );
  }
}

// mypage_controller
class MyPageController extends BaseController {
  void initData() async {
    try {
      String uid = uid;
      String userCreateRequestString = await searchUserData(uid);

      Map<String, dynamic> map =
      jsonDecode(userCreateRequestString) as Map<String, dynamic>;

      map['phoneNumber'] = _firebaseAuthManager.getCurrentUser()!.phoneNumber;
      setUserUiModel(UserUiModel.fromJson(map));
    } catch (e) {
      print(e.toString());
    }
  }

  Future<String> searchUserData(String uid) async {
    return _preferenceManager.getString(uid);
  }

  final Rxn<UserUiModel> _userUiModel =
      Rxn<UserUiModel>(null);

  UserUiModel? get userUiModel => _userUiModel.value;

  void setUserUiModel(UserUiModel value) =>
      _userUiModel.value = value;

  @override
  void onInit() {
    initData();
    super.onInit();
  }
}

Currently, I receive user data from shared Preferences and initialize it in the controller's onInit stage.目前,我从共享首选项接收用户数据并在控制器的 onInit 阶段对其进行初始化。

Through debug, it was confirmed that the UserUiModel value was initialized normally.通过debug确认UserUiModel值初始化正常。

The widget tree consists of the following:小部件树由以下内容组成:

在此处输入图像描述

In this situation, I have no reason why ClipRect's child is not visible on the screen.在这种情况下,我没有理由为什么 ClipRect 的孩子在屏幕上不可见。

If you insert a widget such as Text in the ClipRect position, it can be seen normally on the screen.如果在 ClipRect position 中插入 Text 等小部件,则可以在屏幕上正常看到。

What is the problem?问题是什么?

Uh... I was very foolish... NetworkImage was class, not a widget.... The solution was to change NetworkImage to Image.network.... OMG呃......我很愚蠢...... NetworkImage 是 class,而不是小部件......解决方案是将 NetworkImage 更改为 Image.network...... OMG

ClipRRect(
              borderRadius: BorderRadius.circular(50),
              child: controller.userUiModel == null ||
                      controller.userUiModel!.photo == null
                  ? Container(
                      color: AppColors.colorBlack,
                      height: 88,
                      width: 88,
                    )
                  : Image.network(
                      controller.userUiModel!.photo!,
                      scale: 88,
                    ),
            ),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM