edituser.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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:namer_app/footer.dart';
  5. import 'package:namer_app/header.dart';
  6. import 'package:namer_app/service/edit_user.dart';
  7. import '../globals.dart';
  8. class EditUserPage extends StatefulWidget {
  9. const EditUserPage({super.key, required json});
  10. @override
  11. State<EditUserPage> createState() => _EditUserPageState();
  12. }
  13. class _EditUserPageState extends State<EditUserPage>{
  14. var jsonList;
  15. @override
  16. void initState(){
  17. getData();
  18. }
  19. void getData() async {
  20. try {
  21. var response = await Dio()
  22. .get('http://localhost:8080/api/v1/users',
  23. options: Options(headers: headers));
  24. if (response.statusCode == 200) {
  25. setState(() {
  26. jsonList = response.data['results'] as List;
  27. });
  28. } else {
  29. print(response.statusCode);
  30. }
  31. } catch (e) {
  32. print(e);
  33. }
  34. }
  35. @override
  36. Widget build(BuildContext context) {
  37. // TextEditingController usernameController = jsonList['username'];
  38. // TextEditingController nameController = jsonList['name'];
  39. var usernameController = TextEditingController();
  40. var nameController = TextEditingController();
  41. // usernameController.text = jsonList['username'];
  42. // nameController.text = jsonList['name'];
  43. return Scaffold(
  44. appBar: CustomAppbar(),
  45. backgroundColor: Colors.white,
  46. body: Column(
  47. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  48. children: [
  49. Center(
  50. child: Row(
  51. mainAxisAlignment: MainAxisAlignment.center,
  52. children: [
  53. Text(
  54. 'EDIT USER',
  55. style: TextStyle(color: Colors.black, fontSize: 48),
  56. ),
  57. ],
  58. )),
  59. Column(
  60. children: [
  61. Padding(
  62. padding: const EdgeInsets.all(8.0),
  63. child: SizedBox(
  64. width: 396,
  65. child: TextField(
  66. decoration: InputDecoration(
  67. border: OutlineInputBorder(),
  68. focusedBorder: OutlineInputBorder(
  69. borderRadius: BorderRadius.all(Radius.circular(12)),
  70. borderSide: BorderSide(color: Colors.black)),
  71. enabledBorder: OutlineInputBorder(
  72. borderRadius: BorderRadius.all(Radius.circular(12)),
  73. borderSide: BorderSide(color: Colors.black)),
  74. labelText: 'Enter Username', //todo get data
  75. labelStyle: TextStyle(color: Colors.black),
  76. filled: true,
  77. fillColor: Colors.white.withOpacity(0.25)),
  78. cursorColor: Colors.black,
  79. style: TextStyle(color: Colors.black),
  80. controller: usernameController,
  81. ),
  82. ),
  83. ),
  84. Padding(
  85. padding: const EdgeInsets.all(8.0),
  86. child: SizedBox(
  87. width: 396,
  88. child: TextField(
  89. decoration: InputDecoration(
  90. border: OutlineInputBorder(),
  91. focusedBorder: OutlineInputBorder(
  92. borderRadius: BorderRadius.all(Radius.circular(12)),
  93. borderSide: BorderSide(color: Colors.black)),
  94. enabledBorder: OutlineInputBorder(
  95. borderRadius: BorderRadius.all(Radius.circular(12)),
  96. borderSide: BorderSide(color: Colors.black)),
  97. labelText: 'Enter Name', //todo get data
  98. labelStyle: TextStyle(color: Colors.black),
  99. filled: true,
  100. fillColor: Colors.white.withOpacity(0.25)),
  101. cursorColor: Colors.black,
  102. style: TextStyle(color: Colors.black),
  103. controller: nameController,
  104. ),
  105. ),
  106. ),
  107. Padding(
  108. padding: const EdgeInsets.all(20.0),
  109. child: SizedBox(
  110. width: 396,
  111. height: 61,
  112. child: ElevatedButton(
  113. onPressed: () => edit(context, jsonList['id'], usernameController.text, nameController.text),
  114. style: ElevatedButton.styleFrom(
  115. backgroundColor: Colors.black, //todo putih lage
  116. side: BorderSide(color: Colors.white),
  117. shape: RoundedRectangleBorder(
  118. borderRadius: BorderRadius.circular(12.0),
  119. ),
  120. ),
  121. child: Text(
  122. 'Edit',
  123. style: TextStyle(color: Colors.white),
  124. ),
  125. ),
  126. ),
  127. ),
  128. ],
  129. ),
  130. ],
  131. ),
  132. bottomNavigationBar: Footer(),
  133. );
  134. }
  135. }