Skip to content

Instantly share code, notes, and snippets.

@febritecno
Last active October 10, 2022 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save febritecno/1aed8d430fe0493bca98bcfb4f249b38 to your computer and use it in GitHub Desktop.
Save febritecno/1aed8d430fe0493bca98bcfb4f249b38 to your computer and use it in GitHub Desktop.
universal textField component
import 'package:bjb_epays_mobile/marketplace/shared/theme.dart';
import 'package:bjb_epays_mobile/shared/shared_colors.dart';
import 'package:flutter/material.dart';
class ButtonComponent extends StatelessWidget {
final VoidCallback? onTap;
final String? title;
final double? fontSize, borderCircular, height, width;
final Color? color, fontColor;
final FontWeight? fontWeight;
final LinearGradient? linearGradient;
final BoxDecoration? boxDecoration;
final TextStyle? textStyle;
const ButtonComponent(
this.title, {
Key? key,
this.onTap,
this.fontSize,
this.color,
this.fontWeight,
this.borderCircular,
this.fontColor,
this.linearGradient,
this.height,
this.boxDecoration,
this.textStyle,
this.width,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
width: width ?? MediaQuery.of(context).size.width,
height: height ?? 54,
decoration: boxDecoration ??
BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black26,
offset: Offset(0, 4),
blurRadius: 5.0)
],
gradient: linearGradient ??
LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [HexColor("#427ECF"), HexColor("#2D5994")],
),
color: color,
borderRadius: BorderRadius.circular(borderCircular ?? 16)),
child: ElevatedButton(
onPressed: onTap,
style: ButtonStyle(
shadowColor: MaterialStateProperty.all(Colors.transparent),
backgroundColor: MaterialStateProperty.all(Colors.transparent),
elevation: MaterialStateProperty.all<double>(0),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
borderCircular ?? 20,
),
),
),
),
child: Text(
title!,
style: textStyle ??
TextStyle(
color: fontColor ?? Colors.white,
fontSize: fontSize ?? 16,
fontWeight: fontWeight ?? semiBold),
),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class InputComponent extends StatelessWidget {
final Function(String)? onChanged;
final TextStyle? placeholderStyle, labelStyle;
final Color? color;
final Widget? suffix, prefix;
final String? label, initialValue, placeholder, labelText;
final FontWeight? fontWeight;
final Alignment? suffixAlign, prefixAlign;
final TextInputType? keyboardType;
final List<TextInputFormatter>? inputFormatters;
final double? labelSize,
fontSize,
suffixSize,
prefixSize,
paddingHorizontal,
paddingVertical;
final int? maxLines, minLines;
final TextInputAction? textInputAction;
final bool? enabled, readOnly, autofocus, obscureText;
final TextEditingController? controller;
final EdgeInsets? contentPadding;
final Widget? suffixIcon;
final Widget? prefixIcon;
const InputComponent(
{Key? key,
this.label,
this.suffix,
this.prefix,
this.fontWeight,
this.labelSize,
this.controller,
this.initialValue,
this.enabled,
this.suffixSize,
this.prefixSize,
this.suffixIcon,
this.contentPadding,
this.fontSize,
this.suffixAlign,
this.prefixAlign,
this.readOnly,
this.paddingHorizontal,
this.paddingVertical,
this.placeholder,
this.labelText,
this.keyboardType,
this.inputFormatters,
this.autofocus,
this.onChanged,
this.maxLines,
this.textInputAction,
this.minLines,
this.color,
this.prefixIcon,
this.placeholderStyle,
this.obscureText,
this.labelStyle})
: super(key: key);
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
(label != null)
? Text(label ?? 'label',
style: textStyle.copyWith(
color: Colors.grey,
fontWeight: fontWeight ?? FontWeight.bold,
fontSize: labelSize ?? 14))
: const SizedBox(),
TextFormField(
cursorColor: Colors.black,
minLines: minLines ?? 1,
maxLines: maxLines ?? 1,
obscureText: obscureText ?? false,
textInputAction: textInputAction ?? TextInputAction.done,
onChanged: onChanged,
autofocus: autofocus ?? false,
readOnly: readOnly ?? false,
controller: controller,
style: TextStyle(
color: color ?? Colors.black,
fontWeight: fontWeight ?? FontWeight.w400,
fontSize: fontSize ?? 20),
initialValue: initialValue,
decoration: InputDecoration(
hintText: placeholder,
hintStyle: placeholderStyle,
prefixIconConstraints: const BoxConstraints(),
enabled: enabled ?? true,
labelText: labelText,
labelStyle: labelStyle,
floatingLabelBehavior: FloatingLabelBehavior.never,
suffix: suffix ?? SizedBox(width: suffixSize ?? 0),
prefix: prefix ?? SizedBox(width: prefixSize ?? 0),
suffixIcon: suffixIcon,
prefixIcon: prefixIcon,
disabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey.shade300)),
fillColor: Colors.white,
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey.shade300)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey.shade400)),
contentPadding: contentPadding ??
const EdgeInsets.symmetric(horizontal: 0, vertical: 12)),
keyboardType: keyboardType ?? TextInputType.text,
inputFormatters: inputFormatters ?? [],
),
],
);
}
}
@febritecno
Copy link
Author

