// 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/footer.dart'; import 'package:namer_app/globals.dart'; import 'package:namer_app/header.dart'; import '../service/delete_user.dart'; class ListUserPage extends StatefulWidget { const ListUserPage({super.key}); @override State createState() => _ListUserPageState(); } class _ListUserPageState extends State { 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( appBar: CustomAppbar(), body: Stack(children: [ SingleChildScrollView( child: Column( children: [ Center( child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( 'LIST USER', style: TextStyle(color: Colors.black, fontSize: 48), ), ], )), Column( 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]), ), )) ), ], ), ), ]), bottomNavigationBar: Footer(), ); } } class ButtonUser extends StatelessWidget { final Map items; ButtonUser({ required this.items, super.key, }); @override Widget build(BuildContext context) { return Row( mainAxisSize: MainAxisSize.min, children: [ ElevatedButton( onPressed: () => context.go("/signup/listuser/edit/$items['id']"), style: ElevatedButton.styleFrom( backgroundColor: Colors.black, ), child: Text( 'Edit', style: TextStyle(color: Colors.white), ), ), ElevatedButton( //todo tombol item onPressed: () => deluser(context, items['id']), style: ElevatedButton.styleFrom( backgroundColor: Colors.black, ), child: Text( 'Delete', style: TextStyle(color: Colors.white), ), ), ], ); } }