Created
November 7, 2022 10:31
-
-
Save sinnoorc/435004ad8446869a8abb50e26ec1374d to your computer and use it in GitHub Desktop.
HomeView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:get/get.dart'; | |
import '../controller/home_controller.dart'; | |
class HomeView extends GetView<HomeController> { | |
const HomeView({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: const Text('Users')), | |
body: SafeArea( | |
child: controller.obx( | |
(state) => ListView.builder( | |
itemCount: state!.length, | |
itemBuilder: (context, index) { | |
final user = state[index]; | |
return ListTile( | |
leading: CircleAvatar( | |
radius: 25, | |
backgroundColor: Colors.white, | |
backgroundImage: NetworkImage(user.image!), | |
), | |
title: Text(user.username!), | |
subtitle: Text(user.email!), | |
trailing: IconButton( | |
icon: const Icon(Icons.delete), | |
onPressed: () => controller.deleteUser(user.id.toString()), | |
), | |
); | |
}, | |
), | |
onLoading: const Center(child: CircularProgressIndicator()), | |
onError: (error) => Center(child: Text(error.toString()))), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment