// ignore_for_file: prefer_typing_uninitialized_variables, must_call_super import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:namer_app/footer.dart'; import 'package:namer_app/header.dart'; import 'package:namer_app/service/delete_bug.dart'; import '../globals.dart'; class ListBugPage extends StatefulWidget { const ListBugPage({super.key}); @override State createState() => _ListBugPageState(); } class _ListBugPageState extends State { var jsonList; @override void initState(){ getData(); } void getData() async { try { var response = await Dio() .get('http://localhost:8080/api/v1/bugs', options: Options(headers: headers)); if (response.statusCode == 200) { setState(() { jsonList = response.data['results'] as List; }); } 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 BUG', style: TextStyle(color: Colors.black, fontSize: 48), ), ], )), Column( children: List.generate( jsonList == null ? 0 : jsonList.length, (i) => SizedBox( child: ListTile( leading: SizedBox( child: Icon(Icons.bug_report), ), title: Text(jsonList[i]['description']), subtitle: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(jsonList[i]['goodday_url']), Row( children: [ Text(jsonList[i]['created']), Container( width: 30, ), Text(jsonList[i]['level']), ], ), Row( children: [ Text(jsonList[i]['qc']), Container( width: 20, ), Text(jsonList[i]['status']), Container( width: 20, ), Text(jsonList[i]['dev']), Container( width: 20, ), Text(jsonList[i]['dev_status']) ], ) ], ), trailing: ButtonUser( items: jsonList[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: () => context.go('/login/bug/editbug'), style: ElevatedButton.styleFrom( backgroundColor: Colors.black, ), child: Text( 'Edit', style: TextStyle(color: Colors.white), ), ), ElevatedButton( onPressed: () => delbug(context, items['id']), style: ElevatedButton.styleFrom( backgroundColor: Colors.black, ), child: Text( 'Delete', style: TextStyle(color: Colors.white), ), ), ElevatedButton( onPressed: () => context.go('/addcomment'), style: ElevatedButton.styleFrom( backgroundColor: Colors.black, ), child: Text( 'Add Comment', style: TextStyle(color: Colors.white), ), ), ElevatedButton( onPressed: () => context.go('/login/bug/comment'), style: ElevatedButton.styleFrom( backgroundColor: Colors.black, ), child: Text( 'List Comment', style: TextStyle(color: Colors.white), ), ), ], ); } }