listproject.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // ignore_for_file: must_call_super, prefer_typing_uninitialized_variables
  2. import 'package:dio/dio.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:go_router/go_router.dart';
  5. import 'package:namer_app/footer.dart';
  6. import 'package:namer_app/header.dart';
  7. import 'package:namer_app/service/delete_project.dart';
  8. import '../globals.dart';
  9. class ListProjectPage extends StatefulWidget {
  10. const ListProjectPage({super.key});
  11. @override
  12. State<ListProjectPage> createState() => _ListProjectPageState();
  13. }
  14. class _ListProjectPageState extends State<ListProjectPage> {
  15. var jsonList;
  16. @override
  17. void initState(){
  18. getData();
  19. }
  20. void getData() async {
  21. try {
  22. var response = await Dio()
  23. .get('http://localhost:8080/api/v1/projects',
  24. options: Options(headers: headers));
  25. if (response.statusCode == 200) {
  26. setState(() {
  27. jsonList = response.data['results'] as List;
  28. });
  29. } else {
  30. print(response.statusCode);
  31. }
  32. } catch (e) {
  33. print(e);
  34. }
  35. }
  36. @override
  37. Widget build(BuildContext context) {
  38. return Scaffold(
  39. appBar: CustomAppbar(),
  40. body: Stack(children: [
  41. SingleChildScrollView(
  42. child: Column(
  43. children: [
  44. Center(
  45. child: Row(
  46. mainAxisAlignment: MainAxisAlignment.center,
  47. children: [
  48. Text(
  49. 'LIST PROJECT',
  50. style: TextStyle(color: Colors.black, fontSize: 48),
  51. ),
  52. ],
  53. )),
  54. Column(
  55. children: List.generate(
  56. jsonList == null ? 0 : jsonList.length,
  57. (i) => SizedBox(
  58. child: ListTile(
  59. leading: SizedBox(
  60. child: Icon(Icons.phone),
  61. ),
  62. title: Text(jsonList[i]['name']),
  63. subtitle: Column(
  64. crossAxisAlignment: CrossAxisAlignment.start,
  65. children: [
  66. Text(jsonList[i]['description']),
  67. Text(jsonList[i]['owner']['name'])
  68. ],
  69. ),
  70. trailing: ButtonUser(
  71. items: jsonList[i],
  72. ),
  73. ),
  74. )),
  75. ),
  76. ],
  77. ),
  78. ),
  79. ]),
  80. bottomNavigationBar: Footer(),
  81. );
  82. }
  83. }
  84. class ButtonUser extends StatelessWidget {
  85. final Map<String, dynamic> items;
  86. ButtonUser({
  87. required this.items,
  88. super.key,
  89. });
  90. //todo edit platform
  91. //todo tombol item
  92. //todo tombol delete
  93. @override
  94. Widget build(BuildContext context) {
  95. return Row(
  96. mainAxisSize: MainAxisSize.min,
  97. children: [
  98. ElevatedButton(
  99. onPressed: () => context.go('/editproject'),
  100. style: ElevatedButton.styleFrom(
  101. backgroundColor: Colors.black,
  102. ),
  103. child: Text(
  104. 'Edit',
  105. style: TextStyle(color: Colors.white),
  106. ),
  107. ),
  108. ElevatedButton(
  109. onPressed: () => delproject(context, items['id']),
  110. style: ElevatedButton.styleFrom(
  111. backgroundColor: Colors.black,
  112. ),
  113. child: Text(
  114. 'Delete',
  115. style: TextStyle(color: Colors.white),
  116. ),
  117. ),
  118. ElevatedButton(
  119. onPressed: () => context.go('/addmember'),
  120. style: ElevatedButton.styleFrom(
  121. backgroundColor: Colors.black,
  122. ),
  123. child: Text(
  124. 'Add Member',
  125. style: TextStyle(color: Colors.white),
  126. ),
  127. ),
  128. ElevatedButton(
  129. onPressed: () => context.go('/listplatform/listmember'),
  130. style: ElevatedButton.styleFrom(
  131. backgroundColor: Colors.black,
  132. ),
  133. child: Text(
  134. 'List Member',
  135. style: TextStyle(color: Colors.white),
  136. ),
  137. ),
  138. ],
  139. );
  140. }
  141. }