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.

88 lines
2.3 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. flexibleSpace: SafeArea(
  37. child: Container(
  38. padding: const EdgeInsets.only(right: 16),
  39. child: Row(
  40. children: <Widget>[
  41. showBack ?
  42. _backButton(context) :
  43. const SizedBox.shrink(),
  44. showBack ?
  45. const SizedBox(width: 2,) :
  46. const SizedBox(width: 15),
  47. Expanded(
  48. child: Column(
  49. crossAxisAlignment: CrossAxisAlignment.start,
  50. mainAxisAlignment: MainAxisAlignment.center,
  51. children: <Widget>[
  52. title,
  53. ],
  54. ),
  55. ),
  56. rightHandButton != null ?
  57. rightHandButton! :
  58. const SizedBox.shrink(),
  59. ],
  60. ),
  61. ),
  62. ),
  63. );
  64. }
  65. Widget _backButton(BuildContext context) {
  66. return IconButton(
  67. onPressed: () {
  68. if (beforeBack != null) {
  69. beforeBack!().then((dynamic) => Navigator.pop(context));
  70. return;
  71. }
  72. Navigator.pop(context);
  73. },
  74. icon: Icon(
  75. Icons.arrow_back,
  76. color: iconColor != null ?
  77. iconColor! :
  78. Theme.of(context).appBarTheme.iconTheme?.color,
  79. ),
  80. );
  81. }
  82. }