listcomment.dart 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // ignore_for_file: must_call_super, prefer_typing_uninitialized_variables, no_logic_in_create_state
  2. import 'package:dio/dio.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:namer_app/footer.dart';
  5. import 'package:namer_app/header.dart';
  6. import 'package:namer_app/service/delete_comment.dart';
  7. import '../globals.dart';
  8. class ListCommentPage extends StatefulWidget {
  9. final int bugId;
  10. const ListCommentPage({super.key, required this.bugId});
  11. @override
  12. State<ListCommentPage> createState() => _ListCommentPageState(
  13. bugId: bugId
  14. );
  15. }
  16. class _ListCommentPageState extends State<ListCommentPage> {
  17. int bugId;
  18. _ListCommentPageState({required this.bugId});
  19. var comments;
  20. @override
  21. void initState(){
  22. getData(bugId);
  23. }
  24. void getData(int bugId) async {
  25. try {
  26. var response = await Dio()
  27. .get('http://localhost:8080/api/v1/bugs/$bugId/comment',
  28. options: Options(headers: headers));
  29. if (response.statusCode == 200) {
  30. setState(() {
  31. comments = response.data['results'] as List;
  32. });
  33. print(comments);
  34. } else {
  35. print(response.statusCode);
  36. }
  37. } catch (e) {
  38. print(e);
  39. }
  40. }
  41. @override
  42. Widget build(BuildContext context) {
  43. return Scaffold(
  44. appBar: CustomAppbar(),
  45. body: Stack(children: [
  46. SingleChildScrollView(
  47. child: Column(
  48. children: [
  49. Center(
  50. child: Row(
  51. mainAxisAlignment: MainAxisAlignment.center,
  52. children: [
  53. Text(
  54. 'LIST COMMENT',
  55. style: TextStyle(color: Colors.black, fontSize: 48),
  56. ),
  57. ],
  58. )),
  59. Column(
  60. children: List.generate(
  61. comments == null ? 0 : comments.length,
  62. (i) => SizedBox(
  63. child: ListTile(
  64. leading: SizedBox(
  65. child: Icon(Icons.chat),
  66. ),
  67. title: Text(comments[i]['content']),
  68. subtitle: Column(
  69. crossAxisAlignment: CrossAxisAlignment.start,
  70. children: [
  71. Text(comments[i]['created']),
  72. Text(comments[i]['creator'])
  73. ],
  74. ),
  75. trailing: ButtonUser(
  76. items: comments[i],
  77. ),
  78. ),
  79. )),
  80. ),
  81. ],
  82. ),
  83. ),
  84. ]),
  85. bottomNavigationBar: Footer(),
  86. );
  87. }
  88. }
  89. class ButtonUser extends StatelessWidget {
  90. final Map<String, dynamic> items;
  91. ButtonUser({
  92. required this.items,
  93. super.key,
  94. });
  95. //todo tombol item
  96. //todo tombol delete
  97. @override
  98. Widget build(BuildContext context) {
  99. return Row(
  100. mainAxisSize: MainAxisSize.min,
  101. children: [
  102. ElevatedButton(
  103. onPressed: () => delcomment(context, items['id']),
  104. style: ElevatedButton.styleFrom(
  105. backgroundColor: Colors.black,
  106. ),
  107. child: Text(
  108. 'Delete',
  109. style: TextStyle(color: Colors.white),
  110. ),
  111. ),
  112. ],
  113. );
  114. }
  115. }