build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Implementation

@override
Widget build(BuildContext context) {

  bool showBack = ModalRoute.of(context)?.canPop ?? false ;
  // bool showBack = Navigator.of(context).canPop();

  Drawer? thisDrawer = buildDrawer(context);
  // bool largeScreen = context.largeScreen;
  // 调用MediaQuery.of(context) 会导致输入法打开又关闭.
  bool largeScreen = !Plat.isMobile;

  Widget? leadButton;
  if (thisDrawer != null) {
    leadButton = Builder(
      builder: (ctx) {
        return IconButton(
          onPressed: () {
            if (largeScreen) {
              _showDrawer = !_showDrawer;
              updateState();
            } else {
              Scaffold.of(ctx).openDrawer();
            }
          },
          icon: Icons.menu.icon(size: 32),
        );
      },
    );
  } else if (showBack) {
    leadButton = IconButton(
      onPressed: () {
        onBackPressed(context);
      },
      icon: Icons.keyboard_arrow_left.icon(size: 32),
    );
  }

  HareAppBar? bar = buildAppBar(
    context,
    leading: leadButton,
    leadingWidth: (leadButton != null) ? 48 : null,
    titleSpacing: (leadButton != null) ? 0 : null,
    title: buildTitle(context),
    actions: buildActions(context),
    centerTitle: isTitleCenter(),
    bottom: buildAppBarBottom(context),
  ).also((e) => appBar = e);

  HareBuilder bBuilder = HareBuilder((c) => buildBody(c, thisDrawer, largeScreen) ?? Container());
  bodyBuilder = bBuilder;
  return buildScaffold(
    context,
    appBar: bar,
    bottomBar: buildBottomNavigationBar(context),
    drawer: largeScreen ? null : thisDrawer,
    body: safeArea ? Container(child: bBuilder).safeArea() : Container(child: bBuilder),
  );
}