| 12345678910111213141516171819202122232425262728293031323334353637 |
- import 'package:chicken_farm/stores/auth_store.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- class HomePage extends ConsumerWidget {
- const HomePage({super.key});
- @override
- Widget build(BuildContext context, WidgetRef ref) {
- final authState = ref.watch(authStoreProvider);
- final authStore = ref.read(authStoreProvider.notifier);
- return Scaffold(
- appBar: AppBar(
- title: const Text('主页'),
- actions: [
- IconButton(
- icon: const Icon(Icons.logout),
- onPressed: () => authStore.logout(),
- ),
- ],
- ),
- body: Center(child: _buildContent(authState)),
- );
- }
- Widget _buildContent(AuthInfo authState) {
- switch (authState.state) {
- case AuthState.loading:
- return const CircularProgressIndicator();
- case AuthState.unauthenticated:
- return const Text('未登录');
- case AuthState.authenticated:
- return Text('欢迎回来, ${authState.user?.nickName ?? '访客'}!');
- }
- }
- }
|