edituser.dart 5.1 KB

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