Flutter:showModalBottomSheet底部弹出完整页面

dart 复制代码
  // 弹出:商品详情信息页面
  void showInfoBottomSheet(int shopId, int goodsId) {
    showModalBottomSheet(
      context: Get.context!,
      isScrollControlled: true,
      backgroundColor: Colors.transparent,
      isDismissible: true,
      enableDrag: true,
      builder: (context) {
        return Container(
          height: MediaQuery.of(context).size.height * 0.8,
          decoration: BoxDecoration(
            color: AppTheme.pageBgColor,
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(40.w),
              topRight: Radius.circular(40.w),
            ),
          ),
          clipBehavior: Clip.antiAlias,
          child: InfoPage(
            arguments: {
              'shopId': shopId,
              'goodsId': goodsId,
              'customCallback': () {
                // 关闭弹窗
                Get.back();
                // 执行确认后的业务逻辑
                print('用户确认了商品ID: $goodsId');
                showCreateOrderBottomSheet(shopId, goodsId);
              },
            },
          ),
        );
      },
    );
  }

info页面需要接收参数和回调

dart 复制代码
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class InfoController extends GetxController {
  final Map<String, dynamic> arguments;
  InfoController({required this.arguments});
  // ID
  int shopId = 0;
  int goodsId = 0;
  // 自定义回调函数
  VoidCallback? customCallback;

  void _initData() async {
    shopId = arguments['shopId'] ?? 0;
    goodsId = arguments['goodsId'] ?? 0;
    customCallback = arguments['customCallback'];
    update(["info"]);
  }

  // 确认操作
  void onConfirm() {
    customCallback?.call();
  }

}
dart 复制代码
import 'package:ayidaojia/common/index.dart';
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import 'package:get/get.dart';

import 'index.dart';

class InfoPage extends GetView<InfoController> {
  const InfoPage({super.key, required this.arguments});
  final Map<String, dynamic> arguments;

  // 主视图
  Widget _buildView() {
    return <Widget>[
    ].toColumn();
  }
  // 底部按钮
  Widget _buildBottomBar() {
    var bottomStatusBarHeight = MediaQuery.of(Get.context!).padding.bottom;
    return <Widget>[
      ButtonWidget(
        text: '立即抢购',
        width: 750,
        height: 98,
        borderRadius: 0,
        onTap: () => controller.onConfirm(),
      ),
    ]
    .toRow(mainAxisAlignment: MainAxisAlignment.center)
    .paddingOnly(bottom: bottomStatusBarHeight);
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<InfoController>(
      init: InfoController(arguments: arguments),
      id: "info",
      builder: (_) {
        return <Widget>[
          // 主体内容 内部可滚动
          Expanded(
            child: SingleChildScrollView(
              child: _buildView(),
            ),
          ),
          // 固定在底部按钮的按钮
          _buildBottomBar(),
        ].toColumn();
      },
    );
  }
}
相关推荐
组合缺一5 小时前
用 ChatModel 构建 LLM 驱动的 Java 应用
java·开发语言·ai·llm·solon·rag
前端炒粉5 小时前
马克思主义基本原理在Vue框架中的指导作用探析
前端·javascript·vue.js
零点零一5 小时前
QT 5升级到 Qt 6 使用 Clazy 检查将 C++ 应用程序移植到 Qt 6
开发语言·c++·qt
caimouse5 小时前
reactos 测试安装32位微信失败的日志
开发语言·微信
爱奥尼欧5 小时前
轻量级可扩展日志框架-异步日志与系统集成
开发语言·数据库·c++·学习
happyprince5 小时前
12-vLLM 量化方案全面分析
前端·javascript·vllm
大圣编程5 小时前
python break语句
开发语言·前端·python
AI-好学者6 小时前
MCP企业运用全面知识点-基础篇
服务器·开发语言·网络·人工智能·python·架构
ch.ju6 小时前
Java程序设计(第3版)第四章——类加载
java·开发语言
河阿里6 小时前
SLF4J深度指南(Java):从原理到 Spring 项目实战
java·开发语言·spring