Untitled
unknown
plain_text
24 days ago
3.9 kB
2
Indexable
Never
import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:go_router/go_router.dart'; import 'package:networkon_flutter/method_channel_service/native_util_function/native_utils_function.dart'; import 'package:networkon_flutter/utils/extensions/extensions.dart'; import 'package:networkon_flutter/utils/theme/app_theme.dart'; import 'change_url_dialog_box.dart'; /* This class is used for the primary app bar widget */ class PrimaryAppBar extends StatefulWidget implements PreferredSizeWidget { /// Data field initialization final void Function()? onBackPress; final bool showBackButton, showWhiteColorAppBar; final List<Widget>? actionButton; final bool showProfileIcon; final Color? backgroundColor; final String title; final double? height; final bool toNative; int tapCount = 0; final SystemUiOverlayStyle? systemOverlayStyle; PrimaryAppBar({ super.key, this.onBackPress, this.showBackButton = true, this.actionButton, this.showProfileIcon = false, this.backgroundColor, this.systemOverlayStyle, this.showWhiteColorAppBar = false, required this.title, this.height, this.toNative = false }) : preferredSize = Size.fromHeight(height ?? kToolbarHeight); @override final Size preferredSize; @override State<PrimaryAppBar> createState() => _PrimaryAppBarState(); } class _PrimaryAppBarState extends State<PrimaryAppBar> { List<Widget>? addActions() { if (widget.actionButton != null) { return widget.actionButton; } List<Widget>? widgets = []; return widgets; } @override Widget build(BuildContext context) { int tapCount = 0; // Ensure this is declared in the appropriate scope return AppBar( scrolledUnderElevation: 0.0, actions: addActions(), backgroundColor: widget.backgroundColor, systemOverlayStyle: widget.systemOverlayStyle ?? SystemUiOverlayStyle( statusBarColor: appColor.colorPrimary, // Tested And Getting White Text in Brightness.dark statusBarIconBrightness: Platform.isAndroid ? widget.showWhiteColorAppBar ? Brightness.dark : Brightness.light : Brightness.dark, // For Android (dark icons) statusBarBrightness: Platform.isAndroid ? Brightness.light : Brightness.dark, ), automaticallyImplyLeading: widget.showProfileIcon == true ? true : widget.showBackButton, leading: showLeading(), centerTitle: true, elevation: 0, title: GestureDetector( onTap: () { setState(() { tapCount++; }); }, onLongPress: (tapCount != 5) ? null : () { if (tapCount == 5) { showDialog( context: context, barrierDismissible: true, builder: (context) { return const ChangeURLDialogBox(); }, ); } }, child: Text( widget.title, style: context.textTheme.bodyMedium?.copyWith( color: appColor.black, fontSize: 18.sp, ), ), ), ); } Widget? showLeading() { return widget.showBackButton ? IconButton( icon: const Icon( Icons.arrow_back, color: Colors.black, ), onPressed: widget.onBackPress ?? () { if(widget.toNative){ NativeUtilsFunction.popRoute(); return; } context.pop(); }, ) : null; } }
Leave a Comment