listplatform.dart 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // ignore_for_file: prefer_typing_uninitialized_variables, must_call_super
  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_platform.dart';
  8. import '../globals.dart';
  9. class ListPlatformPage extends StatefulWidget {
  10. const ListPlatformPage({super.key});
  11. @override
  12. State<ListPlatformPage> createState() => _ListPlatformPageState();
  13. }
  14. class _ListPlatformPageState extends State<ListPlatformPage> {
  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/platforms',
  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 PLATFORM',
  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]['project'])
  67. ],
  68. ),
  69. trailing: ButtonUser(
  70. items: jsonList[i],
  71. ),
  72. ),
  73. )),
  74. ),
  75. ],
  76. ),
  77. ),
  78. ]),
  79. bottomNavigationBar: Footer(),
  80. );
  81. }
  82. }
  83. class ButtonUser extends StatelessWidget {
  84. final Map<String, dynamic> items;
  85. ButtonUser({
  86. required this.items,
  87. super.key,
  88. });
  89. //todo edit platform
  90. //todo tombol item
  91. //todo tombol delete
  92. @override
  93. Widget build(BuildContext context) {
  94. return Row(
  95. mainAxisSize: MainAxisSize.min,
  96. children: [
  97. ElevatedButton(
  98. onPressed: () => context.go('/listplatform/editplatform'),
  99. style: ElevatedButton.styleFrom(
  100. backgroundColor: Colors.black,
  101. ),
  102. child: Text(
  103. 'Edit',
  104. style: TextStyle(color: Colors.white),
  105. ),
  106. ),
  107. ElevatedButton(
  108. onPressed: () => delplatform(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. }