febritecno commented Oct 10, 2022

import 'package:cached_network_image/cached_network_image.dart';
import 'package:dteksi/shared/constants.dart';
import 'package:flutter/material.dart';

class ImgNetwork extends StatelessWidget {
  final double? loaderHeight;
  final double? loaderWidth;
  final double? loaderRadius;
  final String? defaultPath;
  final String url;
  final BoxFit? fit;
  const ImgNetwork(this.url,
      {Key? key,
      this.loaderHeight,
      this.loaderWidth,
      this.loaderRadius = 0,
      this.fit,
      this.defaultPath: NO_IMAGE})
      : super(key: key);
  @override
  Widget build(BuildContext context) {
    return CachedNetworkImage(
      imageUrl: url,
      fit: fit ?? BoxFit.cover,
      // progressIndicatorBuilder: (context, child, loadingProgress) {
      //   if (loadingProgress == null) return SizedBox();
      //   return Center(
      //       child: BoxSkeleton(
      //           height: loaderHeight,
      //           width: loaderWidth,
      //           radius: loaderRadius));
      // },
      errorWidget: (context, exception, stackTrace) {
        return Container(
          height: 200,
          color: Colors.grey.withOpacity(0.2),
          child: Center(child: Image.asset(defaultPath!, fit: BoxFit.fill)),
        );
      },
    );
  }
}

@febritecno
Copy link
Author

febritecno commented Oct 10, 2022

import 'package:dteksi/helpers/third_party/shimmer.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:dteksi/helpers/third_party/sizer/sizer.dart';

class BoxSkeleton extends StatelessWidget {
  final double? height;
  final double? width;
  final double? radius;
  const BoxSkeleton({Key? key, this.height, this.width, this.radius})
      : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Shimmer.fromColors(
        baseColor: Colors.grey.shade500,
        highlightColor: Colors.grey.shade600,
        child: Container(
          decoration: BoxDecoration(
              borderRadius: BorderRadius.all(Radius.circular(radius ?? 12)),
              color: Colors.grey),
          height: height ?? 30.h,
          width: width ?? Get.width,
        ),
      ),
    );
  }
}

@febritecno
Copy link
Author

febritecno commented Oct 10, 2022

import 'package:intl/intl.dart';

class FormatNumber {
  static String convertNumber(dynamic number, int decimalDigit) {
    NumberFormat formattedNumber = NumberFormat.currency(
      locale: 'en_US',
      symbol: '',
      decimalDigits: decimalDigit,
    );
    return formattedNumber.format(number);
  }

  static String convertRupiah(String number,
      {symbol = 'Rp. ', customPattern, decimalDigit = 0}) {
    NumberFormat formattedNumber = NumberFormat.currency(
      // customPattern: "#,##0",
      // locale: 'id',
      customPattern: customPattern,
      symbol: symbol,
      decimalDigits: decimalDigit,
    );
    var parsed = number.replaceAll(RegExp('[^0-9]'), '');
    return formattedNumber.format(int.parse(parsed));
  }
}

@febritecno
Copy link
Author

febritecno commented Oct 10, 2022

import 'package:flutter/material.dart';
import 'package:get/get.dart';

class AppSnackBar {
  static void dynamic(
      {String title = "Info",
      required String message,
      Color colorText = Colors.white,
      Color backgroundColor = Colors.black,
      required Icon icon,
      SnackPosition snackPosition = SnackPosition.BOTTOM,
      int seconds = 3}) {
    Get.snackbar(
      title,
      message,
      icon: icon,
      colorText: colorText,
      backgroundColor: backgroundColor,
      forwardAnimationCurve: Curves.fastOutSlowIn,
      snackPosition: snackPosition,
      shouldIconPulse: true,
      margin: EdgeInsets.only(bottom: 5, left: 20, right: 20),
      isDismissible: true,
      duration: Duration(seconds: seconds),
    );
  }

