listbug.dart 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. // ignore_for_file: prefer_typing_uninitialized_variables, must_call_super
  2. import 'package:dio/dio.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:go_router/go_router.dart';
  5. import 'package:namer_app/footer.dart';
  6. import 'package:namer_app/header.dart';
  7. import 'package:namer_app/service/delete_bug.dart';
  8. import '../globals.dart';
  9. class ListBugPage extends StatefulWidget {
  10. const ListBugPage({super.key});
  11. @override
  12. State<ListBugPage> createState() => _ListBugPageState();
  13. }
  14. class _ListBugPageState extends State<ListBugPage> {
  15. var jsonList;
  16. @override
  17. void initState(){
  18. getData();
  19. }
  20. void getData() async {
  21. try {
  22. var response = await Dio()
  23. .get('http://localhost:8080/api/v1/bugs',
  24. options: Options(headers: headers));
  25. if (response.statusCode == 200) {
  26. setState(() {
  27. jsonList = response.data['results'] as List;
  28. });
  29. } else {
  30. print(response.statusCode);
  31. }
  32. } catch (e) {
  33. print(e);
  34. }
  35. }
  36. @override
  37. Widget build(BuildContext context) {
  38. return Scaffold(
  39. appBar: CustomAppbar(),
  40. body: Stack(children: [
  41. SingleChildScrollView(
  42. child: Column(
  43. children: [
  44. Center(
  45. child: Row(
  46. mainAxisAlignment: MainAxisAlignment.center,
  47. children: [
  48. Text(
  49. 'LIST BUG',
  50. style: TextStyle(color: Colors.black, fontSize: 48),
  51. ),
  52. ],
  53. )),
  54. Column(
  55. children: List.generate(
  56. jsonList == null ? 0 : jsonList.length,
  57. (i) => SizedBox(
  58. child: ListTile(
  59. leading: SizedBox(
  60. child: Icon(Icons.bug_report),
  61. ),
  62. title: Text(jsonList[i]['description']),
  63. subtitle: Column(
  64. crossAxisAlignment: CrossAxisAlignment.start,
  65. children: [
  66. Text(jsonList[i]['goodday_url']),
  67. Row(
  68. children: [
  69. Text(jsonList[i]['created']),
  70. Container(
  71. width: 30,
  72. ),
  73. Text(jsonList[i]['level']),
  74. ],
  75. ),
  76. Row(
  77. children: [
  78. Text(jsonList[i]['qc']),
  79. Container(
  80. width: 20,
  81. ),
  82. Text(jsonList[i]['status']),
  83. Container(
  84. width: 20,
  85. ),
  86. Text(jsonList[i]['dev']),
  87. Container(
  88. width: 20,
  89. ),
  90. Text(jsonList[i]['dev_status'])
  91. ],
  92. )
  93. ],
  94. ),
  95. trailing: ButtonUser(
  96. items: jsonList[i],
  97. ),
  98. ),
  99. )),
  100. ),
  101. ],
  102. ),
  103. ),
  104. ]),
  105. bottomNavigationBar: Footer(),
  106. );
  107. }
  108. }
  109. class ButtonUser extends StatelessWidget {
  110. final Map<String, dynamic> items;
  111. ButtonUser({
  112. required this.items,
  113. super.key,
  114. });
  115. //todo tombol item
  116. //todo tombol delete
  117. @override
  118. Widget build(BuildContext context) {
  119. return Row(
  120. mainAxisSize: MainAxisSize.min,
  121. children: [
  122. ElevatedButton(
  123. onPressed: () => context.go('/login/bug/editbug'),
  124. style: ElevatedButton.styleFrom(
  125. backgroundColor: Colors.black,
  126. ),
  127. child: Text(
  128. 'Edit',
  129. style: TextStyle(color: Colors.white),
  130. ),
  131. ),
  132. ElevatedButton(
  133. onPressed: () => delbug(context, items['id']),
  134. style: ElevatedButton.styleFrom(
  135. backgroundColor: Colors.black,
  136. ),
  137. child: Text(
  138. 'Delete',
  139. style: TextStyle(color: Colors.white),
  140. ),
  141. ),
  142. ElevatedButton(
  143. onPressed: () => context.go('/addcomment'),
  144. style: ElevatedButton.styleFrom(
  145. backgroundColor: Colors.black,
  146. ),
  147. child: Text(
  148. 'Add Comment',
  149. style: TextStyle(color: Colors.white),
  150. ),
  151. ),
  152. ElevatedButton(
  153. onPressed: () => context.go('/login/bug/comment'),
  154. style: ElevatedButton.styleFrom(
  155. backgroundColor: Colors.black,
  156. ),
  157. child: Text(
  158. 'List Comment',
  159. style: TextStyle(color: Colors.white),
  160. ),
  161. ),
  162. ],
  163. );
  164. }
  165. }