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.

167 lines
5.2 KiB

2 years ago
  1. import 'package:flutter/material.dart';
  2. class HeaderWidget extends StatefulWidget {
  3. final double _height;
  4. final bool _showIcon;
  5. final IconData _icon;
  6. const HeaderWidget(this._height, this._showIcon, this._icon, {Key? key}) : super(key: key);
  7. @override
  8. _HeaderWidgetState createState() => _HeaderWidgetState(_height, _showIcon, _icon);
  9. }
  10. class _HeaderWidgetState extends State<HeaderWidget> {
  11. double _height;
  12. bool _showIcon;
  13. IconData _icon;
  14. _HeaderWidgetState(this._height, this._showIcon, this._icon);
  15. @override
  16. Widget build(BuildContext context) {
  17. double width = MediaQuery
  18. .of(context)
  19. .size
  20. .width;
  21. return Container(
  22. child: Stack(
  23. children: [
  24. ClipPath(
  25. child: Container(
  26. decoration: new BoxDecoration(
  27. gradient: new LinearGradient(
  28. colors: [
  29. Theme.of(context).primaryColor.withOpacity(0.4),
  30. Theme.of(context).accentColor.withOpacity(0.7),
  31. ],
  32. begin: const FractionalOffset(0.0, 0.0),
  33. end: const FractionalOffset(1.0, 0.0),
  34. stops: [0.0, 1.0],
  35. tileMode: TileMode.clamp
  36. ),
  37. ),
  38. ),
  39. clipper: new ShapeClipper(
  40. [
  41. Offset(width / 5, _height),
  42. Offset(width / 10 * 5, _height - 60),
  43. Offset(width / 5 * 4, _height + 20),
  44. Offset(width, _height - 18)
  45. ]
  46. ),
  47. ),
  48. ClipPath(
  49. child: Container(
  50. decoration: new BoxDecoration(
  51. gradient: new LinearGradient(
  52. colors: [
  53. Theme.of(context).primaryColor.withOpacity(0.4),
  54. Theme.of(context).accentColor.withOpacity(0.4),
  55. ],
  56. begin: const FractionalOffset(0.0, 0.0),
  57. end: const FractionalOffset(1.0, 0.0),
  58. stops: [0.0, 1.0],
  59. tileMode: TileMode.clamp
  60. ),
  61. ),
  62. ),
  63. clipper: new ShapeClipper(
  64. [
  65. Offset(width / 3, _height + 20),
  66. Offset(width / 10 * 8, _height - 60),
  67. Offset(width / 5 * 4, _height - 60),
  68. Offset(width, _height - 20)
  69. ]
  70. ),
  71. ),
  72. ClipPath(
  73. child: Container(
  74. decoration: new BoxDecoration(
  75. gradient: new LinearGradient(
  76. colors: [
  77. Theme.of(context).primaryColor,
  78. Theme.of(context).accentColor,
  79. ],
  80. begin: const FractionalOffset(0.0, 0.0),
  81. end: const FractionalOffset(1.0, 0.0),
  82. stops: [0.0, 1.0],
  83. tileMode: TileMode.clamp
  84. ),
  85. ),
  86. ),
  87. clipper: new ShapeClipper(
  88. [
  89. Offset(width / 5, _height),
  90. Offset(width / 2, _height - 40),
  91. Offset(width / 5 * 4, _height - 80),
  92. Offset(width, _height - 20)
  93. ]
  94. ),
  95. ),
  96. Visibility(
  97. visible: _showIcon,
  98. child: Container(
  99. height: _height - 40,
  100. child: Center(
  101. child: Container(
  102. margin: EdgeInsets.all(20),
  103. padding: EdgeInsets.only(
  104. left: 5.0,
  105. top: 20.0,
  106. right: 5.0,
  107. bottom: 20.0,
  108. ),
  109. decoration: BoxDecoration(
  110. // borderRadius: BorderRadius.circular(20),
  111. borderRadius: BorderRadius.only(
  112. topLeft: Radius.circular(100),
  113. topRight: Radius.circular(100),
  114. bottomLeft: Radius.circular(60),
  115. bottomRight: Radius.circular(60),
  116. ),
  117. border: Border.all(width: 5, color: Colors.white),
  118. ),
  119. child: Icon(
  120. _icon,
  121. color: Colors.white,
  122. size: 40.0,
  123. ),
  124. ),
  125. ),
  126. ),
  127. ),
  128. ],
  129. ),
  130. );
  131. }
  132. }
  133. class ShapeClipper extends CustomClipper<Path> {
  134. List<Offset> _offsets = [];
  135. ShapeClipper(this._offsets);
  136. @override
  137. Path getClip(Size size) {
  138. var path = new Path();
  139. path.lineTo(0.0, size.height-20);
  140. // path.quadraticBezierTo(size.width/5, size.height, size.width/2, size.height-40);
  141. // path.quadraticBezierTo(size.width/5*4, size.height-80, size.width, size.height-20);
  142. path.quadraticBezierTo(_offsets[0].dx, _offsets[0].dy, _offsets[1].dx,_offsets[1].dy);
  143. path.quadraticBezierTo(_offsets[2].dx, _offsets[2].dy, _offsets[3].dx,_offsets[3].dy);
  144. // path.lineTo(size.width, size.height-20);
  145. path.lineTo(size.width, 0.0);
  146. path.close();
  147. return path;
  148. }
  149. @override
  150. bool shouldReclip(CustomClipper<Path> oldClipper) => false;
  151. }