  static void success(String message, {seconds}) {
    Get.snackbar(
      "Success",
      message,
      icon: Icon(Icons.check_circle_outline_rounded, color: Colors.white),
      colorText: Colors.white,
      backgroundColor: Colors.green[900],
      forwardAnimationCurve: Curves.fastOutSlowIn,
      snackPosition: SnackPosition.TOP,
      shouldIconPulse: true,
      margin: EdgeInsets.only(bottom: 5, left: 20, right: 20),
      isDismissible: true,
      duration: Duration(seconds: seconds ?? 3),
    );
  }

  static void info(String message, {duration}) {
    Get.snackbar(
      "Info",
      message,
      colorText: Colors.white,
      backgroundColor: Colors.black,
      forwardAnimationCurve: Curves.fastLinearToSlowEaseIn,
      reverseAnimationCurve: Curves.linear,
      snackPosition: SnackPosition.BOTTOM,
      shouldIconPulse: true,
      isDismissible: true,
      duration: Duration(seconds: duration ?? 3),
    );
  }

  static void error(String message, {String? title}) {
    Get.snackbar(
      title ?? "Error",
      message,
      icon: Icon(Icons.error, color: Colors.white),
      colorText: Colors.white,
      backgroundColor: Colors.red[900],
      forwardAnimationCurve: Curves.fastOutSlowIn,
      snackPosition: SnackPosition.TOP,
      shouldIconPulse: true,
      margin: EdgeInsets.only(bottom: 5, left: 20, right: 20),
      isDismissible: true,
      duration: Duration(seconds: 3),
    );
  }
}

@febritecno
Copy link
Author

import 'package:dteksi/helpers/third_party/sizer/sizer.dart';
import 'package:dteksi/shared/theme.dart';
import 'package:dteksi/shared/widgets/components/img_network.dart';
import 'package:dteksi/shared/widgets/text_app.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class AppDialog {
  static void load(Widget child,
      {barrierDismissible = false, barrierColor = Colors.black45}) {
    Get.dialog(
      child,
      barrierColor: barrierColor,
      barrierDismissible: barrierDismissible,
    );
  }

  static Future<dynamic> showAlert(
      {required title,
      required btnLeft,
      required btnRight,
      required desc,
      onBtnLeft,
      onBtnRight}) {
    return showDialog(
        context: Get.context!,
        builder: (BuildContext context) {
          return AlertItem(
              btnLeft: btnLeft,
              btnRight: btnRight,
              desc: desc,
              onBtnLeft: onBtnLeft,
              onBtnRight: onBtnRight,
              title: title);
        });
  }

  static Future<dynamic> previewImage({image}) {
    return showDialog(
        context: Get.context!,
        builder: (BuildContext context) {
          return PreviewItem(
            image: image,
          );
        });
  }
}

class PreviewItem extends StatelessWidget {
  final String? image;

  const PreviewItem({
    Key? key,
    this.image,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onDoubleTap: () => Get.back(),
      child: Container(
        color: Colors.black.withOpacity(0.8),
        child: InteractiveViewer(
          panEnabled: false,
          boundaryMargin: EdgeInsets.all(100),
          minScale: 0.5,
          maxScale: 2,
          child: AlertDialog(
              contentPadding: EdgeInsets.zero,
              titlePadding: EdgeInsets.zero,
              buttonPadding: EdgeInsets.zero,
              actionsPadding: EdgeInsets.zero,
              insetPadding: EdgeInsets.zero,
              backgroundColor: Colors.transparent,
              content: ImgNetwork(image!)),
        ),
      ),
    );
  }
}

//* AUTOSIZE CONTAINER DIALOG
class AlertItem extends StatelessWidget {
  final String? title, desc, btnLeft, btnRight;
  final Widget? body, footer;
  final VoidCallback? onBtnLeft, onBtnRight;

