home.dart 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import 'package:chicken_farm/stores/auth_store.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_riverpod/flutter_riverpod.dart';
  4. class HomePage extends ConsumerWidget {
  5. const HomePage({super.key});
  6. @override
  7. Widget build(BuildContext context, WidgetRef ref) {
  8. final authState = ref.watch(authStoreProvider);
  9. final authStore = ref.read(authStoreProvider.notifier);
  10. return Scaffold(
  11. appBar: AppBar(
  12. title: const Text('主页'),
  13. actions: [
  14. IconButton(
  15. icon: const Icon(Icons.logout),
  16. onPressed: () => authStore.logout(),
  17. ),
  18. ],
  19. ),
  20. body: Center(child: _buildContent(authState)),
  21. );
  22. }
  23. Widget _buildContent(AuthInfo authState) {
  24. switch (authState.state) {
  25. case AuthState.loading:
  26. return const CircularProgressIndicator();
  27. case AuthState.unauthenticated:
  28. return const Text('未登录');
  29. case AuthState.authenticated:
  30. return Text('欢迎回来, ${authState.user?.nickName ?? '访客'}!');
  31. }
  32. }
  33. }