notification_widget.dart 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import 'package:flutter/material.dart';
  2. import "package:photos/ente_theme_data.dart";
  3. import 'package:photos/theme/colors.dart';
  4. import "package:photos/theme/ente_theme.dart";
  5. import 'package:photos/theme/text_style.dart';
  6. import 'package:photos/ui/components/buttons/icon_button_widget.dart';
  7. // CreateNotificationType enum
  8. enum NotificationType {
  9. warning,
  10. banner,
  11. goldenBanner,
  12. notice,
  13. }
  14. class NotificationWidget extends StatelessWidget {
  15. final IconData startIcon;
  16. final IconData actionIcon;
  17. final String text;
  18. final String? subText;
  19. final GestureTapCallback onTap;
  20. final NotificationType type;
  21. const NotificationWidget({
  22. Key? key,
  23. required this.startIcon,
  24. required this.actionIcon,
  25. required this.text,
  26. required this.onTap,
  27. this.subText,
  28. this.type = NotificationType.warning,
  29. }) : super(key: key);
  30. @override
  31. Widget build(BuildContext context) {
  32. EnteColorScheme colorScheme = getEnteColorScheme(context);
  33. EnteTextTheme textTheme = getEnteTextTheme(context);
  34. TextStyle mainTextStyle = darkTextTheme.bodyBold;
  35. TextStyle subTextStyle = darkTextTheme.miniMuted;
  36. LinearGradient? backgroundGradient;
  37. Color? backgroundColor;
  38. EnteColorScheme strokeColorScheme = darkScheme;
  39. List<BoxShadow>? boxShadow;
  40. switch (type) {
  41. case NotificationType.warning:
  42. backgroundColor = warning500;
  43. break;
  44. case NotificationType.banner:
  45. colorScheme = getEnteColorScheme(context);
  46. textTheme = getEnteTextTheme(context);
  47. backgroundColor = colorScheme.backgroundElevated2;
  48. mainTextStyle = textTheme.bodyBold;
  49. subTextStyle = textTheme.miniMuted;
  50. strokeColorScheme = colorScheme;
  51. boxShadow = [
  52. BoxShadow(color: Colors.black.withOpacity(0.25), blurRadius: 1),
  53. ];
  54. break;
  55. case NotificationType.goldenBanner:
  56. backgroundGradient = LinearGradient(
  57. colors: [colorScheme.golden700, colorScheme.golden500],
  58. stops: const [0.25, 1],
  59. begin: Alignment.bottomCenter,
  60. end: Alignment.topCenter,
  61. );
  62. boxShadow = Theme.of(context).colorScheme.enteTheme.shadowMenu;
  63. break;
  64. case NotificationType.notice:
  65. backgroundColor = colorScheme.backgroundElevated2;
  66. mainTextStyle = textTheme.bodyBold;
  67. subTextStyle = textTheme.miniMuted;
  68. strokeColorScheme = colorScheme;
  69. boxShadow = Theme.of(context).colorScheme.enteTheme.shadowMenu;
  70. break;
  71. }
  72. return Center(
  73. child: GestureDetector(
  74. onTap: onTap,
  75. child: Container(
  76. decoration: BoxDecoration(
  77. borderRadius: const BorderRadius.all(
  78. Radius.circular(8),
  79. ),
  80. boxShadow: boxShadow,
  81. color: backgroundColor,
  82. gradient: backgroundGradient,
  83. ),
  84. child: Padding(
  85. padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
  86. child: Row(
  87. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  88. children: [
  89. Icon(
  90. startIcon,
  91. size: 36,
  92. color: strokeColorScheme.strokeBase,
  93. ),
  94. const SizedBox(width: 12),
  95. Expanded(
  96. child: Column(
  97. crossAxisAlignment: CrossAxisAlignment.start,
  98. children: [
  99. Text(
  100. text,
  101. style: mainTextStyle,
  102. textAlign: TextAlign.left,
  103. ),
  104. subText != null
  105. ? Text(
  106. subText!,
  107. style: subTextStyle,
  108. )
  109. : const SizedBox.shrink(),
  110. ],
  111. ),
  112. ),
  113. const SizedBox(width: 12),
  114. IconButtonWidget(
  115. icon: actionIcon,
  116. iconButtonType: IconButtonType.rounded,
  117. iconColor: strokeColorScheme.strokeBase,
  118. defaultColor: strokeColorScheme.fillFaint,
  119. pressedColor: strokeColorScheme.fillMuted,
  120. onTap: onTap,
  121. ),
  122. ],
  123. ),
  124. ),
  125. ),
  126. ),
  127. );
  128. }
  129. }