listcomment.dart 3.3 KB

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