  const AlertItem({
    Key? key,
    this.title,
    this.desc,
    this.btnLeft,
    this.btnRight,
    this.onBtnLeft,
    this.onBtnRight,
    this.body,
    this.footer,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      content: ConstrainedBox(
        constraints: BoxConstraints(
          //* atur maxHeight buat batasin ukuran dialog 100.h = 100% full screen di layar
          maxHeight: 80.h,
        ),
        child: Container(
          decoration: BoxDecoration(
            shape: BoxShape.rectangle,
            color: Color(0xFFFFFF),
            borderRadius: BorderRadius.all(Radius.circular(32)),
          ),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              body == null
                  ? Column(
                      children: [
                        TextApp(
                          title!,
                          color: kBlueColor,
                          fontWeight: FontWeight.w900,
                          fontSize: 16.sp,
                          textAlign: TextAlign.center,
                          overflow: TextOverflow.clip,
                          maxLines: 2,
                        ),
                        SizedBox(height: 2.h),
                        TextApp(
                          desc!,
                          fontWeight: FontWeight.w400,
                          fontSize: 14.sp,
                          textAlign: TextAlign.center,
                          // *atur maxLines buat batasin max baris yang ditampilkan
                          maxLines: 18,
                          softWrap: true,
                          overflow: TextOverflow.clip,
                        ),
                      ],
                    )
                  : body!,
              footer == null
                  ? Padding(
                      padding: EdgeInsets.only(top: 4.h),
                      child: Row(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          ElevatedButton(
                              style: ButtonStyle(
                                backgroundColor:
                                    MaterialStateProperty.resolveWith<Color>(
                                  (Set<MaterialState> states) {
                                    return kBlueColor;
                                  },
                                ),
                                padding: MaterialStateProperty.all(
                                    EdgeInsets.symmetric(
                                        vertical: 0, horizontal: 0)),
                                tapTargetSize: MaterialTapTargetSize.shrinkWrap,
                                minimumSize:
                                    MaterialStateProperty.all(Size(30.w, 20)),
                                shape: MaterialStateProperty.all<
                                        RoundedRectangleBorder>(
                                    RoundedRectangleBorder(
                                  borderRadius: BorderRadius.circular(6.0),
                                )),
                              ),
                              onPressed:
                                  onBtnLeft ?? () => Navigator.pop(context),
                              child: Padding(
                                padding: EdgeInsets.symmetric(
                                    horizontal: 1.w, vertical: 1.5.h),
                                child: TextApp(
                                  btnLeft!,
                                  fontSize: 12.sp,
                                  color: Colors.white,
                                  fontWeight: FontWeight.w700,
                                ),
                              )),
                          // *atur jarak kedua tombol agar engga gancet ketika text cuma sebiji
                          SizedBox(width: 3.w),
                          ElevatedButton(
                            style: ButtonStyle(
                              backgroundColor:
                                  MaterialStateProperty.resolveWith<Color>(
                                (Set<MaterialState> states) {
                                  return kBlueColor;
                                },
                              ),
                              padding: MaterialStateProperty.all(
                                  EdgeInsets.symmetric(
                                      vertical: 0, horizontal: 0)),
                              tapTargetSize: MaterialTapTargetSize.shrinkWrap,
                              minimumSize:
                                  MaterialStateProperty.all(Size(30.w, 20)),
                              shape: MaterialStateProperty.all<
                                      RoundedRectangleBorder>(
                                  RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(6.0),
                              )),
                            ),
                            onPressed: onBtnRight,
                            child: Padding(
                              padding: EdgeInsets.symmetric(
                                  horizontal: 1.w, vertical: 1.5.h),
                              child: TextApp(
                                btnRight!,
                                fontSize: 12.sp,
                                color: Colors.white,
                                fontWeight: FontWeight.w700,
                              ),
                            ),
                          ),
                        ],
                      ),
                    )
                  : footer!
            ],
          ),
        ),
      ),
    );
  }
}
//*

@febritecno
Copy link
Author

import 'package:bjb_epays_mobile/marketplace/shared/theme.dart';
import 'package:flutter/material.dart';

//* Items
class ListBottomSheet extends StatelessWidget {
  const ListBottomSheet(
      {Key? key,
      required this.title,
      required this.onTap,
      required this.context})
      : super(key: key);

  final String title;
  final Function onTap;
  final BuildContext context;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        ListTile(
          contentPadding:
              const EdgeInsets.symmetric(horizontal: defaultMargin + 4),
          title: Text(title, style: textStyle.copyWith(fontSize: 18)),
          onTap: () async {
            Navigator.pop(context);
            await onTap();
          },
        ),
        Divider(height: 20, color: Colors.grey.shade300),
      ],
    );
  }
}

