Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:flutter_svg/svg.dart';
- import 'package:investorv2/provider/notification_provider.dart';
- import 'package:investorv2/singleton/shared_pref.dart';
- import 'package:investorv2/utility/colors.dart';
- import 'package:investorv2/utility/routes.dart';
- import 'package:investorv2/utility/valueStrings.dart';
- import 'package:provider/provider.dart';
- class CustomAppBar extends StatefulWidget {
- final String title;
- final Color color;
- final Function() onTap;
- final bool notificationIcon;
- final bool menuIcon;
- const CustomAppBar({
- super.key,
- required this.title,
- required this.color,
- required this.onTap,
- this.notificationIcon = false,
- this.menuIcon = false,
- });
- @override
- _CustomAppBarState createState() => _CustomAppBarState();
- }
- class _CustomAppBarState extends State<CustomAppBar> {
- String logged = '';
- @override
- void initState() {
- logged = SharedPref.getString(token);
- if (widget.notificationIcon) {
- context.read<NotificationProvider>().unreadNotification = null;
- context.read<NotificationProvider>().checkUnreadNotification();
- }
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return PreferredSize(
- preferredSize:
- const Size.fromHeight(kToolbarHeight), // Set the preferred height
- child: AppBar(
- title: Text(
- widget.title,
- style: widget.color == ProjectColors.primaryColor
- ? Theme.of(context)
- .appBarTheme
- .titleTextStyle!
- .merge(TextStyle(fontWeight: FontWeight.bold, fontSize: 18))
- : Theme.of(context).appBarTheme.titleTextStyle!.merge(TextStyle(
- color: ProjectColors.black,
- fontWeight: FontWeight.bold,
- fontSize: 18)),
- ),
- centerTitle: true,
- backgroundColor: widget.color,
- leading: widget.menuIcon
- ? Padding(
- padding: const EdgeInsets.only(left: 8.0),
- child: IconButton(
- color: Colors.black,
- icon: SvgPicture.asset(
- "assets/images/hamburger.svg",
- colorFilter: const ColorFilter.mode(
- ProjectColors.black, BlendMode.srcIn),
- height: 36,
- width: 36,
- ),
- onPressed: widget.onTap),
- )
- : IconButton(
- icon: Icon(
- Icons.arrow_back,
- color: widget.color == ProjectColors.primaryColor
- ? Colors.white
- : ProjectColors.black,
- size: 28,
- ),
- iconSize: 40,
- onPressed: widget.onTap,
- ),
- actions: [
- widget.notificationIcon && logged.isNotEmpty
- ? Padding(
- padding: const EdgeInsets.only(right: 24.0),
- child: GestureDetector(
- onTap: () {
- Navigator.pushNamed(context, notificationPage,
- arguments: {});
- },
- child: Stack(alignment: Alignment.topRight, children: [
- Icon(Icons.notifications),
- showIcon(context)
- ]),
- ),
- )
- : Container(),
- ],
- ),
- );
- }
- Widget showIcon(BuildContext context) {
- final unreadNotification =
- context.watch<NotificationProvider>().unreadNotification;
- if (unreadNotification == null ||
- unreadNotification.notificationsUnread == null) {
- return const SizedBox
- .shrink(); // Return an empty widget if unreadNotification is null
- }
- return Visibility(
- visible: unreadNotification.notificationsUnread!,
- child: Positioned(
- child: Container(
- padding: EdgeInsets.all(2),
- decoration: BoxDecoration(
- color: Colors.red,
- shape: BoxShape.circle,
- ),
- constraints: BoxConstraints(
- minWidth: 13,
- minHeight: 13,
- ),
- child: Text(
- '',
- style: TextStyle(
- color: Colors.white,
- fontSize: 8,
- ),
- textAlign: TextAlign.center,
- ),
- ),
- ),
- );
- }
- }
- // use it by
- Scaffold(
- appBar: PreferredSize(
- preferredSize: const Size.fromHeight(kToolbarHeight), // Set
- child: CustomAppBar(
- title: args["tittle"],
- color: Colors.white,
- onTap: () {
- Navigator.of(context).pop();
- },
- ),
- ),
- body: YoutubePlayerBuilder(
- player: YoutubePlayer(controller: _controller),
- builder: (context, player) {
- return Column(children: [player]);
- },
- ),
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement