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.

72 lines
1.9 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. }) : super(key: key);
  11. final Text title;
  12. final bool showBack;
  13. final IconButton? rightHandButton;
  14. final Color? backgroundColor;
  15. @override
  16. Size get preferredSize => const Size.fromHeight(kToolbarHeight);
  17. @override
  18. Widget build(BuildContext context) {
  19. return AppBar(
  20. elevation: 0,
  21. automaticallyImplyLeading: false,
  22. backgroundColor:
  23. backgroundColor != null ?
  24. backgroundColor! :
  25. Theme.of(context).appBarTheme.backgroundColor,
  26. flexibleSpace: SafeArea(
  27. child: Container(
  28. padding: const EdgeInsets.only(right: 16),
  29. child: Row(
  30. children: <Widget>[
  31. showBack ?
  32. _backButton(context) :
  33. const SizedBox.shrink(),
  34. showBack ?
  35. const SizedBox(width: 2,) :
  36. const SizedBox(width: 15),
  37. Expanded(
  38. child: Column(
  39. crossAxisAlignment: CrossAxisAlignment.start,
  40. mainAxisAlignment: MainAxisAlignment.center,
  41. children: <Widget>[
  42. title,
  43. ],
  44. ),
  45. ),
  46. rightHandButton != null ?
  47. rightHandButton! :
  48. const SizedBox.shrink(),
  49. ],
  50. ),
  51. ),
  52. ),
  53. );
  54. }
  55. Widget _backButton(BuildContext context) {
  56. return IconButton(
  57. onPressed: (){
  58. Navigator.pop(context);
  59. },
  60. icon: Icon(
  61. Icons.arrow_back,
  62. color: Theme.of(context).appBarTheme.iconTheme?.color,
  63. ),
  64. );
  65. }
  66. }