//* Handler
class MPBottomSheet {
  static show(
      {required context,
      RoundedRectangleBorder? shape = const RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(
          top: Radius.circular(12),
        ),
      ),
      required String? title,
      required Function? items,
      required itemLenght,
      double? heightFactor = 1,
      Widget? header,
      Widget? body,
      bool isFull = false,
      bool isDismissible = true}) {
    return showModalBottomSheet(
      shape: shape,
      context: context,
      isScrollControlled: isFull,
      clipBehavior: Clip.antiAliasWithSaveLayer,
      isDismissible: isDismissible,
      builder: (context) => FractionallySizedBox(
        heightFactor: heightFactor,
        child: Column(
          children: [
            header ??
                Padding(
                  padding: const EdgeInsets.symmetric(vertical: 30),
                  child: Row(
                    children: [
                      GestureDetector(
                        onTap: () => Navigator.pop(context),
                        child: const Padding(
                          padding:
                              EdgeInsets.symmetric(horizontal: defaultMargin),
                          child:
                              Icon(Icons.close, color: Colors.grey, size: 35),
                        ),
                      ),
                      Center(
                        child: Text(
                          "$title",
                          style: textStyle.copyWith(
                            fontSize: 24,
                            fontWeight: FontWeight.w700,
                          ),
                        ),
                      )
                    ],
                  ),
                ),
            body ??
                Expanded(
                  child: ListView.builder(
                    itemBuilder: (_, index) => items!(index),
                    itemCount: itemLenght,
                  ),
                ),
          ],
        ),
      ),
    );
  }
}

@febritecno
Copy link
Author

import 'package:bjb_epays_mobile/marketplace/shared/theme.dart';
import 'package:bjb_epays_mobile/marketplace/shared/widgets/img_network.dart';
import 'package:flutter/material.dart';

//* Items
class PreviewItem extends StatelessWidget {
  final String? image;

  const PreviewItem({
    Key? key,
    this.image,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onDoubleTap: () => Navigator.pop(context),
      child: Container(
        color: Colors.black.withOpacity(0.8),
        child: InteractiveViewer(
          panEnabled: false,
          boundaryMargin: const EdgeInsets.all(100),
          minScale: 0.5,
          maxScale: 2,
          child: AlertDialog(
              contentPadding: EdgeInsets.zero,
              titlePadding: EdgeInsets.zero,
              buttonPadding: EdgeInsets.zero,
              actionsPadding: EdgeInsets.zero,
              insetPadding: EdgeInsets.zero,
              backgroundColor: Colors.transparent,
              content: ImgNetwork(image!)),
        ),
      ),
    );
  }
}

class AlertItem extends StatelessWidget {
  final String? title, desc, btnLeft, btnRight;
  final Widget? body, footer;
  final VoidCallback? onBtnLeft, onBtnRight;

