athrainsky 7 mesiacov pred
rodič
commit
7827689163

+ 44 - 16
lib/bug/listbug.dart

@@ -1,16 +1,46 @@
+// ignore_for_file: prefer_typing_uninitialized_variables, must_call_super
+
+import 'package:dio/dio.dart';
 import 'package:flutter/material.dart';
 import 'package:go_router/go_router.dart';
-import 'package:namer_app/data/databug.dart';
 import 'package:namer_app/footer.dart';
 import 'package:namer_app/header.dart';
 
-class ListBugPage extends StatelessWidget {
+import '../globals.dart';
+
+class ListBugPage extends StatefulWidget {
   const ListBugPage({super.key});
 
+  @override
+  State<ListBugPage> createState() => _ListBugPageState();
+}
+
+class _ListBugPageState extends State<ListBugPage> {
+  var jsonList;
+  @override
+void initState(){
+  getData();
+}
+
+void getData() async { 
+    try { 
+      var response = await Dio() 
+          .get('http://localhost:8080/api/v1/bugs',
+          options: Options(headers: headers)); 
+      if (response.statusCode == 200) { 
+        setState(() { 
+          jsonList = response.data['results'] as List; 
+        }); 
+      } else { 
+        print(response.statusCode); 
+      } 
+    } catch (e) { 
+      print(e); 
+    } 
+  } 
   @override
   Widget build(BuildContext context) {
     return Scaffold(
-
       appBar: CustomAppbar(),
       body: Stack(children: [
         SingleChildScrollView(
@@ -28,49 +58,47 @@ class ListBugPage extends StatelessWidget {
               )),
               Column(
                 children: List.generate(
-                    2,
+                    jsonList == null ? 0 : jsonList.length,
                     (i) => SizedBox(
-                          // height: 80,
-                          child: ListTile(
-                            // visualDensity: VisualDensity(vertical: 4),
+                          child: ListTile(                          
                             leading: SizedBox(
                               child: Icon(Icons.bug_report),
                             ),
-                            title: Text(bugs[i]['bug']),
+                            title: Text(jsonList[i]['description']),
                             subtitle: Column(
                               crossAxisAlignment: CrossAxisAlignment.start,
                               children: [
-                                Text(bugs[i]['goodday']),
+                                Text(jsonList[i]['goodday_url']),
                                 Row(
                                   children: [
-                                    Text(bugs[i]['created']),
+                                    Text(jsonList[i]['created']),
                                     Container(
                                       width: 30,
                                     ),
-                                    Text(bugs[i]['level']),
+                                    Text(jsonList[i]['level']),
                                   ],
                                 ),
                                 Row(
                                   children: [
-                                    Text(bugs[i]['qc']),
+                                    Text(jsonList[i]['qc']),
                                     Container(
                                       width: 20,
                                     ),
-                                    Text(bugs[i]['status']),
+                                    Text(jsonList[i]['status']),
                                     Container(
                                       width: 20,
                                     ),
-                                    Text(bugs[i]['programmer']),
+                                    Text(jsonList[i]['dev']),
                                     Container(
                                       width: 20,
                                     ),
-                                    Text(bugs[i]['dev_status'])
+                                    Text(jsonList[i]['dev_status'])
                                   ],
                                 )
                               ],
                             ),
                             trailing: ButtonUser(
-                              items: bugs[i],
+                              items: jsonList[i],
                             ),
                           ),
                         )),

+ 11 - 1
lib/globals.dart

@@ -1,3 +1,13 @@
 library my_prj.globals;
+import 'dart:convert';
 
-String userLogin = '';
+String USER_LOGIN = 'user';
+String PASS_LOGIN = 'password';
+var path = 'http://localhost:8080/api/v1/';
+
+var auth = 'Basic ${base64Encode(utf8.encode('$USER_LOGIN:$PASS_LOGIN'))}';
+Map<String, String> headers = {
+  'content-type': 'application/json',
+  'accept': 'application/json',
+  'authorization': auth
+};

+ 112 - 76
lib/header.dart

@@ -31,12 +31,21 @@ class _CustomAppbarState extends State<CustomAppbar> {
           padding: const EdgeInsets.symmetric(horizontal: 8.0),
           child: DropdownButtonHideUnderline(
             child: DropdownButton2(
+              customButton: const Icon(Icons.home),
+              onChanged: (value) => context.go('/'), 
               items: [
                 DropdownMenuItem(
                   child: Text('Home'),
                 )
               ],
-              onChanged: (value) => context.go('/'),
+              dropdownStyleData: DropdownStyleData(
+                width: 80,
+                padding: const EdgeInsets.symmetric(vertical: 6),
+                decoration: BoxDecoration(
+                  borderRadius: BorderRadius.circular(4),
+                ),
+                offset: const Offset(0, 8),
+              ),
             ),
           ),
         ),
@@ -44,23 +53,20 @@ class _CustomAppbarState extends State<CustomAppbar> {
           padding: const EdgeInsets.symmetric(horizontal: 8.0),
           child: DropdownButtonHideUnderline(
             child: DropdownButton2(
-              customButton: Text(
-                'Bug',
-                style: TextStyle(fontSize: 15),
-              ),
+              customButton: const Icon(Icons.person),
               items: [
-                ...MenuItems2.firstItems.map(
+                ...UserItems.firstItems.map(
                   (item) => DropdownMenuItem<MenuItem>(
                     value: item,
-                    child: MenuItems2.buildItem(item),
+                    child: UserItems.buildItem(item),
                   ),
                 ),
               ],
               onChanged: (value) {
-                MenuItems2.onChanged(context, value!);
+                UserItems.onChanged(context, value!);
               },
               dropdownStyleData: DropdownStyleData(
-                width: 150,
+                width: 100,
                 padding: const EdgeInsets.symmetric(vertical: 6),
                 decoration: BoxDecoration(
                   borderRadius: BorderRadius.circular(4),
@@ -69,7 +75,7 @@ class _CustomAppbarState extends State<CustomAppbar> {
               ),
               menuItemStyleData: MenuItemStyleData(
                 customHeights: [
-                  ...List<double>.filled(MenuItems2.firstItems.length, 48),
+                  ...List<double>.filled(UserItems.firstItems.length, 48),
                 ],
                 padding: const EdgeInsets.only(left: 16, right: 16),
               ),
@@ -80,20 +86,50 @@ class _CustomAppbarState extends State<CustomAppbar> {
           padding: const EdgeInsets.symmetric(horizontal: 8.0),
           child: DropdownButtonHideUnderline(
             child: DropdownButton2(
-              customButton: Text(
-                'Platform',
-                style: TextStyle(fontSize: 15),
+              customButton: const Icon(Icons.bug_report),
+              items: [
+                ...BugItems.firstItems.map(
+                  (item) => DropdownMenuItem<MenuItem>(
+                    value: item,
+                    child: BugItems.buildItem(item),
+                  ),
+                ),
+              ],
+              onChanged: (value) {
+                BugItems.onChanged(context, value!);
+              },
+              dropdownStyleData: DropdownStyleData(
+                width: 100,
+                padding: const EdgeInsets.symmetric(vertical: 6),
+                decoration: BoxDecoration(
+                  borderRadius: BorderRadius.circular(4),
+                ),
+                offset: const Offset(0, 8),
               ),
+              menuItemStyleData: MenuItemStyleData(
+                customHeights: [
+                  ...List<double>.filled(BugItems.firstItems.length, 48),
+                ],
+                padding: const EdgeInsets.only(left: 16, right: 16),
+              ),
+            ),
+          ),
+        ),
+        Padding(
+          padding: const EdgeInsets.symmetric(horizontal: 8.0),
+          child: DropdownButtonHideUnderline(
+            child: DropdownButton2(
+              customButton: const Icon(Icons.dynamic_form),
               items: [
-                ...MenuItems.firstItems.map(
+                ...PlatformItems.firstItems.map(
                   (item) => DropdownMenuItem<MenuItem>(
                     value: item,
-                    child: MenuItems.buildItem(item),
+                    child: PlatformItems.buildItem(item),
                   ),
                 ),
               ],
               onChanged: (value) {
-                MenuItems.onChanged(context, value!);
+                PlatformItems.onChanged(context, value!);
               },
               dropdownStyleData: DropdownStyleData(
                 width: 150,
@@ -105,7 +141,7 @@ class _CustomAppbarState extends State<CustomAppbar> {
               ),
               menuItemStyleData: MenuItemStyleData(
                 customHeights: [
-                  ...List<double>.filled(MenuItems.firstItems.length, 48),
+                  ...List<double>.filled(PlatformItems.firstItems.length, 48),
                 ],
                 padding: const EdgeInsets.only(left: 16, right: 16),
               ),
@@ -116,12 +152,21 @@ class _CustomAppbarState extends State<CustomAppbar> {
           padding: const EdgeInsets.symmetric(horizontal: 8),
           child: DropdownButtonHideUnderline(
             child: DropdownButton2(
+              customButton: const Icon(Icons.pan_tool),
               items: [
                 DropdownMenuItem(
                   child: Text('Maintenance'),
                 )
               ],
               onChanged: (value) => context.go('/maintenance'),
+              dropdownStyleData: DropdownStyleData(
+                width: 130,
+                padding: const EdgeInsets.symmetric(vertical: 6),
+                decoration: BoxDecoration(
+                  borderRadius: BorderRadius.circular(4),
+                ),
+                offset: const Offset(0, 8),
+              ),
             ),
           ),
         ),
@@ -129,12 +174,21 @@ class _CustomAppbarState extends State<CustomAppbar> {
           padding: const EdgeInsets.symmetric(horizontal: 6),
           child: DropdownButtonHideUnderline(
             child: DropdownButton2(
+              customButton: const Icon(Icons.logout),
               items: [
                 DropdownMenuItem(
                   child: Text('Log Out'),
                 )
               ],
               onChanged: null,
+              dropdownStyleData: DropdownStyleData(
+                width: 130,
+                padding: const EdgeInsets.symmetric(vertical: 6),
+                decoration: BoxDecoration(
+                  borderRadius: BorderRadius.circular(4),
+                ),
+                offset: const Offset(0, 8),
+              ),
             ),
           ),
         ),
@@ -151,7 +205,7 @@ class MenuItem {
   final String text;
 }
 
-abstract class MenuItems {
+mixin PlatformItems {
   static const List<MenuItem> firstItems = [add, edit, list];
 
   static const add = MenuItem(text: 'Add Platform');
@@ -175,20 +229,20 @@ abstract class MenuItems {
 
   static void onChanged(BuildContext context, MenuItem item) {
     switch (item) {
-      case MenuItems.add:
+      case PlatformItems.add:
         context.go('/addplatform');
         break;
-      case MenuItems.edit:
+      case PlatformItems.edit:
         context.go('/listplatform/editplatform');
         break;
-      case MenuItems.list:
+      case PlatformItems.list:
         context.go('/listplatform');
         break;
     }
   }
 }
 
-abstract class MenuItems2 {
+mixin BugItems {
   static const List<MenuItem> firstItems = [add, edit, list];
 
   static const add = MenuItem(text: 'Add Bug');
@@ -212,70 +266,52 @@ abstract class MenuItems2 {
 
   static void onChanged(BuildContext context, MenuItem item) {
     switch (item) {
-      case MenuItems2.add:
+      case BugItems.add:
         context.go('/addbug');
         break;
-      case MenuItems2.edit:
+      case BugItems.edit:
         context.go('/login/bug/editbug');
         break;
-      case MenuItems2.list:
+      case BugItems.list:
         context.go('/login/bug');
         break;
     }
   }
 }
 
-// class Header extends StatelessWidget implements PreferredSizeWidget {
-//   final Text title;
-//   final AppBar appBar;
-//   final List<Widget> widgets;
+mixin UserItems {
+  static const List<MenuItem> firstItems = [/*edit, change,*/ list];
 
-//   const Header(
-//       {super.key,
-//       required this.title,
-//       required this.appBar,
-//       required this.widgets});
+  static const edit = MenuItem(text: 'Edit User');
+  static const change = MenuItem(text: 'Edit Password');
+  static const list = MenuItem(text: 'List User');
 
-//   @override
-//   Widget build(BuildContext context) {
-//     return AppBar(
-//       backgroundColor: Colors.white,
-//       leading: Icon(Icons.bug_report),
-//       titleSpacing: 0,
-//       title: Text(
-//         'Bug Listing',
-//         style: TextStyle(fontSize: 28, fontWeight: FontWeight.w500),
-//       ),
-//       actions: [
-//         //todo hide kalo non login
-//         ElevatedButton(
-//             onPressed: () => context.go('/'),
-//             style: ElevatedButton.styleFrom(surfaceTintColor: Colors.white),
-//             child: Text(
-//               'Home',
-//               style: TextStyle(color: Colors.black),
-//             )),
-//         ElevatedButton(
-//           onPressed: () => context.go('/listplatform'),
-//           style: ElevatedButton.styleFrom(surfaceTintColor: Colors.white),
-//           child: Text(
-//             'Platform',
-//             style: TextStyle(color: Colors.black),
-//           ),
-//         ),
-//         ElevatedButton(
-//           onPressed: () => context.go('/maintenance'),
-//           style: ElevatedButton.styleFrom(surfaceTintColor: Colors.white),
-//           child: Text(
-//             'Maintenance',
-//             style: TextStyle(color: Colors.black),
-//           ),
-//         ),
-//         Text('Log Out'),
-//       ],
-//     );
-//   }
+  static Widget buildItem(MenuItem item) {
+    return Row(
+      children: [
+        Expanded(
+          child: Text(
+            item.text,
+            style: const TextStyle(
+              color: Colors.black,
+            ),
+          ),
+        ),
+      ],
+    );
+  }
 
-//   @override
-//   Size get preferredSize => Size.fromHeight(appBar.preferredSize.height);
-// }
+  static void onChanged(BuildContext context, MenuItem item) {
+    switch (item) {
+      // case UserItems.edit:
+      //   context.go('/signup/listuser/edit');
+      //   break;
+      // case UserItems.change:
+      //   context.go('/login/bug/editbug');
+      //   break;
+      case UserItems.list:
+        context.go('/signup/listuser');
+        break;
+    }
+  }
+}

+ 1 - 2
lib/login.dart

@@ -1,10 +1,9 @@
 // ignore_for_file: use_build_context_synchronously
 
-import 'package:dio/dio.dart';
 import 'package:flutter/material.dart';
 import 'package:namer_app/footer.dart';
 import 'package:namer_app/header.dart';
-import 'package:namer_app/service/submit.dart';
+import 'package:namer_app/service/login_serv.dart';
 
 class LoginPage extends StatelessWidget {
   const LoginPage({super.key});

+ 14 - 7
lib/main.dart

@@ -1,3 +1,5 @@
+// ignore_for_file: must_call_super, prefer_typing_uninitialized_variables
+
 import 'package:flutter/material.dart';
 import 'package:go_router/go_router.dart';
 import 'package:namer_app/bug/addbug.dart';
@@ -22,7 +24,10 @@ void main() {
   runApp(MyApp());
 }
 
-final _router = GoRouter(
+
+
+  // var jsonList;
+  final _router = GoRouter(
   routes: [
     GoRoute(path: '/', builder: (context, state) => MyHomePage(), routes: [
       GoRoute(path: 'login', builder: (context, state) => LoginPage(), routes: [
@@ -49,9 +54,13 @@ final _router = GoRouter(
                 builder: (context, state) => ListUserPage(),
                 routes: [
                   GoRoute(
-                    path: 'edit',
-                    builder: (context, state) => EditUserPage(),
-                  )
+                    path: 'edit/:id',
+                    builder: (context, state) {
+                      // var item = jsonList.firstWhere(
+                      //   (element) => element('id') == state.pathParameters['id']);
+                        // return EditUserPage(json: item);
+                        return EditUserPage(json: null);
+                    })
                 ])
           ]),
       GoRoute(
@@ -81,11 +90,9 @@ final _router = GoRouter(
       ),
     ]),
   ],
-);
-
+); 
 class MyApp extends StatelessWidget {
   const MyApp({super.key});
-
   @override
   Widget build(BuildContext context) {
     return MaterialApp.router(

+ 49 - 0
lib/service/delete_user.dart

@@ -0,0 +1,49 @@
+
+// ignore_for_file: use_build_context_synchronously
+
+import 'dart:convert';
+import 'package:dio/dio.dart';
+import 'package:flutter/material.dart';
+import '../globals.dart';
+
+Future<void> delete(BuildContext context, int id) async{
+  final dio = Dio();
+  Response response;
+    AlertDialog alert = AlertDialog(
+      title: Text("Delete Sukses"),
+      content: Text("Data terhapus"),
+      actions: [
+        TextButton( 
+          child: Text('Ok'),
+          onPressed: () => Navigator.of(context).pop(),
+        ),
+      ],
+    );
+        AlertDialog alert2 = AlertDialog(
+      title: Text("Delete Gagal"),
+      content: Text("Data Invalid"),
+      actions: [
+        TextButton( 
+          child: Text('Ok'),
+          onPressed: () => Navigator.of(context).pop(),
+        ),
+      ],
+    );
+            var auth = 'Basic ${base64Encode(utf8.encode('$USER_LOGIN:$PASS_LOGIN'))}';
+        Map<String, String> headers = {
+          'content-type': 'application/json',
+          'accept': 'application/json',
+          'authorization': auth
+      };
+try {
+  response = await dio.delete("http://localhost:8080/api/v1/users/$id",
+              options: Options(headers: headers)
+              );
+  if(response.statusCode == 200){
+    showDialog(context: context, builder: (context) => alert);
+    
+  }
+} catch (error){
+  showDialog(context: context, builder: (context) => alert2);
+}
+} 

+ 51 - 0
lib/service/edit_user.dart

@@ -0,0 +1,51 @@
+
+// ignore_for_file: use_build_context_synchronously
+
+import 'dart:convert';
+import 'package:dio/dio.dart';
+import 'package:flutter/material.dart';
+import '../globals.dart';
+
+Future<void> edit(BuildContext context, int id, String username, String name) async{
+  final dio = Dio();
+  Response response;
+    AlertDialog alert = AlertDialog(
+      title: Text("Edit Sukses"),
+      content: Text("Data teredit"),
+      actions: [
+        TextButton( 
+          child: Text('Ok'),
+          onPressed: () => Navigator.of(context).pop(),
+        ),
+      ],
+    );
+        AlertDialog alert2 = AlertDialog(
+      title: Text("Edit Gagal"),
+      content: Text("Data Invalid"),
+      actions: [
+        TextButton( 
+          child: Text('Ok'),
+          onPressed: () => Navigator.of(context).pop(),
+        ),
+      ],
+    );
+            var auth = 'Basic ${base64Encode(utf8.encode('$USER_LOGIN:$PASS_LOGIN'))}';
+        Map<String, String> headers = {
+          'content-type': 'application/json',
+          'accept': 'application/json',
+          'authorization': auth
+      };
+try {
+  response = await dio.put("http://localhost:8080/api/v1/users/$id",
+              options: Options(headers: headers),
+              data: {'username':username, 'name':name}
+              );
+              print(response);
+  if(response.statusCode == 200){
+    showDialog(context: context, builder: (context) => alert);
+    
+  }
+} catch (error){
+  showDialog(context: context, builder: (context) => alert2);
+}
+} 

+ 35 - 0
lib/service/get_user.dart

@@ -0,0 +1,35 @@
+// ignore_for_file: camel_case_types
+
+import 'package:dio/dio.dart';
+import 'package:flutter/material.dart';
+import '../globals.dart';
+
+class _getuser extends StatefulWidget {
+  const _getuser();
+
+  @override
+  State<_getuser> createState() => _getuserState();
+}
+
+class _getuserState extends State<_getuser> {
+  late List jsonList;
+
+  void getuser() async {
+    
+    try { 
+      var response = await Dio() 
+          .get('http://localhost:8080/api/v1/users',
+          options: Options(headers: headers)); 
+      if (response.statusCode == 200) { 
+        setState(() { 
+        jsonList = response.data['results'] as List; 
+        }); 
+      } 
+    } catch (e) { 
+      print(e); 
+    } 
+  } 
+  
+  @override
+  dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
+  }

+ 55 - 0
lib/service/login_serv.dart

@@ -0,0 +1,55 @@
+// ignore_for_file: use_build_context_synchronously
+
+import 'dart:convert';
+import 'package:dio/dio.dart';
+import 'package:flutter/material.dart';
+import 'package:go_router/go_router.dart';
+import 'package:namer_app/globals.dart';
+
+
+Future<void> submit(BuildContext context, String email, String password) async {
+    final dio = Dio();
+    Response response;
+
+// AlertDialog alert = AlertDialog(
+//       title: Text("Login Sukses"),
+//       content: Text("Sukses"),
+//       actions: [
+//         TextButton( 
+//           child: Text('Ok'),
+//           onPressed: () => Navigator.of(context).pop(),
+//         ),
+//       ],
+//     );
+    AlertDialog alert2 = AlertDialog(
+      title: Text("Login Gagal"),
+      content: Text("Username atau Password salah"),
+      actions: [
+        TextButton( 
+          child: Text('Ok'),
+          onPressed: () => Navigator.of(context).pop(),
+        ),
+      ],
+    );
+
+      var auth = 'Basic ${base64Encode(utf8.encode('$email:$password'))}';
+      Map<String, String> headers = {
+        'content-type': 'application/json',
+        'accept': 'application/json',
+        'authorization': auth
+      };
+    try{
+      response = await dio.get("http://localhost:8080/api/v1/users", 
+          options: Options(headers: headers));
+          if (response.statusCode == 200){
+              USER_LOGIN = email;
+              PASS_LOGIN = password;
+              // showDialog(context: context, builder: (context) => alert);
+              return context.go('/login/bug');
+          } 
+     }  catch (error){
+      showDialog(context: context, builder: (context) => alert2);
+      }
+          
+  }
+

+ 46 - 0
lib/service/signup_serv.dart

@@ -0,0 +1,46 @@
+// ignore_for_file: use_build_context_synchronously
+
+import 'dart:convert';
+
+import 'package:dio/dio.dart';
+import 'package:flutter/material.dart';
+import 'package:go_router/go_router.dart';
+import '../globals.dart';
+
+Future<void> signup(BuildContext context, String email, String password, String name, /*Map data*/) async {
+    final dio = Dio();
+    Response response;
+
+    AlertDialog alert2 = AlertDialog(
+      title: Text("SignUp Gagal"),
+      content: Text("Data Invalid"),
+      actions: [
+        TextButton( 
+          child: Text('Ok'),
+          onPressed: () => Navigator.of(context).pop(),
+        ),
+      ],
+    );
+        var auth = 'Basic ${base64Encode(utf8.encode('$USER_LOGIN:$PASS_LOGIN'))}';
+        Map<String, String> headers = {
+          'content-type': 'application/json',
+          'accept': 'application/json',
+          'authorization': auth
+      };
+    try{
+      response = await dio.post("http://localhost:8080/api/v1/users", 
+                  options: Options(headers: headers),
+                  data: 
+                  // data 
+                  {'username':email,'password':password,'name':name}
+                  );    
+      if (response.statusCode == 201){
+          return context.go('/signup/listuser');
+      } 
+    } catch (error){     
+      
+      showDialog(context: context, builder: (context) => alert2);
+      }
+          
+  }
+

+ 0 - 50
lib/service/submit.dart

@@ -1,50 +0,0 @@
-// ignore_for_file: use_build_context_synchronously
-
-import 'dart:convert';
-import 'package:dio/dio.dart';
-import 'package:flutter/material.dart';
-import 'package:go_router/go_router.dart';
-import 'package:namer_app/globals.dart' as globals;
-
-Future<void> submit(BuildContext context, String email, String password) async {
-    final dio = Dio();
-    Response response;
-    if (email.isEmpty || password.isEmpty) {
-      final snackBar = SnackBar(
-        duration: const Duration(seconds: 5),
-        content: Text("Username dan password harus diisi"),
-        backgroundColor: Colors.red,
-      );
-
-      ScaffoldMessenger.of(context).showSnackBar(snackBar);
-      return;
-    }
-
-    AlertDialog alert2 = AlertDialog(
-      title: Text("Login Gagal"),
-      content: Text("Username atau Password salah"),
-      actions: [
-        TextButton( 
-          child: Text('Ok'),
-          onPressed: () => Navigator.of(context).pop(),
-        ),
-      ],
-    );
-
-        var auth = 'Basic ${base64Encode(utf8.encode('$email:$password'))}';
-        Map<String, String> headers = {
-          'content-type': 'application/json',
-          'accept': 'application/json',
-          'authorization': auth
-      };
-    try{
-      response = await dio.get('http://localhost:8080/api/v1/users', 
-          options: Options(headers: headers));
-          if (response.statusCode == 200){
-              globals.userLogin = email;
-              return context.go('/login/bug');
-          } 
-     }  catch (error){     showDialog(context: context, builder: (context) => alert2);}
-          
-  }
-

+ 45 - 5
lib/user/edituser.dart

@@ -1,13 +1,53 @@
+// ignore_for_file: must_call_super, prefer_typing_uninitialized_variables
+
+
+import 'package:dio/dio.dart';
 import 'package:flutter/material.dart';
 import 'package:namer_app/footer.dart';
 import 'package:namer_app/header.dart';
+import 'package:namer_app/service/edit_user.dart';
+import '../globals.dart';
+
+
+class EditUserPage extends StatefulWidget {
+  const EditUserPage({super.key, required json});
 
+@override
+State<EditUserPage> createState() => _EditUserPageState();
+}
+
+class _EditUserPageState extends State<EditUserPage>{
+var jsonList;
+@override
+void initState(){
+  getData();
+}
 
-class EditUserPage extends StatelessWidget {
-  const EditUserPage({super.key});
+void getData() async { 
+    try { 
+      var response = await Dio() 
+          .get('http://localhost:8080/api/v1/users',
+          options: Options(headers: headers)); 
+      if (response.statusCode == 200) { 
+        setState(() { 
+          jsonList = response.data['results'] as List; 
+        }); 
+      } else { 
+        print(response.statusCode); 
+      } 
+    } catch (e) { 
+      print(e); 
+    } 
+  } 
 
   @override
   Widget build(BuildContext context) {
+    // TextEditingController usernameController = jsonList['username'];
+    // TextEditingController nameController = jsonList['name'];
+    var usernameController = TextEditingController();
+    var nameController = TextEditingController();
+    // usernameController.text = jsonList['username'];
+    // nameController.text = jsonList['name'];
     return Scaffold(
       appBar: CustomAppbar(),
       backgroundColor: Colors.white,
@@ -30,7 +70,6 @@ class EditUserPage extends StatelessWidget {
                 padding: const EdgeInsets.all(8.0),
                 child: SizedBox(
                   width: 396,
-                  // height: 51,
                   child: TextField(
                     decoration: InputDecoration(
                         border: OutlineInputBorder(),
@@ -46,6 +85,7 @@ class EditUserPage extends StatelessWidget {
                         fillColor: Colors.white.withOpacity(0.25)),
                     cursorColor: Colors.black,
                     style: TextStyle(color: Colors.black),
+                    controller: usernameController,
                   ),
                 ),
               ),
@@ -53,7 +93,6 @@ class EditUserPage extends StatelessWidget {
                 padding: const EdgeInsets.all(8.0),
                 child: SizedBox(
                   width: 396,
-                  // height: 51,
                   child: TextField(
                     decoration: InputDecoration(
                         border: OutlineInputBorder(),
@@ -69,6 +108,7 @@ class EditUserPage extends StatelessWidget {
                         fillColor: Colors.white.withOpacity(0.25)),
                     cursorColor: Colors.black,
                     style: TextStyle(color: Colors.black),
+                    controller: nameController,
                   ),
                 ),
               ),
@@ -78,7 +118,7 @@ class EditUserPage extends StatelessWidget {
                   width: 396,
                   height: 61,
                   child: ElevatedButton(
-                    onPressed: null, //todo save edit
+                    onPressed: () => edit(context, jsonList['id'], usernameController.text, nameController.text),
                     style: ElevatedButton.styleFrom(
                       backgroundColor: Colors.black, //todo putih lage
                       side: BorderSide(color: Colors.white),

+ 50 - 18
lib/user/listuser.dart

@@ -1,12 +1,44 @@
+// ignore_for_file: must_call_super, prefer_typing_uninitialized_variables
+
+import 'package:dio/dio.dart';
 import 'package:flutter/material.dart';
 import 'package:go_router/go_router.dart';
-import 'package:namer_app/data/datauser.dart';
 import 'package:namer_app/footer.dart';
+import 'package:namer_app/globals.dart';
 import 'package:namer_app/header.dart';
+import '../service/delete_user.dart';
 
-class ListUserPage extends StatelessWidget {
+class ListUserPage extends StatefulWidget {
   const ListUserPage({super.key});
 
+@override
+State<ListUserPage> createState() => _ListUserPageState();
+}
+
+class _ListUserPageState extends State<ListUserPage> {
+var jsonList;
+@override
+void initState(){
+  getData();
+}
+
+void getData() async { 
+    try { 
+      var response = await Dio() 
+          .get('http://localhost:8080/api/v1/users',
+          options: Options(headers: headers)); 
+      if (response.statusCode == 200) { 
+        setState(() { 
+          jsonList = response.data['results'] as List; 
+        }); 
+      } else { 
+        print(response.statusCode); 
+      } 
+    } catch (e) { 
+      print(e); 
+    } 
+  } 
+
   @override
   Widget build(BuildContext context) {
     return Scaffold(
@@ -26,19 +58,19 @@ class ListUserPage extends StatelessWidget {
                 ],
               )),
               Column(
-                children: List.generate(
-                    9,
-                    (i) => SizedBox(
-                          child: ListTile(
-                            visualDensity: VisualDensity(vertical: 4),
-                            leading: SizedBox(
-                              child: Icon(Icons.person),
-                            ),
-                            title: Text(users[i]['username']),
-                            subtitle: Text(users[i]['user']),
-                            trailing: ButtonUser(items: users[i]),
-                          ),
-                        )),
+                children: 
+                List.generate(
+                  jsonList == null ? 0 : jsonList.length,
+                  (index) => SizedBox(
+                    child: ListTile(
+                      leading: SizedBox(
+                        child: Icon(Icons.person),
+                      ),
+                      title: Text(jsonList[index]['username']),
+                      subtitle: Text(jsonList[index]['name']),
+                      trailing: ButtonUser(items: jsonList[index]),
+                    ),
+                  ))
               ),
             ],
           ),
@@ -58,11 +90,11 @@ class ButtonUser extends StatelessWidget {
 
   @override
   Widget build(BuildContext context) {
-    return Column(
+    return Row(
       mainAxisSize: MainAxisSize.min,
       children: [
         ElevatedButton(
-          onPressed: () => context.go('/signup/listuser/edit'),
+          onPressed: () => context.go("/signup/listuser/edit/$items['id']"),
           style: ElevatedButton.styleFrom(
             backgroundColor: Colors.black,
           ),
@@ -73,7 +105,7 @@ class ButtonUser extends StatelessWidget {
         ),
         ElevatedButton(
           //todo tombol item
-          onPressed: null, //todo delete
+          onPressed: () => delete(context, items['id']),
           style: ElevatedButton.styleFrom(
             backgroundColor: Colors.black,
           ),

+ 99 - 85
lib/user/signup.dart

@@ -1,60 +1,85 @@
 import 'package:flutter/material.dart';
-import 'package:go_router/go_router.dart';
 import 'package:namer_app/footer.dart';
 import 'package:namer_app/header.dart';
+import 'package:namer_app/service/signup_serv.dart';
 
 class SignupPage extends StatelessWidget {
   const SignupPage({super.key});
 
   @override
   Widget build(BuildContext context) {
+    var usernameController = TextEditingController();
+    final nameController = TextEditingController();
+    final passwordController = TextEditingController();
     return Scaffold(
       appBar: CustomAppbar(),
       backgroundColor: Colors.white,
-      body: Column(
-        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
-        children: [
-          Center(
-              child: Row(
-            mainAxisAlignment: MainAxisAlignment.center,
-            children: [
-              Text(
-                'SIGN UP',
-                style: TextStyle(color: Colors.black, fontSize: 48),
-              ),
-            ],
-          )),
-          Column(
-            children: [
-              Padding(
-                padding: const EdgeInsets.all(8.0),
-                child: SizedBox(
-                  width: 396,
-                  // height: 51,
-                  child: TextField(
-                    decoration: InputDecoration(
-                        border: OutlineInputBorder(),
-                        focusedBorder: OutlineInputBorder(
-                            borderRadius: BorderRadius.all(Radius.circular(12)),
-                            borderSide: BorderSide(color: Colors.black)),
-                        enabledBorder: OutlineInputBorder(
-                            borderRadius: BorderRadius.all(Radius.circular(12)),
-                            borderSide: BorderSide(color: Colors.black)),
-                        labelText: 'Enter Username',
-                        labelStyle: TextStyle(color: Colors.black),
-                        filled: true,
-                        fillColor: Colors.white.withOpacity(0.25)),
-                    cursorColor: Colors.black,
-                    style: TextStyle(color: Colors.black),
+      body: Form(
+        child: Column(
+          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
+          children: [
+            Center(
+                child: Row(
+              mainAxisAlignment: MainAxisAlignment.center,
+              children: [
+                Text(
+                  'SIGN UP',
+                  style: TextStyle(color: Colors.black, fontSize: 48),
+                ),
+              ],
+            )),
+            Column(
+              children: [
+                Padding(
+                  padding: const EdgeInsets.all(8.0),
+                  child: SizedBox(
+                    width: 396,
+                    child: TextFormField(
+                      decoration: InputDecoration(
+                          border: OutlineInputBorder(),
+                          focusedBorder: OutlineInputBorder(
+                              borderRadius: BorderRadius.all(Radius.circular(12)),
+                              borderSide: BorderSide(color: Colors.black)),
+                          enabledBorder: OutlineInputBorder(
+                              borderRadius: BorderRadius.all(Radius.circular(12)),
+                              borderSide: BorderSide(color: Colors.black)),
+                          labelText: 'Enter Username',
+                          labelStyle: TextStyle(color: Colors.black),
+                          filled: true,
+                          fillColor: Colors.white.withOpacity(0.25)),
+                      cursorColor: Colors.black,
+                      style: TextStyle(color: Colors.black),
+                      controller: usernameController,
+                    ),
+                  ),
+                ),
+                Padding(
+                  padding: const EdgeInsets.all(8.0),
+                  child: SizedBox(
+                    width: 396,
+                    child: TextFormField(
+                      decoration: InputDecoration(
+                          border: OutlineInputBorder(),
+                          focusedBorder: OutlineInputBorder(
+                              borderRadius: BorderRadius.all(Radius.circular(12)),
+                              borderSide: BorderSide(color: Colors.black)),
+                          enabledBorder: OutlineInputBorder(
+                              borderRadius: BorderRadius.all(Radius.circular(12)),
+                              borderSide: BorderSide(color: Colors.black)),
+                          labelText: 'Enter Name',
+                          labelStyle: TextStyle(color: Colors.black),
+                          filled: true,
+                          fillColor: Colors.white.withOpacity(0.25)),
+                      cursorColor: Colors.black,
+                      style: TextStyle(color: Colors.black),
+                      controller: nameController,
+                    ),
                   ),
                 ),
-              ),
-              Padding(
-                padding: const EdgeInsets.all(8.0),
-                child: SizedBox(
+                SizedBox(
                   width: 396,
-                  // height: 51,
-                  child: TextField(
+                  child: TextFormField(
+                    obscureText: true,
                     decoration: InputDecoration(
                         border: OutlineInputBorder(),
                         focusedBorder: OutlineInputBorder(
@@ -63,62 +88,51 @@ class SignupPage extends StatelessWidget {
                         enabledBorder: OutlineInputBorder(
                             borderRadius: BorderRadius.all(Radius.circular(12)),
                             borderSide: BorderSide(color: Colors.black)),
-                        labelText: 'Enter Name',
+                        labelText: 'Enter Password',
                         labelStyle: TextStyle(color: Colors.black),
                         filled: true,
                         fillColor: Colors.white.withOpacity(0.25)),
                     cursorColor: Colors.black,
                     style: TextStyle(color: Colors.black),
+                    
+                    controller: passwordController,
                   ),
                 ),
-              ),
-              SizedBox(
-                width: 396,
-                // height: 51,
-                child: TextField(
-                  obscureText: true,
-                  decoration: InputDecoration(
-                      border: OutlineInputBorder(),
-                      focusedBorder: OutlineInputBorder(
-                          borderRadius: BorderRadius.all(Radius.circular(12)),
-                          borderSide: BorderSide(color: Colors.black)),
-                      enabledBorder: OutlineInputBorder(
-                          borderRadius: BorderRadius.all(Radius.circular(12)),
-                          borderSide: BorderSide(color: Colors.black)),
-                      labelText: 'Enter Password',
-                      labelStyle: TextStyle(color: Colors.black),
-                      filled: true,
-                      fillColor: Colors.white.withOpacity(0.25)),
-                  cursorColor: Colors.black,
-                  style: TextStyle(color: Colors.black),
-                ),
-              ),
-              Padding(
-                padding: const EdgeInsets.all(20.0),
-                child: SizedBox(
-                  width: 396,
-                  height: 61,
-                  child: ElevatedButton(
-                    onPressed: () => context.go('/signup/listuser'),
-                    style: ElevatedButton.styleFrom(
-                      backgroundColor: Colors.black, //todo putih lage
-                      side: BorderSide(color: Colors.white),
-                      shape: RoundedRectangleBorder(
-                        borderRadius: BorderRadius.circular(12.0),
+                Padding(
+                  padding: const EdgeInsets.all(20.0),
+                  child: SizedBox(
+                    width: 396,
+                    height: 61,
+                    child: ElevatedButton(
+                      onPressed: () => signup(context, 
+                      // formData
+                      usernameController.text,
+                      passwordController.text,
+                      nameController.text
+                      ),
+                      style: ElevatedButton.styleFrom(//todo putih lage
+                        backgroundColor: Colors.black, 
+                        side: BorderSide(color: Colors.white),
+                        shape: RoundedRectangleBorder(
+                          borderRadius: BorderRadius.circular(12.0),
+                        ),
+                      ),
+                      child: Text(
+                        'Save',
+                        style: TextStyle(color: Colors.white),
                       ),
-                    ),
-                    child: Text(
-                      'Save',
-                      style: TextStyle(color: Colors.white),
                     ),
                   ),
                 ),
-              ),
-            ],
-          ),
-        ],
+              ],
+            ),
+          ],
+        ),
       ),
       bottomNavigationBar: Footer(),
     );
+     
   }
+
+ 
 }

+ 2 - 0
macos/Flutter/GeneratedPluginRegistrant.swift

@@ -5,6 +5,8 @@
 import FlutterMacOS
 import Foundation
 
+import shared_preferences_foundation
 
 func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
+  SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
 }

+ 133 - 5
pubspec.lock

@@ -53,10 +53,10 @@ packages:
     dependency: "direct main"
     description:
       name: dio
-      sha256: "49af28382aefc53562459104f64d16b9dfd1e8ef68c862d5af436cc8356ce5a8"
+      sha256: "50fec96118958b97c727d0d8f67255d3683f16cc1f90d9bc917b5d4fe3abeca9"
       url: "https://pub.dev"
     source: hosted
-    version: "5.4.1"
+    version: "5.4.2"
   dotted_line:
     dependency: "direct main"
     description:
@@ -89,6 +89,22 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "1.3.1"
+  ffi:
+    dependency: transitive
+    description:
+      name: ffi
+      sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21"
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.1.2"
+  file:
+    dependency: transitive
+    description:
+      name: file
+      sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c"
+      url: "https://pub.dev"
+    source: hosted
+    version: "7.0.0"
   flutter:
     dependency: "direct main"
     description: flutter
@@ -106,10 +122,10 @@ packages:
     dependency: "direct dev"
     description:
       name: flutter_lints
-      sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7
+      sha256: "9e8c3858111da373efc5aa341de011d9bd23e2c5c5e0c62bccf32438e192d7b1"
       url: "https://pub.dev"
     source: hosted
-    version: "3.0.1"
+    version: "3.0.2"
   flutter_test:
     dependency: "direct dev"
     description: flutter
@@ -232,6 +248,46 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "1.9.0"
+  path_provider_linux:
+    dependency: transitive
+    description:
+      name: path_provider_linux
+      sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.2.1"
+  path_provider_platform_interface:
+    dependency: transitive
+    description:
+      name: path_provider_platform_interface
+      sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334"
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.1.2"
+  path_provider_windows:
+    dependency: transitive
+    description:
+      name: path_provider_windows
+      sha256: "8bc9f22eee8690981c22aa7fc602f5c85b497a6fb2ceb35ee5a5e5ed85ad8170"
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.2.1"
+  platform:
+    dependency: transitive
+    description:
+      name: platform
+      sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec"
+      url: "https://pub.dev"
+    source: hosted
+    version: "3.1.4"
+  plugin_platform_interface:
+    dependency: transitive
+    description:
+      name: plugin_platform_interface
+      sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.1.8"
   provider:
     dependency: "direct main"
     description:
@@ -248,6 +304,62 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "3.2.1"
+  shared_preferences:
+    dependency: "direct main"
+    description:
+      name: shared_preferences
+      sha256: "81429e4481e1ccfb51ede496e916348668fd0921627779233bd24cc3ff6abd02"
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.2.2"
+  shared_preferences_android:
+    dependency: transitive
+    description:
+      name: shared_preferences_android
+      sha256: "8568a389334b6e83415b6aae55378e158fbc2314e074983362d20c562780fb06"
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.2.1"
+  shared_preferences_foundation:
+    dependency: transitive
+    description:
+      name: shared_preferences_foundation
+      sha256: "7708d83064f38060c7b39db12aefe449cb8cdc031d6062280087bc4cdb988f5c"
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.3.5"
+  shared_preferences_linux:
+    dependency: transitive
+    description:
+      name: shared_preferences_linux
+      sha256: "9f2cbcf46d4270ea8be39fa156d86379077c8a5228d9dfdb1164ae0bb93f1faa"
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.3.2"
+  shared_preferences_platform_interface:
+    dependency: transitive
+    description:
+      name: shared_preferences_platform_interface
+      sha256: "22e2ecac9419b4246d7c22bfbbda589e3acf5c0351137d87dd2939d984d37c3b"
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.3.2"
+  shared_preferences_web:
+    dependency: transitive
+    description:
+      name: shared_preferences_web
+      sha256: "9aee1089b36bd2aafe06582b7d7817fd317ef05fc30e6ba14bff247d0933042a"
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.3.0"
+  shared_preferences_windows:
+    dependency: transitive
+    description:
+      name: shared_preferences_windows
+      sha256: "841ad54f3c8381c480d0c9b508b89a34036f512482c407e6df7a9c4aa2ef8f59"
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.3.2"
   sky_engine:
     dependency: transitive
     description: flutter
@@ -349,6 +461,22 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "0.5.1"
+  win32:
+    dependency: transitive
+    description:
+      name: win32
+      sha256: "8cb58b45c47dcb42ab3651533626161d6b67a2921917d8d429791f76972b3480"
+      url: "https://pub.dev"
+    source: hosted
+    version: "5.3.0"
+  xdg_directories:
+    dependency: transitive
+    description:
+      name: xdg_directories
+      sha256: faea9dee56b520b55a566385b84f2e8de55e7496104adada9962e0bd11bcff1d
+      url: "https://pub.dev"
+    source: hosted
+    version: "1.0.4"
 sdks:
   dart: ">=3.3.0 <4.0.0"
-  flutter: ">=3.16.0"
+  flutter: ">=3.19.0"

+ 6 - 2
pubspec.yaml

@@ -21,14 +21,18 @@ dependencies:
   timeline_tile: ^2.0.0
   lint: ^2.3.0  
   dropdown_button2: ^2.3.9
-  dio: ^5.4.1
+  dio: ^5.4.2
   http: ^1.2.1
+  shared_preferences: ^2.2.2
+
+my_storage:
+  path: '../my_storage'
 
 dev_dependencies:
   flutter_test:
     sdk: flutter
 
-  flutter_lints: ^3.0.1
+  flutter_lints: ^3.0.2
 
 flutter:
   uses-material-design: true