0

我正在尝试在 android studio 中运行颤振应用程序,出现此错误

Exception caught by widgets library Value not in range: 7
   The relevant error-causing widget was: 
      VendorTypeVerticalListItem file:///D:/downloads/31145802-fuodz-grocery-food-pharmacy-store- 
    parcelcourier-delivery-mobile-app-with-php-laravel-backend/1.3.3-fix-1/Apps/Customer/New%20Owners/lib/widgets/states/welcome.empty.dart:85:42

我正在尝试在 android studio 真实设备中运行

welcome.empty.dart 文件第 85 行返回 VendorTypeVerticalListItem 收到此错误 小部件库捕获的异常值不在范围内:7

import 'package:flutter/material.dart';
import 'package:flutter_icons/flutter_icons.dart';
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
import 'package:fuodz/constants/app_colors.dart';
import 'package:fuodz/services/auth.service.dart';
import 'package:fuodz/utils/ui_spacer.dart';
import 'package:fuodz/view_models/welcome.vm.dart';
import 'package:fuodz/widgets/busy_indicator.dart';
import 'package:fuodz/widgets/custom_list_view.dart';
import 'package:fuodz/widgets/list_items/vendor_type.list_item.dart';
import 'package:fuodz/widgets/list_items/vendor_type.vertical_list_item.dart';
import 'package:masonry_grid/masonry_grid.dart';
import 'package:velocity_x/velocity_x.dart';
import 'package:fuodz/translations/welcome.i18n.dart';

class EmptyWelcome extends StatelessWidget {
  const EmptyWelcome({this.vm, Key key}) : super(key: key);

  final WelcomeViewModel vm;
  @override
  Widget build(BuildContext context) {
    return VStack(
      [
        VxBox(
          child: SafeArea(
            child: VStack(
              [
                ("Welcome".i18n +
                    (vm.isAuthenticated()
                        ? " ${AuthServices.currentUser?.name}"
                        : ""))
                    .text
                    .white
                    .xl3
                    .semiBold
                    .make(),
                "How can I help you today?".i18n.text.white.xl.medium.make(),
              ],
            ).py12(),
          ),
        ).color(AppColor.primaryColor).p20.make().wFull(context),
        //
        VStack(
          [
            HStack(
              [
                "I want to:".i18n.text.xl.medium.make().expand(),
                Icon(
                  vm.showGrid ? FlutterIcons.grid_fea : FlutterIcons.list_fea,
                ).p2().onInkTap(() {
                  vm.showGrid = !vm.showGrid;
                  vm.notifyListeners();
                }),
              ],
              crossAlignment: CrossAxisAlignment.center,
            ).py4(),
            //list view
            !vm.showGrid
                ? CustomListView(
              noScrollPhysics: true,
              dataSet: vm.vendorTypes,
              isLoading: vm.isBusy,
              itemBuilder: (context, index) {
                final vendorType = vm.vendorTypes[index];
                return VendorTypeListItem(
                  vendorType,
                  onPressed: () {
                    vm.pageSelected(vendorType);
                  },
                );
              },
              separatorBuilder: (context, index) => UiSpacer.emptySpace(),
            )
                : (vm.isBusy
                ? BusyIndicator().centered()
                : AnimationLimiter(
              child: MasonryGrid(
                column: 2,
                crossAxisSpacing: 10,
                mainAxisSpacing: 10,
                children: List.generate(
                  vm.vendorTypes.length ?? 0,
                      (index) {
                    final vendorType = vm.vendorTypes[index];
                    return VendorTypeVerticalListItem(
                      vendorType,
                      onPressed: () {
                        vm.pageSelected(vendorType);
                      },
                    );
                  },
                ),
              ),
            ))
                .py4(),
          ],
        ).p20(),
      ],
    ).scrollVertical();
  }
}

在此文件中,我收到错误,请参阅屏幕截图:

应用截图

4

1 回答 1

0

当您尝试在该列中构建第 7 个小部件但您用于构建的列表中没有 7 个项目时,会发生这种情况。不幸的是,我无法确切说明在您的情况下导致此错误的原因。

ps:有些人可能会说在你的代码中使用大量的包不是很明智......它使你的应用程序难以跟踪和阅读,你不能轻易理解正在发生的事情。

于 2021-08-21T07:59:40.743 回答