使用bottomSheet看不到脚手架

时间:2020-06-12 11:24:09

标签: flutter

我想用脚手架属性bottomSheet或bottomNavigationBar或persistantfooterbutton创建底线。身体不可见, WarenkorbFooterState列导致此问题。 返回容器( 子:列( crossAxisAlignment:CrossAxisAlignment.end, mainAxisAlignment:MainAxisAlignment.end, 孩子:[

如何解决这个问题?

class WarenkorbScreen extends StatefulWidget {
  WarenkorbScreen();

  @override
  _WarenkorbScreenState createState() => _WarenkorbScreenState();
}

class _WarenkorbScreenState extends State<WarenkorbScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomSheet: WarenkorbFooter(),
      bottomNavigationBar: WarenkorbFooter(),

      body: CustomScrollView(
        shrinkWrap: true,
        physics: ClampingScrollPhysics(),
        slivers: <Widget>[
          SliverList(
            delegate: SliverChildListDelegate([
              Container(
                  //height: ScreenUtil.instance.height - 1430,
                  child: WarenkorbListe()),
              // WarenkorbFooter(),
            ]),
          ),
        ],
      ),
    );
  }
}

class WarenkorbListe extends StatefulWidget {
  WarenkorbListe();

  @override
  _WarenkorbListeState createState() => _WarenkorbListeState();
}

class _WarenkorbListeState extends State<WarenkorbListe> {
  @override
  Widget build(BuildContext context) {
    WarenkorbBloc warenkorbBloc = BlocProvider.of<WarenkorbBloc>(context);
    final warenkorbLines = (warenkorbBloc.currentState as WarenkorbLoaded)
        .warenkorbLines
        .values
        .toList();

    if (warenkorbLines.length == 0) {
      return Padding(
        padding: const EdgeInsets.symmetric(
            horizontal: ImpexStyle.horizontalPadding),
        child: Text('Bitte fügen Sie Artikel zum Warenkorb hinzu. '),
      );
    }

    return CustomScrollView(
      shrinkWrap: true,
      physics: ClampingScrollPhysics(),
      slivers: <Widget>[
        BlocBuilder(
          bloc: warenkorbBloc,
          builder: (context, state) {
            return SliverList(
              delegate: SliverChildBuilderDelegate(
                (context, index) {
                  if (index >= warenkorbLines.length) return null;
                  return Column(
                    children: <Widget>[
                      WarenkorbListItem(
                        warenkorbLine: warenkorbLines[index],
                        buildWithDivider: index < warenkorbLines.length - 1,
                        buildWithPadding: index == 0,
                      ),
                    ],
                  );
                },
                childCount: warenkorbLines.length,
              ),
            );
          },
        ),
      ],
    );
  }
}

class WarenkorbListItem extends StatefulWidget {
  final WarenkorbLine warenkorbLine;
  final bool buildWithDivider;
  final bool buildWithPadding;

  WarenkorbListItem(
      {this.warenkorbLine, this.buildWithDivider, this.buildWithPadding});

  @override
  _WarenkorbListItemState createState() => _WarenkorbListItemState();
}

class _WarenkorbListItemState extends State<WarenkorbListItem> {
  Future<String> _articleImageData;
  Future<ArticlePrice> _articlePrice;
  Future<Article> _article;
  WarenkorbBloc warenkorbBloc;

  double _imageSize;

  @override
  void initState() {
    super.initState();

    super.initState();
    _imageSize = (ScreenUtil.screenWidth / 8).ceil().toDouble();

    _articleImageData = Repository().queryArticleImage(
        widget.warenkorbLine.articleId,
        width: _imageSize.floor(),
        height: _imageSize.floor());

    _articlePrice =
        Repository().queryArticlePrice(widget.warenkorbLine.articleId);
    _article = Repository().queryArticleDetails(widget.warenkorbLine.articleId);

    warenkorbBloc = BlocProvider.of<WarenkorbBloc>(context);
  }

  @override
  Widget build(BuildContext context) {
    return Dismissible(
      onDismissed: (direction) {
        warenkorbBloc.dispatch(
            RemoveWarenkorbItem(articleId: widget.warenkorbLine.articleId));
      },
      key: Key(''),
      child: FlatButton(
        padding: EdgeInsets.zero,
        onPressed: () {
          Navigator.pushNamed(context, RouteName.ARTICLE_DETAIL,
              arguments: widget.warenkorbLine.articleId);
        },
        child: Column(
          children: <Widget>[
            widget.buildWithPadding
                ? Container(
                    height: ImpexStyle.verticalPadding,
                  )
                : Center(),
            Flex(
              direction: Axis.horizontal,
              children: <Widget>[
                Container(
                  width: ImpexStyle.horizontalPadding,
                ),
                MyFutureBuilder(
                  future: _articleImageData,
                  builder: (context, snapshotData) {
                    return Container(
                      width: ImpexStyle.imageSize.toDouble(),
                      height: ImpexStyle.imageSize.toDouble(),
                      child: Image.memory(
                          Uint8List.fromList(snapshotData.codeUnits)),
                    );
                  },
                ),
                Container(
                  width: ImpexStyle.horizontalPadding,
                ),
                MyFutureBuilder(
                  future: _article,
                  builder: (context, article) {
                    return MyFutureBuilder(
                      future: _articlePrice,
                      builder: (context, price) {
                        final singlePrice =
                            getPriceFromArticleAndSettings(price, context);
                        final totalPrice =
                            singlePrice * widget.warenkorbLine.amount;

                        final singlePriceString =
                            formatDoubleNumber(singlePrice);
                        final totalPriceString = formatDoubleNumber(totalPrice);

                        return Flexible(
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
                              Row(
                                children: <Widget>[
                                  Text(
                                    article.no,
                                    style: ImpexStyle.fontStyleSmall,
                                  ),
                                  Spacer(),
                                  article.isRaffleWin
                                      ? RaffleWinIcon()
                                      : Text('€',
                                          style: ImpexStyle.fontStyleSmall),
                                  Text(singlePriceString,
                                      style: ImpexStyle.fontStyleSmall),
                                  Container(width: ImpexStyle.verticalPadding),
                                ],
                              ),
                              Row(
                                children: <Widget>[
                                  Text(widget.warenkorbLine.amount.toString()),
                                  Text(article.defaultUnit),
                                  Spacer(),
                                  article.isRaffleWin
                                      ? RaffleWinIcon()
                                      : Text('€'),
                                  Text(totalPriceString),
                                  Container(width: ImpexStyle.verticalPadding),
                                ],
                              ),
                              Padding(
                                padding: const EdgeInsets.only(
                                    right: ImpexStyle.horizontalPadding),
                                child: Text(article.name,
                                    style: ImpexStyle.fontStyleNormal),
                              )
                            ],
                          ),
                        );
                      },
                    );
                  },
                ),
              ],
            ),
            widget.buildWithDivider
                ? Divider(
                    color: ImpexColors.dividerColor,
                  )
                : Center(),
          ],
        ),
      ),
    );
  }
}