  const AlertItem({
    Key? key,
    this.title,
    this.desc,
    this.btnLeft,
    this.btnRight,
    this.onBtnLeft,
    this.onBtnRight,
    this.body,
    this.footer,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      content: ConstrainedBox(
        constraints: const BoxConstraints(
          maxHeight: 180,
        ),
        child: Container(
          decoration: const BoxDecoration(
            shape: BoxShape.rectangle,
            color: Color(0xFFFFFF),
            borderRadius: BorderRadius.all(Radius.circular(32)),
          ),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              body == null
                  ? Column(
                      children: [
                        Text(
                          title!,
                          textAlign: TextAlign.center,
                          maxLines: 2,
                          style: const TextStyle(
                            fontWeight: FontWeight.w900,
                            fontSize: 16,
                            color: kBlueColor,
                            overflow: TextOverflow.clip,
                          ),
                        ),
                        const SizedBox(height: 4),
                        Text(
                          desc!,
                          textAlign: TextAlign.center,
                          maxLines: 18,
                          softWrap: true,
                          overflow: TextOverflow.clip,
                          style: const TextStyle(
                            fontWeight: FontWeight.w400,
                            fontSize: 14,
                          ),
                        ),
                      ],
                    )
                  : body!,
              footer == null
                  ? Padding(
                      padding: const EdgeInsets.only(top: 4),
                      child: Row(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          ElevatedButton(
                              style: ButtonStyle(
                                backgroundColor:
                                    MaterialStateProperty.resolveWith<Color>(
                                  (Set<MaterialState> states) {
                                    return kBlueColor;
                                  },
                                ),
                                padding: MaterialStateProperty.all(
                                    const EdgeInsets.symmetric(
                                        vertical: 0, horizontal: 0)),
                                tapTargetSize: MaterialTapTargetSize.shrinkWrap,
                                minimumSize: MaterialStateProperty.all(
                                    const Size(30, 20)),
                                shape: MaterialStateProperty.all<
                                        RoundedRectangleBorder>(
                                    RoundedRectangleBorder(
                                  borderRadius: BorderRadius.circular(6.0),
                                )),
                              ),
                              onPressed:
                                  onBtnLeft ?? () => Navigator.pop(context),
                              child: Padding(
                                padding: const EdgeInsets.symmetric(
                                    horizontal: 1, vertical: 1.5),
                                child: Text(
                                  btnLeft!,
                                  style: const TextStyle(
                                    fontSize: 12,
                                    color: Colors.white,
                                    fontWeight: FontWeight.w700,
                                  ),
                                ),
                              )),
                          const SizedBox(width: 3),
                          ElevatedButton(
                            style: ButtonStyle(
                              backgroundColor:
                                  MaterialStateProperty.resolveWith<Color>(
                                (Set<MaterialState> states) {
                                  return kBlueColor;
                                },
                              ),
                              padding: MaterialStateProperty.all(
                                  const EdgeInsets.symmetric(
                                      vertical: 0, horizontal: 0)),
                              tapTargetSize: MaterialTapTargetSize.shrinkWrap,
                              minimumSize:
                                  MaterialStateProperty.all(const Size(30, 20)),
                              shape: MaterialStateProperty.all<
                                      RoundedRectangleBorder>(
                                  RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(6.0),
                              )),
                            ),
                            onPressed: onBtnRight,
                            child: Padding(
                              padding: const EdgeInsets.symmetric(
                                  horizontal: 4, vertical: 1.5),
                              child: Text(
                                btnRight!,
                                style: const TextStyle(
                                  fontSize: 12,
                                  color: Colors.white,
                                  fontWeight: FontWeight.w700,
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                    )
                  : footer!
            ],
          ),
        ),
      ),
    );
  }
}

//* Handler
class MPDialog {
  static Future<dynamic> showAlert(
      {required title,
      required btnLeft,
      required btnRight,
      required desc,
      required context,
      onBtnLeft,
      onBtnRight}) {
    return showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertItem(
              btnLeft: btnLeft,
              btnRight: btnRight,
              desc: desc,
              onBtnLeft: onBtnLeft,
              onBtnRight: onBtnRight,
              title: title);
        });
  }

  static Future<dynamic> previewImage(context, {image}) {
    return showDialog(
        context: context,
        builder: (BuildContext context) {
          return PreviewItem(
            image: image,
          );
        });
  }
}

@febritecno
Copy link
Author

import 'package:bjb_epays_mobile/shared/environment.dart';
import 'package:flutter/material.dart';

class Helpers {
  static log(value, {prefix = "logPrint"}) {
    if (Environment().config.name == "DEV") {
      // ignore: avoid_print
      return print("$prefix=> ${value!}");
    } else {
      return;
    }
  }

  static percentWidth(BuildContext context, double width) {
    return ((MediaQuery.of(context).size.width) * width) / 100;
  }

  static percentHeight(BuildContext context, double height) {
    return ((MediaQuery.of(context).size.height) * height) / 100;
  }

  static height(BuildContext context) {
    return (MediaQuery.of(context).size.height);
  }

  static width(BuildContext context) {
    return (MediaQuery.of(context).size.width);
  }

  static sp(BuildContext context, double val) {
    return val * (MediaQuery.of(context).size.width / 3) / 100;
  }
}

@febritecno
Copy link
Author

import 'package:bjb_epays_mobile/marketplace/shared/theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';

class AppbarTemplate extends StatelessWidget {
  const AppbarTemplate(
      {Key? key,
      this.weight,
      required this.title,
      this.isCenter = true,
      this.body,
      this.onBack,
      this.shadowColor = Colors.white30})
      : super(key: key);

