123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- import 'package:cs_resources/theme/app_colors_theme.dart';
- import 'package:cs_resources/theme/theme_config.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:flutter/widgets.dart';
- import 'package:cs_resources/constants/color_constants.dart';
- import 'package:router/ext/auto_router_extensions.dart';
- import 'my_load_image.dart';
- import 'search_app_bar.dart';
- class MyAppBar {
-
- static AppBar appBar(BuildContext context, String title,
- {void Function()? backCallback,
- Key? key,
- String? backIconPath,
- double? backIconWidth,
- double? backIconHeight,
- String? subTitle,
- Color backgroundColor = Colors.transparent,
- SystemUiOverlayStyle? systemUiOverlayStyle,
- bool showBottomDivider = false,
- bool showBackButton = true,
- List<Widget>? actions}) {
-
- final bool isDarkMode = Theme.of(context).brightness == Brightness.dark;
- return AppBar(
- key: key,
- backgroundColor: backgroundColor,
- surfaceTintColor: backgroundColor,
- systemOverlayStyle: systemUiOverlayStyle ?? ThemeConfig.getSystemUiOverlayStyleByTheme(context),
-
- leading: showBackButton
- ? (backIconPath != null
- ? IconButton(
- icon: MyAssetImage(
- backIconPath,
- width: backIconWidth ?? 11,
- height: backIconHeight ?? 18,
- ),
- onPressed: backCallback,
- )
- : null)
- : const SizedBox.shrink(),
- iconTheme: IconThemeData(color: isDarkMode ? Colors.white : Theme.of(context).colorScheme.primary),
- centerTitle: true,
- title: subTitle == null
- ? Text(
- title,
- style: TextStyle(color: isDarkMode ? Colors.white : Colors.black, fontSize: 17, fontWeight: FontWeight.w500),
- )
- : Column(
- mainAxisSize: MainAxisSize.max,
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- Text(
- title,
- style: TextStyle(color: isDarkMode ? Colors.white : Colors.black, fontSize: 17, fontWeight: FontWeight.w500),
- ),
- Text(
- subTitle,
- style: TextStyle(color: isDarkMode ? Colors.white : Colors.black, fontSize: 15, fontWeight: FontWeight.w400),
- )
- ],
- ),
- actions: actions,
- elevation: 0.0,
- bottom: showBottomDivider
- ? PreferredSize(
- preferredSize: const Size.fromHeight(0.5),
- child: Divider(
- height: 0.5,
- indent: 0.0,
- color: context.appColors.dividerDefault,
- ))
- : null,
- );
- }
-
- static AppBar searchAppBar(BuildContext context,
- {void Function()? backCallback,
- String? value,
- String? hintText,
- String? backIconPath,
- double? backIconWidth,
- double? backIconHeight,
- Color textColor = Colors.black,
- Color backgroundColor = Colors.transparent,
- ValueChanged<String>? onSearch,
- ValueChanged<String>? onChanged,
- SystemUiOverlayStyle? systemUiOverlayStyle,
- TextEditingController? controller,
- bool showBottomDivider = false,
- List<Widget>? actions}) {
-
- final bool isDarkMode = Theme.of(context).brightness == Brightness.dark;
- return AppBar(
- backgroundColor: backgroundColor,
- surfaceTintColor: backgroundColor,
- systemOverlayStyle: systemUiOverlayStyle ?? ThemeConfig.getSystemUiOverlayStyleByTheme(context),
-
- titleSpacing: 0,
-
- leading: backIconPath != null
- ? IconButton(
- icon: MyAssetImage(
- backIconPath,
- width: backIconWidth ?? 11,
- height: backIconHeight ?? 18,
- ),
- onPressed: backCallback,
- )
- : null,
- iconTheme: IconThemeData(color: isDarkMode ? Colors.white : Theme.of(context).colorScheme.primary),
- centerTitle: true,
- title: SearchAppBar(
- onSearch: onSearch,
- onChanged: onChanged,
- value: value,
- hintText: hintText,
- controller: controller,
- ),
- actions: actions,
- elevation: 0.0,
- bottom: showBottomDivider
- ? const PreferredSize(
- preferredSize: Size.fromHeight(0.5),
- child: Divider(
- height: 0.5,
- indent: 0.0,
- color: ColorConstants.dividerBar,
- ))
- : null,
- );
- }
-
- static Widget titleBar(
- BuildContext context,
- String title, {
- void Function()? backCallback,
- String? backIconPath,
- double? backIconWidth,
- double? backIconHeight,
- String? subTitle,
- Color backgroundColor = Colors.transparent,
- bool showBottomDivider = false,
- List<Widget>? actions,
- }) {
-
- double sideWidth = 55;
-
- final bool isDarkMode = Theme.of(context).brightness == Brightness.dark;
- return Column(
- children: [
- Container(
- height: kToolbarHeight,
- color: backgroundColor,
- child: Stack(
- children: [
-
- Positioned(
- left: 0,
- top: 0,
- bottom: 0,
- child: Container(
- width: sideWidth,
- alignment: Alignment.center,
- child: backIconPath != null
- ? IconButton(
- icon: MyAssetImage(
- backIconPath,
- width: backIconWidth ?? 11,
- height: backIconHeight ?? 18,
- ),
- onPressed: () {
- if (backCallback != null) {
- backCallback();
- } else {
- appRouter.maybePop();
- }
- },
- )
- : BackButton(
- color: isDarkMode ? Colors.white : Theme.of(context).colorScheme.primary,
- onPressed: () {
- if (backCallback != null) {
- backCallback();
- } else {
- appRouter.maybePop();
- }
- },
- ),
- ),
- ),
-
- Positioned.fill(
- child: Center(
- child: ConstrainedBox(
- constraints: BoxConstraints(
- maxWidth: MediaQuery.of(context).size.width - 2 * sideWidth,
- ),
- child: subTitle == null
- ? Text(
- title,
- style: TextStyle(color: isDarkMode ? Colors.white : Colors.black, fontSize: 17, fontWeight: FontWeight.w500),
- overflow: TextOverflow.ellipsis,
- )
- : Column(
- mainAxisSize: MainAxisSize.min,
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- Text(
- title,
- style: TextStyle(color: isDarkMode ? Colors.white : Colors.black, fontSize: 17, fontWeight: FontWeight.w500),
- overflow: TextOverflow.ellipsis,
- ),
- Text(
- subTitle,
- style: TextStyle(color: isDarkMode ? Colors.white : Colors.black, fontSize: 15, fontWeight: FontWeight.w400),
- ),
- ],
- ),
- ),
- ),
- ),
-
- Positioned(
- right: 0,
- top: 0,
- bottom: 0,
- child: Container(
- alignment: Alignment.centerRight,
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: actions ?? [SizedBox(width: sideWidth)],
- ),
- ),
- ),
- ],
- ),
- ),
-
- if (showBottomDivider)
- const Divider(
- height: 0.5,
- color: ColorConstants.dividerBar,
- ),
- ],
- );
- }
-
- static Widget searchTitleBar(
- BuildContext context, {
- void Function()? backCallback,
- String? value,
- String? hintText,
- String? backIconPath,
- double? backIconWidth,
- double? backIconHeight,
- Color backgroundColor = Colors.transparent,
- ValueChanged<String>? onSearch,
- ValueChanged<String>? onChanged,
- TextEditingController? controller,
- bool showBottomDivider = false,
- List<Widget>? actions,
- }) {
-
- final bool isDarkMode = Theme.of(context).brightness == Brightness.dark;
- return Column(
- children: [
- Container(
- height: kToolbarHeight,
- color: backgroundColor,
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
-
- Container(
- width: 55,
- alignment: Alignment.center,
- child: backIconPath != null
- ? IconButton(
- icon: MyAssetImage(
- backIconPath,
- width: backIconWidth ?? 11,
- height: backIconHeight ?? 18,
- ),
- onPressed: () {
- if (backCallback != null) {
- backCallback();
- } else {
- appRouter.maybePop();
- }
- },
- )
- : BackButton(
- color: isDarkMode ? Colors.white : Theme.of(context).colorScheme.primary,
- onPressed: () {
- if (backCallback != null) {
- backCallback();
- } else {
- appRouter.maybePop();
- }
- },
- ),
- ),
-
- Expanded(
- child: SearchAppBar(
- onSearch: onSearch,
- onChanged: onChanged,
- value: value,
- hintText: hintText,
- controller: controller,
- ),
- ),
-
- Container(
- alignment: Alignment.centerRight,
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: actions ?? [],
- ),
- ),
- ],
- ),
- ),
-
- if (showBottomDivider)
- const Divider(
- height: 0.5,
- indent: 0.0,
- color: ColorConstants.dividerBar,
- ),
- ],
- );
- }
- }
|