listmember.dart 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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_member.dart';
  7. import '../globals.dart';
  8. class ListMemberPage extends StatefulWidget {
  9. final int projId;
  10. const ListMemberPage({super.key, required this.projId});
  11. @override
  12. State<ListMemberPage> createState() => _ListMemberPageState(
  13. bugId: projId
  14. );
  15. }
  16. class _ListMemberPageState extends State<ListMemberPage> {
  17. int bugId;
  18. _ListMemberPageState({required this.bugId});
  19. var members;
  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/projects/$bugId/member',
  28. options: Options(headers: headers));
  29. if (response.statusCode == 200) {
  30. setState(() {
  31. members = response.data['results'] as List;
  32. });
  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 MEMBER',
  54. style: TextStyle(color: Colors.black, fontSize: 48),
  55. ),
  56. ],
  57. )),
  58. Column(
  59. children: List.generate(
  60. members == null ? 0 : members.length,
  61. (i) => SizedBox(
  62. child: ListTile(
  63. leading: SizedBox(
  64. child: Icon(Icons.group_work),
  65. ),
  66. title: Text(members[i]['project']),
  67. subtitle: Column(
  68. crossAxisAlignment: CrossAxisAlignment.start,
  69. children: [
  70. Row(
  71. children: [
  72. Text(members[i]['user']),
  73. Expanded(child: Container()),
  74. Text(members[i]['role'])
  75. ],
  76. ),
  77. ],
  78. ),
  79. trailing: ButtonUser(
  80. items: members[i],
  81. ),
  82. ),
  83. )),
  84. ),
  85. ],
  86. ),
  87. ),
  88. ]),
  89. bottomNavigationBar: Footer(),
  90. );
  91. }
  92. }
  93. class ButtonUser extends StatelessWidget {
  94. final Map<String, dynamic> items;
  95. ButtonUser({
  96. required this.items,
  97. super.key,
  98. });
  99. //todo delete
  100. //todo tombol item
  101. @override
  102. Widget build(BuildContext context) {
  103. return Row(
  104. // crossAxisAlignment: CrossAxisAlignment.center,
  105. mainAxisSize: MainAxisSize.min,
  106. children: [
  107. ElevatedButton(
  108. onPressed: () => delmember(context, items['id']),
  109. style: ElevatedButton.styleFrom(
  110. backgroundColor: Colors.black,
  111. ),
  112. child: Text(
  113. 'Delete',
  114. style: TextStyle(color: Colors.white),
  115. ),
  116. ),
  117. ],
  118. );
  119. }
  120. }