Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.4 KiB

  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. @immutable
  4. class CustomTitleBar extends StatelessWidget with PreferredSizeWidget {
  5. const CustomTitleBar({
  6. Key? key,
  7. required this.title,
  8. required this.showBack,
  9. this.rightHandButton,
  10. this.backgroundColor,
  11. this.forgroundColor,
  12. this.iconColor,
  13. this.beforeBack,
  14. }) : super(key: key);
  15. final Text title;
  16. final bool showBack;
  17. final IconButton? rightHandButton;
  18. final Color? backgroundColor;
  19. final Color? forgroundColor;
  20. final Color? iconColor;
  21. final Future<void> Function()? beforeBack;
  22. @override
  23. Size get preferredSize => const Size.fromHeight(kToolbarHeight);
  24. @override
  25. Widget build(BuildContext context) {
  26. return AppBar(
  27. elevation: 0,
  28. automaticallyImplyLeading: false,
  29. backgroundColor:
  30. backgroundColor != null ?
  31. backgroundColor! :
  32. Theme.of(context).appBarTheme.backgroundColor,
  33. foregroundColor: forgroundColor != null ?
  34. forgroundColor! :
  35. Theme.of(context).appBarTheme.foregroundColor,
  36. systemOverlayStyle: const SystemUiOverlayStyle(
  37. statusBarColor: Colors.white,
  38. ),
  39. flexibleSpace: SafeArea(
  40. child: Container(
  41. padding: const EdgeInsets.only(right: 16),
  42. child: Row(
  43. children: <Widget>[
  44. showBack ?
  45. _backButton(context) :
  46. const SizedBox.shrink(),
  47. showBack ?
  48. const SizedBox(width: 2,) :
  49. const SizedBox(width: 15),
  50. Expanded(
  51. child: Column(
  52. crossAxisAlignment: CrossAxisAlignment.start,
  53. mainAxisAlignment: MainAxisAlignment.center,
  54. children: <Widget>[
  55. title,
  56. ],
  57. ),
  58. ),
  59. rightHandButton != null ?
  60. rightHandButton! :
  61. const SizedBox.shrink(),
  62. ],
  63. ),
  64. ),
  65. ),
  66. );
  67. }
  68. Widget _backButton(BuildContext context) {
  69. return IconButton(
  70. onPressed: () {
  71. if (beforeBack != null) {
  72. beforeBack!().then((dynamic) => Navigator.pop(context));
  73. return;
  74. }
  75. Navigator.pop(context);
  76. },
  77. icon: Icon(
  78. Icons.arrow_back,
  79. color: iconColor != null ?
  80. iconColor! :
  81. Theme.of(context).appBarTheme.iconTheme?.color,
  82. ),
  83. );
  84. }
  85. }