123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- // 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/footer.dart';
- import 'package:namer_app/header.dart';
- import 'package:namer_app/service/delete_platform.dart';
- import '../globals.dart';
- class ListPlatformPage extends StatefulWidget {
- const ListPlatformPage({super.key});
- @override
- State<ListPlatformPage> createState() => _ListPlatformPageState();
- }
- class _ListPlatformPageState extends State<ListPlatformPage> {
- var jsonList;
- @override
- void initState(){
- getData();
- }
- void getData() async {
- try {
- var response = await Dio()
- .get('http://localhost:8080/api/v1/platforms',
- 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 PLATFORM',
- style: TextStyle(color: Colors.black, fontSize: 48),
- ),
- ],
- )),
- Column(
- children: List.generate(
- jsonList == null ? 0 : jsonList.length,
- (i) => SizedBox(
- child: ListTile(
- leading: SizedBox(
- child: Icon(Icons.phone),
- ),
- title: Text(jsonList[i]['name']),
- subtitle: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(jsonList[i]['project'])
- ],
- ),
- trailing: ButtonUser(
- items: jsonList[i],
- ),
- ),
- )),
- ),
- ],
- ),
- ),
- ]),
- bottomNavigationBar: Footer(),
- );
- }
- }
- class ButtonUser extends StatelessWidget {
- final Map<String, dynamic> items;
- ButtonUser({
- required this.items,
- super.key,
- });
- //todo edit platform
- //todo tombol item
- //todo tombol delete
- @override
- Widget build(BuildContext context) {
- return Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- ElevatedButton(
- onPressed: () => context.go('/listplatform/editplatform'),
- style: ElevatedButton.styleFrom(
- backgroundColor: Colors.black,
- ),
- child: Text(
- 'Edit',
- style: TextStyle(color: Colors.white),
- ),
- ),
- ElevatedButton(
- onPressed: () => delplatform(context, items['id']),
- style: ElevatedButton.styleFrom(
- backgroundColor: Colors.black,
- ),
- child: Text(
- 'Delete',
- style: TextStyle(color: Colors.white),
- ),
- ),
- ],
- );
- }
- }
|