// ignore_for_file: must_call_super, prefer_typing_uninitialized_variables, no_logic_in_create_state import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:namer_app/footer.dart'; import 'package:namer_app/header.dart'; import 'package:namer_app/service/delete_comment.dart'; import '../globals.dart'; class ListCommentPage extends StatefulWidget { final int bugId; const ListCommentPage({super.key, required this.bugId}); @override State createState() => _ListCommentPageState( bugId: bugId ); } class _ListCommentPageState extends State { int bugId; _ListCommentPageState({required this.bugId}); var comments; @override void initState(){ getData(bugId); } void getData(int bugId) async { try { var response = await Dio() .get('http://localhost:8080/api/v1/bugs/$bugId/comment', options: Options(headers: headers)); if (response.statusCode == 200) { setState(() { comments = response.data['results'] as List; }); print(comments); } else { print(response.statusCode); } } catch (e) { print(e); } } @override Widget build(BuildContext context) { return Scaffold( appBar: CustomAppbar(), body: Stack(children: [ SingleChildScrollView( child: Column( children: [ Center( child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( 'LIST COMMENT', style: TextStyle(color: Colors.black, fontSize: 48), ), ], )), Column( children: List.generate( comments == null ? 0 : comments.length, (i) => SizedBox( child: ListTile( leading: SizedBox( child: Icon(Icons.chat), ), title: Text(comments[i]['content']), subtitle: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(comments[i]['created']), Text(comments[i]['creator']) ], ), trailing: ButtonUser( items: comments[i], ), ), )), ), ], ), ), ]), bottomNavigationBar: Footer(), ); } } class ButtonUser extends StatelessWidget { final Map items; ButtonUser({ required this.items, super.key, }); //todo tombol item //todo tombol delete @override Widget build(BuildContext context) { return Row( mainAxisSize: MainAxisSize.min, children: [ ElevatedButton( onPressed: () => delcomment(context, items['id']), style: ElevatedButton.styleFrom( backgroundColor: Colors.black, ), child: Text( 'Delete', style: TextStyle(color: Colors.white), ), ), ], ); } }