createLeading static method

KeyedSubtree? createLeading({
  1. required GlobalKey<State<StatefulWidget>> leadingKey,
  2. required Widget? userLeading,
  3. required ModalRoute? route,
  4. required bool automaticallyImplyLeading,
  5. required EdgeInsetsDirectional? padding,
})

Implementation

static KeyedSubtree? createLeading({
  required GlobalKey leadingKey,
  required Widget? userLeading,
  required ModalRoute<dynamic>? route,
  required bool automaticallyImplyLeading,
  required EdgeInsetsDirectional? padding,
}) {
  Widget? leadingContent;

  if (userLeading != null) {
    leadingContent = userLeading;
  } else if (automaticallyImplyLeading &&
      route is PageRoute &&
      route.canPop &&
      route.fullscreenDialog) {
    leadingContent = CupertinoButton(
      padding: EdgeInsets.zero,
      onPressed: () {
        route.navigator!.maybePop();
      },
      child: const Text('Close'),
    );
  } else if (!automaticallyImplyLeading && userLeading == null) {
    /// this will help animate things whatever it takes
    leadingContent = const SizedBox();
  }

  if (leadingContent == null) {
    return null;
  }

  return KeyedSubtree(
    key: leadingKey,
    child: Padding(
      padding: EdgeInsetsDirectional.only(
        start: padding?.start ?? 0,
      ),
      child: IconTheme.merge(
        data: const IconThemeData(
          size: 32.0,
        ),
        child: leadingContent,
      ),
    ),
  );
}