step_card_util.dart 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:keyboard/utils/grid_util.dart';
  4. import '../data/bean/widget_location.dart';
  5. import '../resource/assets.gen.dart';
  6. /// 步骤卡片工具类
  7. class StepCardUtil {
  8. StepCardUtil._();
  9. /// 一列多少个
  10. static const int defaultCrossAxisCount = 3;
  11. /// 获取卡片背景图片
  12. static ImageProvider getCardBgImageProvider(
  13. int itemCount, {
  14. int crossAxisCount = defaultCrossAxisCount,
  15. }) {
  16. // 计算出九宫格有多少行
  17. int rowCount = GridUtil.calculateRowCount(itemCount, crossAxisCount);
  18. // 根据行数不同,使用不同的步骤卡片背景
  19. if (rowCount == 1) {
  20. return Assets.images.bgIntimacyAnalyseUploadCard.provider();
  21. } else if (rowCount == 2) {
  22. return Assets.images.bgIntimacyAnalyseUploadCard2.provider();
  23. } else {
  24. return Assets.images.bgIntimacyAnalyseUploadCard3.provider();
  25. }
  26. }
  27. /// 计算顶部Icon的位置
  28. static WidgetLocation calculateTopIconWidgetLocation(
  29. int itemCount, {
  30. int crossAxisCount = defaultCrossAxisCount,
  31. }) {
  32. // 计算出九宫格有多少行
  33. int rowCount = GridUtil.calculateRowCount(itemCount, crossAxisCount);
  34. if (rowCount == 1) {
  35. return WidgetLocation(null, -8.h, 0, null);
  36. } else if (rowCount == 2) {
  37. return WidgetLocation(null, -5.h, 0, null);
  38. } else {
  39. return WidgetLocation(null, -11.h, 0, null);
  40. }
  41. }
  42. }