  final String title;
  final double? weight;
  final bool? isCenter;
  final Widget? body;
  final VoidCallback? onBack;
  final Color? shadowColor;

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        backgroundColor: Colors.white,
        appBar: AppBar(
          systemOverlayStyle: defaultStatusBar,
          title: Text(
            title,
            style: textStyle.copyWith(
              fontSize: defaultAppbarTitle,
              fontWeight: bold,
              color: Colors.black,
            ),
          ),
          centerTitle: isCenter,
          elevation: 8,
          shadowColor: shadowColor,
          leading: IconButton(
              color: Colors.black,
              onPressed: onBack ?? () => Modular.to.pop(),
              icon: const Icon(Icons.arrow_back_ios_new_rounded,
                  color: Colors.black)),
          backgroundColor: Colors.white,
        ),
        body: body,
      ),
    );
  }
}

@febritecno
Copy link
Author

// LOADING WRAPPER isLoading

// ignore_for_file: library_private_types_in_public_api

import 'package:bjb_epays_mobile/marketplace/shared/helpers/helper.dart';
import 'package:flutter/material.dart';
import '../theme.dart';

class LoadingApp extends StatefulWidget {
  final bool isLoading;
  final double opacity;
  final Color? backroundColor;
  final Widget? progressIndicator;
  final Widget child;

  const LoadingApp({
    super.key,
    required this.isLoading,
    required this.child,
    this.opacity = 0.5,
    this.progressIndicator,
    this.backroundColor = Colors.black87,
  });

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

class _LoadingAppState extends State<LoadingApp>
    with SingleTickerProviderStateMixin {
  late AnimationController _controller;
  late Animation<double> _animation;
  bool? _overlayVisible;

  _LoadingAppState();

  @override
  void initState() {
    super.initState();
    _overlayVisible = false;
    _controller = AnimationController(
        vsync: this, duration: const Duration(milliseconds: 300));
    _animation = Tween(begin: 0.0, end: 1.0).animate(_controller);
    _animation.addStatusListener((status) {
      // ignore: unnecessary_statements
      status == AnimationStatus.forward
          ? setState(() => {_overlayVisible = true})
          : null;
      // ignore: unnecessary_statements
      status == AnimationStatus.dismissed
          ? setState(() => {_overlayVisible = false})
          : null;
    });
    if (widget.isLoading) {
      _controller.forward();
    }
  }

  @override
  void didUpdateWidget(LoadingApp oldWidget) {
    super.didUpdateWidget(oldWidget);
    if (!oldWidget.isLoading && widget.isLoading) {
      _controller.forward();
    }

    if (oldWidget.isLoading && !widget.isLoading) {
      _controller.reverse();
    }
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    var sizeContainer = ((MediaQuery.of(context).size.width) * 30) / 100;
    var widgets = <Widget>[];
    widgets.add(widget.child);
    if (_overlayVisible == true) {
      final modal = FadeTransition(
        opacity: _animation,
        child: Stack(
          children: <Widget>[
            Opacity(
              opacity: widget.opacity,
              child: ModalBarrier(
                dismissible: false,
                color: widget.backroundColor ??
                    Theme.of(context).colorScheme.background,
              ),
            ),
            Center(
              child: Container(
                width: sizeContainer,
                height: sizeContainer,
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.all(
                    Radius.circular(Helpers.percentWidth(context, 6)),
                  ),
                ),
                child: CircleLoading(
                  progressIndicator: widget.progressIndicator,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment: MainAxisAlignment.center,
                ),
              ),
            )
          ],
        ),
      );
      widgets.add(modal);
    }

    return Stack(children: widgets);
  }
}

class CircleLoading extends StatelessWidget {
  final double sizeHeight, strokeWidth;
  final Color? color, backroundColor;
  final MainAxisAlignment mainAxisAlignment;
  final CrossAxisAlignment crossAxisAlignment;
  final Widget? progressIndicator;

  const CircleLoading(
      {super.key,
      this.sizeHeight = 60,
      this.mainAxisAlignment = MainAxisAlignment.center,
      this.crossAxisAlignment = CrossAxisAlignment.center,
      this.progressIndicator,
      this.color,
      this.strokeWidth = 1.2,
      this.backroundColor});

  @override
  Widget build(BuildContext context) {
    final width = (MediaQuery.of(context).size.width);
    return SizedBox(
      width: width,
      height: sizeHeight,
      child: Center(
          child: progressIndicator ??
              CircularProgressIndicator(
                  color: kBlueColor, strokeWidth: width * 1 / 100)),
    );
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment