header.dart 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. import 'package:dropdown_button2/dropdown_button2.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:go_router/go_router.dart';
  4. class CustomAppbar extends StatefulWidget implements PreferredSizeWidget {
  5. final bool? isBack;
  6. final TextEditingController? controller;
  7. const CustomAppbar({super.key, this.isBack, this.controller});
  8. @override
  9. State<CustomAppbar> createState() => _CustomAppbarState();
  10. @override
  11. Size get preferredSize => Size(15, 50);
  12. }
  13. class _CustomAppbarState extends State<CustomAppbar> {
  14. @override
  15. Widget build(BuildContext context) {
  16. return AppBar(
  17. backgroundColor: Colors.white,
  18. leading: Icon(Icons.bug_report),
  19. titleSpacing: 0,
  20. title: Text(
  21. 'Bug Listing',
  22. style: TextStyle(fontSize: 28, fontWeight: FontWeight.w500),
  23. ),
  24. actions: [
  25. Padding(
  26. padding: const EdgeInsets.symmetric(horizontal: 8.0),
  27. child: DropdownButtonHideUnderline(
  28. child: DropdownButton2(
  29. items: [
  30. DropdownMenuItem(
  31. child: Text('Home'),
  32. )
  33. ],
  34. onChanged: (value) => context.go('/'),
  35. ),
  36. ),
  37. ),
  38. Padding(
  39. padding: const EdgeInsets.symmetric(horizontal: 8.0),
  40. child: DropdownButtonHideUnderline(
  41. child: DropdownButton2(
  42. customButton: Text(
  43. 'Bug',
  44. style: TextStyle(fontSize: 15),
  45. ),
  46. items: [
  47. ...MenuItems2.firstItems.map(
  48. (item) => DropdownMenuItem<MenuItem>(
  49. value: item,
  50. child: MenuItems2.buildItem(item),
  51. ),
  52. ),
  53. ],
  54. onChanged: (value) {
  55. MenuItems2.onChanged(context, value!);
  56. },
  57. dropdownStyleData: DropdownStyleData(
  58. width: 150,
  59. padding: const EdgeInsets.symmetric(vertical: 6),
  60. decoration: BoxDecoration(
  61. borderRadius: BorderRadius.circular(4),
  62. ),
  63. offset: const Offset(0, 8),
  64. ),
  65. menuItemStyleData: MenuItemStyleData(
  66. customHeights: [
  67. ...List<double>.filled(MenuItems2.firstItems.length, 48),
  68. ],
  69. padding: const EdgeInsets.only(left: 16, right: 16),
  70. ),
  71. ),
  72. ),
  73. ),
  74. Padding(
  75. padding: const EdgeInsets.symmetric(horizontal: 8.0),
  76. child: DropdownButtonHideUnderline(
  77. child: DropdownButton2(
  78. customButton: Text(
  79. 'Platform',
  80. style: TextStyle(fontSize: 15),
  81. ),
  82. items: [
  83. ...MenuItems.firstItems.map(
  84. (item) => DropdownMenuItem<MenuItem>(
  85. value: item,
  86. child: MenuItems.buildItem(item),
  87. ),
  88. ),
  89. ],
  90. onChanged: (value) {
  91. MenuItems.onChanged(context, value!);
  92. },
  93. dropdownStyleData: DropdownStyleData(
  94. width: 150,
  95. padding: const EdgeInsets.symmetric(vertical: 6),
  96. decoration: BoxDecoration(
  97. borderRadius: BorderRadius.circular(4),
  98. ),
  99. offset: const Offset(0, 8),
  100. ),
  101. menuItemStyleData: MenuItemStyleData(
  102. customHeights: [
  103. ...List<double>.filled(MenuItems.firstItems.length, 48),
  104. ],
  105. padding: const EdgeInsets.only(left: 16, right: 16),
  106. ),
  107. ),
  108. ),
  109. ),
  110. Padding(
  111. padding: const EdgeInsets.symmetric(horizontal: 8),
  112. child: DropdownButtonHideUnderline(
  113. child: DropdownButton2(
  114. items: [
  115. DropdownMenuItem(
  116. child: Text('Maintenance'),
  117. )
  118. ],
  119. onChanged: (value) => context.go('/maintenance'),
  120. ),
  121. ),
  122. ),
  123. Padding(
  124. padding: const EdgeInsets.symmetric(horizontal: 6),
  125. child: DropdownButtonHideUnderline(
  126. child: DropdownButton2(
  127. items: [
  128. DropdownMenuItem(
  129. child: Text('Log Out'),
  130. )
  131. ],
  132. onChanged: null,
  133. ),
  134. ),
  135. ),
  136. ],
  137. );
  138. }
  139. }
  140. class MenuItem {
  141. const MenuItem({
  142. required this.text,
  143. });
  144. final String text;
  145. }
  146. abstract class MenuItems {
  147. static const List<MenuItem> firstItems = [add, edit, list];
  148. static const add = MenuItem(text: 'Add Platform');
  149. static const edit = MenuItem(text: 'Edit Platform');
  150. static const list = MenuItem(text: 'List Platform');
  151. static Widget buildItem(MenuItem item) {
  152. return Row(
  153. children: [
  154. Expanded(
  155. child: Text(
  156. item.text,
  157. style: const TextStyle(
  158. color: Colors.black,
  159. ),
  160. ),
  161. ),
  162. ],
  163. );
  164. }
  165. static void onChanged(BuildContext context, MenuItem item) {
  166. switch (item) {
  167. case MenuItems.add:
  168. context.go('/addplatform');
  169. break;
  170. case MenuItems.edit:
  171. context.go('/listplatform/editplatform');
  172. break;
  173. case MenuItems.list:
  174. context.go('/listplatform');
  175. break;
  176. }
  177. }
  178. }
  179. abstract class MenuItems2 {
  180. static const List<MenuItem> firstItems = [add, edit, list];
  181. static const add = MenuItem(text: 'Add Bug');
  182. static const edit = MenuItem(text: 'Edit Bug');
  183. static const list = MenuItem(text: 'List Bug');
  184. static Widget buildItem(MenuItem item) {
  185. return Row(
  186. children: [
  187. Expanded(
  188. child: Text(
  189. item.text,
  190. style: const TextStyle(
  191. color: Colors.black,
  192. ),
  193. ),
  194. ),
  195. ],
  196. );
  197. }
  198. static void onChanged(BuildContext context, MenuItem item) {
  199. switch (item) {
  200. case MenuItems2.add:
  201. context.go('/addbug');
  202. break;
  203. case MenuItems2.edit:
  204. context.go('/login/bug/editbug');
  205. break;
  206. case MenuItems2.list:
  207. context.go('/login/bug');
  208. break;
  209. }
  210. }
  211. }
  212. // class Header extends StatelessWidget implements PreferredSizeWidget {
  213. // final Text title;
  214. // final AppBar appBar;
  215. // final List<Widget> widgets;
  216. // const Header(
  217. // {super.key,
  218. // required this.title,
  219. // required this.appBar,
  220. // required this.widgets});
  221. // @override
  222. // Widget build(BuildContext context) {
  223. // return AppBar(
  224. // backgroundColor: Colors.white,
  225. // leading: Icon(Icons.bug_report),
  226. // titleSpacing: 0,
  227. // title: Text(
  228. // 'Bug Listing',
  229. // style: TextStyle(fontSize: 28, fontWeight: FontWeight.w500),
  230. // ),
  231. // actions: [
  232. // //todo hide kalo non login
  233. // ElevatedButton(
  234. // onPressed: () => context.go('/'),
  235. // style: ElevatedButton.styleFrom(surfaceTintColor: Colors.white),
  236. // child: Text(
  237. // 'Home',
  238. // style: TextStyle(color: Colors.black),
  239. // )),
  240. // ElevatedButton(
  241. // onPressed: () => context.go('/listplatform'),
  242. // style: ElevatedButton.styleFrom(surfaceTintColor: Colors.white),
  243. // child: Text(
  244. // 'Platform',
  245. // style: TextStyle(color: Colors.black),
  246. // ),
  247. // ),
  248. // ElevatedButton(
  249. // onPressed: () => context.go('/maintenance'),
  250. // style: ElevatedButton.styleFrom(surfaceTintColor: Colors.white),
  251. // child: Text(
  252. // 'Maintenance',
  253. // style: TextStyle(color: Colors.black),
  254. // ),
  255. // ),
  256. // Text('Log Out'),
  257. // ],
  258. // );
  259. // }
  260. // @override
  261. // Size get preferredSize => Size.fromHeight(appBar.preferredSize.height);
  262. // }