144 lines
4.9 KiB
Dart
144 lines
4.9 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:ftc_mobile_app/ftc_mobile_app.dart';
|
|
|
|
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|
final VoidCallback? onBackButtonPressed;
|
|
final Widget? action;
|
|
final Widget? leadingButton;
|
|
final Widget? titleWidget;
|
|
final String titleText;
|
|
final bool showBoxShadow;
|
|
|
|
const CustomAppBar({
|
|
Key? key,
|
|
this.onBackButtonPressed,
|
|
this.showBoxShadow = true,
|
|
this.leadingButton,
|
|
this.action,
|
|
this.titleWidget,
|
|
this.titleText = "",
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final ModalRoute<dynamic>? parentRoute = ModalRoute.of(context);
|
|
final bool canPop = parentRoute?.canPop ?? false;
|
|
return PreferredSize(
|
|
preferredSize: preferredSize,
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
color: CustomAppColors.kPrimaryColor,
|
|
boxShadow: showBoxShadow
|
|
? [
|
|
BoxShadow(
|
|
color: CustomAppColors.kLightGreyColor,
|
|
spreadRadius: 1.2,
|
|
blurRadius: 4,
|
|
offset: const Offset(0, 2),
|
|
),
|
|
]
|
|
: null,
|
|
),
|
|
width: MediaQuery.of(context).size.width,
|
|
alignment: Alignment.center,
|
|
padding: EdgeInsets.only(
|
|
top: GetPlatform.isIOS ? 40.0 : 20.0,
|
|
),
|
|
child: Stack(
|
|
children: [
|
|
Container(
|
|
width: MediaQuery.of(context).size.width,
|
|
padding: EdgeInsets.only(top: 4.sp, left: 20.0.sp, right: 20.sp),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Builder(builder: (context) {
|
|
if (titleWidget != null) {
|
|
return titleWidget!;
|
|
}
|
|
return FittedBox(
|
|
child: CustomTextWidget(
|
|
text: titleText,
|
|
fontColor: CustomAppColors.kIconColor,
|
|
fontSize: 22.0.sp,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
);
|
|
}),
|
|
],
|
|
),
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Visibility(
|
|
visible: canPop || leadingButton != null,
|
|
child: Padding(
|
|
padding: EdgeInsets.only(
|
|
left: 10.0.sp,
|
|
top: 32.0.sp,
|
|
),
|
|
child: leadingButton != null
|
|
? leadingButton!
|
|
: GestureDetector(
|
|
onTap: () {
|
|
if (onBackButtonPressed != null) {
|
|
onBackButtonPressed!();
|
|
} else {
|
|
Navigator.pop(context);
|
|
}
|
|
},
|
|
child: SizedBox(
|
|
width: 30.0,
|
|
height: 30.0,
|
|
child: Container(
|
|
padding: Platform.isIOS
|
|
? const EdgeInsets.symmetric(
|
|
horizontal: 10.0,
|
|
vertical: 5.0,
|
|
)
|
|
: null,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(4.sp),
|
|
color: CustomAppColors.kLightGreyColor,
|
|
),
|
|
alignment: Alignment.center,
|
|
child: Icon(
|
|
Icons.adaptive.arrow_back,
|
|
color: CustomAppColors.kIconColor,
|
|
size: 20.0,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const Spacer(),
|
|
Visibility(
|
|
visible: action != null,
|
|
child: Padding(
|
|
padding: EdgeInsets.only(
|
|
right: 15.0,
|
|
top: 25.0.sp,
|
|
),
|
|
child: action,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Size get preferredSize => const Size.fromHeight(56.0);
|
|
}
|