XAppBar function

AppBar XAppBar(
  1. dynamic context, {
  2. String? title,
  3. PreferredSizeWidget? bottom,
  4. Widget? subTitle,
  5. Widget? titleWidget,
  6. double? tWidth,
  7. double? tHeight,
  8. Function? willPopFn,
  9. Widget? backWidget,
  10. Function? backWidgetFn,
  11. List<Widget>? actions,
  12. Color? backgroundColor,
  13. bool? elevation,
  14. double? toolbarHeight,
  15. String? theme = "light",
  16. bool automaticallyImplyLeading = true,
})

Implementation

AppBar XAppBar(
  context, {
  String? title,
  PreferredSizeWidget? bottom,
  Widget? subTitle,
  Widget? titleWidget,
  double? tWidth,
  double? tHeight,
  Function? willPopFn,
  Widget? backWidget,
  Function? backWidgetFn,
  List<Widget>? actions,
      Color?  backgroundColor,
  bool? elevation,
      double? toolbarHeight,
      String?   theme= "light",
      bool automaticallyImplyLeading = true,
}) {
  onPressed() async {
    if (backWidgetFn == null) {
      var pop = await willPopFn?.call();
      var canPop = pop == null || pop;
      if (Navigator.canPop(context) && canPop) {
        Navigator.pop(context);
      } else {
        if (canPop) {
          XUtil.flutterPop();
        }
      }
    } else {
      backWidgetFn.call();
    }
  }

  return AppBar(
    automaticallyImplyLeading:automaticallyImplyLeading,
    // backgroundColor:Colors.transparent,
    backgroundColor:backgroundColor??(theme == 'light'? themeColor.ffFFFFFF : themeColor.primary),
    title: titleWidget ??
        (Stack(
          alignment: AlignmentDirectional.center,
          children: [
            subTitle ?? const SizedBox(width: 0, height: 0),
            Text(
              '$title',
              style: TextStyle(fontSize: 36.w).copyWith(color:theme == 'light'?  themeColor.ff0E1424:themeColor.ffFFFFFF, fontWeight: FontWeight.w500),
            ),
          ],
        ).background(width: tWidth, height: tHeight)),
    centerTitle: titleWidget == null ? true : false,
    elevation: elevation ?? false ? 1.w : 0,
    toolbarHeight:toolbarHeight??( bottom == null ? 44 : 88),
    leading:automaticallyImplyLeading==false?null:(backWidget == null
        ? IconButton(
      color:theme == 'light'?  Colors.black:themeColor.ffFFFFFF,
      icon: Icon(
        Icons.arrow_back_ios,
        size: 20,
      ),
      onPressed: onPressed,
    )
        : XButton(
      callback: backWidgetFn ?? onPressed,
      child: backWidget,
    )),
    actions: actions ??(automaticallyImplyLeading==false?null: [const SizedBox(width: 44)]),
    bottom: bottom,
  );
}