uaestats_fe/lib/presentation/components/themed_app_bar.dart
2026-05-16 11:31:32 +05:30

128 lines
3.7 KiB
Dart
Executable File

import 'package:external_repos/external_repos.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:uae_stat/config/my_theme.dart';
import 'package:uae_stat/domain/use_cases/language.dart';
import 'package:uae_stat/infrastructure/services/img_asset_paths/icons/misc_icon_asset_path.dart';
import 'package:uae_stat/infrastructure/services/img_asset_paths/logo_asset_path.dart';
import 'package:uae_stat/presentation/components/lang_toggle.dart';
import 'package:uae_stat/presentation/components/space.dart';
class ThemedAppBar extends ConsumerWidget {
const ThemedAppBar({
this.searchController,
this.titleText,
this.foreGroundColor,
this.searchHintText,
super.key,
});
final String? titleText;
final TextEditingController? searchController;
final Color? foreGroundColor;
final String? searchHintText;
@override
Widget build(BuildContext context, ref) {
final showBackButton =
GoRouterState.of(context).fullPath!.split('/').length > 3;
final backBtn = showBackButton
? InkWell(
onTap: context.pop,
borderRadius: BorderRadius.circular(100),
child: Padding(
padding: const EdgeInsetsDirectional.only(
start: 12,
end: 3,
),
child: Image.asset(
MiscIconAssetPath.back,
height: 32,
color: foreGroundColor ?? const Color(0xff414042),
),
),
)
: null;
final drawerBtn = InkWell(
onTap: () {
Scaffold.of(context).openDrawer();
},
borderRadius: BorderRadius.circular(100),
child: Padding(
padding: EdgeInsetsDirectional.only(
start: backBtn == null ? 12 : 3,
),
child: Image.asset(
MiscIconAssetPath.menu,
height: 22,
color: foreGroundColor ?? const Color(0xff414042),
),
),
);
final logo = Image.asset(
LogoAssetPath.uaeStatLight,
height: 36,
);
final title = titleText == null
? null
: Text(
titleText!,
style: TextStyle(
fontFamily: context.translate(
'Roboto',
'NotoKufi',
),
fontSize: 20,
fontWeight: FontWeight.w500,
color: foreGroundColor ?? const Color(0xff414042),
),
);
final upperBody = Stack(
alignment: Alignment.center,
children: [
if (title == null) logo,
Row(
children: [
6.horizontalSpace,
if (backBtn != null) backBtn,
drawerBtn,
12.horizontalSpace,
title == null ? const Spacer() : Expanded(child: title),
5.horizontalSpace,
const LangToggle(),
13.horizontalSpace,
],
),
],
);
final searchField = CupertinoSearchTextField(
controller: searchController,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: MyTheme.topicColor(IndicatorTopic.social).shade300,
),
borderRadius: BorderRadius.circular(100),
),
);
final body = Column(
children: [
18.verticalSpace,
upperBody,
12.verticalSpace,
if (searchController != null) ...[
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: searchField,
),
12.verticalSpace,
],
],
);
return body;
}
}