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.

78 lines
2.1 KiB

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