You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

41 lines
1.2 KiB

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
class UserListPage extends ConsumerWidget {
const UserListPage({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final usersAsync = ref.watch(usersProvider);
return Scaffold(
appBar: AppBar(title: const Text('用户管理')),
body: usersAsync.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (error, stack) => Center(child: Text('Error: $error')),
data: (users) => ListView.builder(
itemCount: users.length,
itemBuilder: (context, index) {
final user = users[index];
return ListTile(
title: Text(user['username']),
subtitle: Text(user['email']),
trailing: IconButton(
icon: const Icon(Icons.edit),
onPressed: () {
// 编辑用户
},
),
);
},
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
// 添加用户
},
child: const Icon(Icons.add),
),
);
}
}