Skip to content

Commit

Permalink
Access profile screen from home
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Nov 17, 2023
1 parent 1dab6a6 commit 3a1e66e
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 174 deletions.
16 changes: 8 additions & 8 deletions lib/src/navigation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'package:lichess_mobile/src/view/watch/watch_tab_screen.dart';
import 'package:lichess_mobile/src/view/puzzle/puzzle_tab_screen.dart';

enum BottomTab {
home(Icons.home),
play(Icons.home),
puzzles(PuzzleIcons.mix),
tools(CupertinoIcons.wrench),
watch(Icons.live_tv);
Expand All @@ -25,8 +25,8 @@ enum BottomTab {

String label(AppLocalizations strings) {
switch (this) {
case BottomTab.home:
return 'Home';
case BottomTab.play:
return strings.play;
case BottomTab.puzzles:
return strings.puzzles;
case BottomTab.tools:
Expand All @@ -38,12 +38,12 @@ enum BottomTab {
}

final currentBottomTabProvider =
StateProvider<BottomTab>((ref) => BottomTab.home);
StateProvider<BottomTab>((ref) => BottomTab.play);

final currentNavigatorKeyProvider = Provider<GlobalKey<NavigatorState>>((ref) {
final currentTab = ref.watch(currentBottomTabProvider);
switch (currentTab) {
case BottomTab.home:
case BottomTab.play:
return homeNavigatorKey;
case BottomTab.puzzles:
return puzzlesNavigatorKey;
Expand All @@ -57,7 +57,7 @@ final currentNavigatorKeyProvider = Provider<GlobalKey<NavigatorState>>((ref) {
final currentRootScrollControllerProvider = Provider<ScrollController>((ref) {
final currentTab = ref.watch(currentBottomTabProvider);
switch (currentTab) {
case BottomTab.home:
case BottomTab.play:
return homeScrollController;
case BottomTab.puzzles:
return puzzlesScrollController;
Expand Down Expand Up @@ -109,7 +109,7 @@ class BottomNavScaffold extends ConsumerWidget {
final currentTab = ref.watch(currentBottomTabProvider);
final isHomeRoot = ref.watch(isHomeRootProvider);
final tabs = ref.watch(tabsProvider);
final shouldRemoveTabBarBorder = currentTab == BottomTab.home && isHomeRoot;
final shouldRemoveTabBarBorder = currentTab == BottomTab.play && isHomeRoot;

switch (defaultTargetPlatform) {
case TargetPlatform.android:
Expand Down Expand Up @@ -219,7 +219,7 @@ class BottomNavScaffold extends ConsumerWidget {
switch (index) {
case 0:
return CupertinoTabView(
defaultTitle: 'Home',
defaultTitle: context.l10n.play,
navigatorKey: homeNavigatorKey,
navigatorObservers: [homeRouteObserver],
builder: (context) => const HomeTabScreen(),
Expand Down
158 changes: 158 additions & 0 deletions lib/src/view/account/profile_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'package:lichess_mobile/src/styles/styles.dart';
import 'package:lichess_mobile/src/model/account/account_repository.dart';
import 'package:lichess_mobile/src/widgets/feedback.dart';
import 'package:lichess_mobile/src/widgets/platform.dart';
import 'package:lichess_mobile/src/widgets/player.dart';
import 'package:lichess_mobile/src/widgets/shimmer.dart';
import 'package:lichess_mobile/src/view/user/user_profile.dart';
import 'package:lichess_mobile/src/view/user/recent_games.dart';
import 'package:lichess_mobile/src/view/user/perf_cards.dart';
import 'package:lichess_mobile/src/view/user/user_activity.dart';

class ProfileScreen extends ConsumerWidget {
const ProfileScreen({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
return ConsumerPlatformWidget(
ref: ref,
androidBuilder: _buildAndroid,
iosBuilder: _buildIos,
);
}

Widget _buildAndroid(BuildContext context, WidgetRef ref) {
final account = ref.watch(accountProvider);
return Scaffold(
appBar: AppBar(
title: account.when(
data: (user) => user == null
? const SizedBox.shrink()
: PlayerTitle(
userName: user.username,
title: user.title,
isPatron: user.isPatron,
),
loading: () => const SizedBox.shrink(),
error: (error, _) => const SizedBox.shrink(),
),
),
body: account.when(
data: (user) {
if (user == null) {
return const Center(
child: Text('You must be logged in to view this page.'),
);
}
return ListView(
children: [
UserProfile(user: user),
const _PerfCards(),
const UserActivityWidget(),
const RecentGames(),
],
);
},
loading: () => const Center(child: CircularProgressIndicator()),
error: (error, _) {
return FullScreenRetryRequest(
onRetry: () => ref.invalidate(accountProvider),
);
},
),
);
}

Widget _buildIos(BuildContext context, WidgetRef ref) {
final account = ref.watch(accountProvider);
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: account.when(
data: (user) => user == null
? const SizedBox.shrink()
: PlayerTitle(
userName: user.username,
title: user.title,
isPatron: user.isPatron,
),
loading: () => const SizedBox.shrink(),
error: (error, _) => const SizedBox.shrink(),
),
),
child: account.when(
data: (user) {
if (user == null) {
return const Center(
child: Text('You must be logged in to view this page.'),
);
}
return SafeArea(
child: ListView(
children: [
UserProfile(user: user),
const _PerfCards(),
const UserActivityWidget(),
const RecentGames(),
],
),
);
},
loading: () =>
const Center(child: CircularProgressIndicator.adaptive()),
error: (error, _) {
return FullScreenRetryRequest(
onRetry: () => ref.invalidate(accountProvider),
);
},
),
);
}
}

class _PerfCards extends ConsumerWidget {
const _PerfCards();

@override
Widget build(BuildContext context, WidgetRef ref) {
final account = ref.watch(accountProvider);
return account.when(
data: (user) {
if (user != null) {
return PerfCards(user: user);
} else {
return const SizedBox.shrink();
}
},
loading: () => Shimmer(
child: Padding(
padding: Styles.bodySectionPadding,
child: SizedBox(
height: 106,
child: ListView.separated(
padding: const EdgeInsets.symmetric(vertical: 3.0),
scrollDirection: Axis.horizontal,
itemCount: 5,
separatorBuilder: (context, index) => const SizedBox(width: 10),
itemBuilder: (context, index) => ShimmerLoading(
isLoading: true,
child: Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(10.0),
),
),
),
),
),
),
),
error: (error, stack) => const SizedBox.shrink(),
);
}
}
Loading

0 comments on commit 3a1e66e

Please sign in to comment.