Skip to content

Commit

Permalink
refactor: extract user display logic into UserBar widget for offline …
Browse files Browse the repository at this point in the history
…access of settings and logs
  • Loading branch information
Dr-Blank committed Oct 3, 2024
1 parent f6cfff5 commit fd10791
Showing 1 changed file with 43 additions and 46 deletions.
89 changes: 43 additions & 46 deletions lib/features/you/view/you_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:shelfsdk/audiobookshelf_api.dart';
import 'package:vaani/api/api_provider.dart';
import 'package:vaani/router/router.dart';
import 'package:vaani/shared/utils.dart';
Expand All @@ -12,27 +11,6 @@ class YouPage extends HookConsumerWidget {
super.key,
});

@override
Widget build(BuildContext context, WidgetRef ref) {
final me = ref.watch(meProvider);
return me.when(
data: (data) {
return _YouPage(userData: data);
},
loading: () => const CircularProgressIndicator(),
error: (error, stack) => Text('Error: $error'),
);
}
}

class _YouPage extends HookConsumerWidget {
const _YouPage({
super.key,
required this.userData,
});

final User userData;

@override
Widget build(BuildContext context, WidgetRef ref) {
final api = ref.watch(authenticatedApiProvider);
Expand Down Expand Up @@ -71,30 +49,7 @@ class _YouPage extends HookConsumerWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
CircleAvatar(
radius: 40,
// backgroundImage: NetworkImage(userData.avatarUrl),
// first letter of the username
child: Text(
userData.username[0].toUpperCase(),
style: const TextStyle(
fontSize: 32,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(width: 16),
Text(
userData.username,
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
],
),
UserBar(),
const SizedBox(height: 16),
Wrap(
spacing: 8,
Expand Down Expand Up @@ -169,3 +124,45 @@ class _YouPage extends HookConsumerWidget {
);
}
}

class UserBar extends HookConsumerWidget {
const UserBar({
super.key,
});

@override
Widget build(BuildContext context, WidgetRef ref) {
final me = ref.watch(meProvider);

return me.when(
data: (userData) {
return Row(
children: [
CircleAvatar(
radius: 40,
// backgroundImage: NetworkImage(userData.avatarUrl),
// first letter of the username
child: Text(
userData.username[0].toUpperCase(),
style: const TextStyle(
fontSize: 32,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(width: 16),
Text(
userData.username,
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
],
);
},
loading: () => const CircularProgressIndicator(),
error: (error, stack) => Text('Error: $error'),
);
}
}

0 comments on commit fd10791

Please sign in to comment.