class WarenkorbFooter extends StatefulWidget {
  WarenkorbFooter();

  @override
  _WarenkorbFooterState createState() => _WarenkorbFooterState();
}

class _WarenkorbFooterState extends State<WarenkorbFooter> {
  WarenkorbBloc warenkorbBloc;
  SettingsBloc settingsBloc;
  Future<double> sum;

  @override
  void initState() {
    super.initState();
    warenkorbBloc = BlocProvider.of<WarenkorbBloc>(context);
    settingsBloc = BlocProvider.of<SettingsBloc>(context);
    sum = getWarenkorbSumme(context);
  }

  Future<double> getWarenkorbSumme(BuildContext context) async {
    double sum = 0;

    Map<int, WarenkorbLine> warenkorbLines =
        (warenkorbBloc.currentState as WarenkorbLoaded).warenkorbLines;

    for (WarenkorbLine line in warenkorbLines.values) {
      Article article = await Repository().queryArticleDetails(line.articleId);
      if (article.isRaffleWin) {
        continue;
      }

      ArticleRangedPriceList rangedList =
          await Repository().queryArticleRangedPrices(line.articleId);
      ArticlePrice articlePrice =
          await Repository().queryArticlePrice(line.articleId);
      double singlePrice =
          getPriceFromArticleAndSettings(articlePrice, context);
      for (int i = 0; i < rangedList.articleRangedPrices.length; ++i) {
        ArticleRangedPrice rangedPrice = rangedList.articleRangedPrices[i];
        if (line.amount >= rangedPrice.fromQuantity) {
          singlePrice =
              getPriceFromRangedPriceAndSettings(rangedPrice, context);
        }
      }

      sum += singlePrice * line.amount;
    }

    return sum;
  }

  @override
  Widget build(BuildContext context) {
    double einkaufsrahmen =
        (settingsBloc.currentState as SettingsLoaded).user.customerCreditLimit;

    String priceInfo = (settingsBloc.currentState as SettingsLoaded).useUst
        ? 'Gesamt Brutto'
        : 'Gesamt Netto';

    return Container(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.end,
        mainAxisAlignment: MainAxisAlignment.end,
        children: <Widget>[
          Container(
            height: ImpexStyle.verticalPadding,
          ),
          ImpexButton(
            data: 'Bestellen',
            pressed: () {
              if ((warenkorbBloc.currentState as WarenkorbLoaded)
                  .warenkorbLines
                  .isNotEmpty)
                Navigator.pushNamed(context, RouteName.BAUSTELLEN);
            },
          ),
          Container(
            height: ImpexStyle.verticalPadding,
          ),
          Row(
            children: <Widget>[
              Spacer(),
              Text('$priceInfo €'),
              MyFutureBuilder(
                future: sum,
                builder: (context, double sum) {
                  var mySum = formatDoubleNumber(sum);
                  return Text('$mySum');
                },
              ),
              Container(
                width: ImpexStyle.horizontalPadding,
              ),
            ],
          ),
          Row(
            children: <Widget>[
              Spacer(),
              Text(
                'Ihr Einkaufsrahmen ',
                style: ImpexStyle.fontStyleNormal,
              ),
              Text(
                einkaufsrahmen != 0 ? '$einkaufsrahmen' : 'verbraucht',
                style: TextStyle(
                    color:
                        einkaufsrahmen == 0 ? ImpexColors.red : Colors.black),
              ),
              Container(
                width: ImpexStyle.horizontalPadding,
              ),
            ],
          ),
        ],
      ),
    );
  }
}

class EmptyBasket extends StatelessWidget {
  const EmptyBasket();

  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        // prevent TextOverflow: wrap [Text] inside [Expanded] and put in [Row]
        Expanded(
          child: Text(
            'Gehen sie im Menü auf "Artikel" um Artikel zu finden und in den Warenkorb zu legen. ',
          ),
        ),
      ],
    );
  }
}

1 个答案:

答案 0 :(得分:0)

我必须将页脚包装在CustomScrollView中