Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
feat: pass username when logging in
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed May 2, 2024
1 parent b51d5fc commit 7214bbf
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
13 changes: 11 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ void main(List<String> argsList) async {
});
}

String? _getUserName(BuildContext context) {
final route = ModalRoute.of(context);
if (route == null) return null;
if (route.settings.arguments == null) return null;

final args = route.settings.arguments as Map<String, dynamic>;
return args['userName'];
}

class GenesisShellApp extends StatelessWidget {
const GenesisShellApp({
super.key,
Expand All @@ -69,8 +78,8 @@ class GenesisShellApp extends StatelessWidget {
),
themeMode: ThemeMode.dark,
routes: {
'/': (_) => const DesktopView(),
'/lock': (_) => const LockView(),
'/': (context) => DesktopView(userName: _getUserName(context)),
'/lock': (context) => LockView(userName: _getUserName(context)),
'/login': (_) => const LoginView(),
},
initialRoute: initLocked ? '/lock' : (displayManager ? '/login' : '/'),
Expand Down
3 changes: 3 additions & 0 deletions lib/views/desktop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ class DesktopView extends StatefulWidget {
this.wallpaper = null,
this.desktopWallpaper = null,
this.mobileWallpaper = null,
this.userName = null,
});

final String? wallpaper;
final String? desktopWallpaper;
final String? mobileWallpaper;
final String? userName;

@override
State<DesktopView> createState() => _DesktopViewState();
Expand Down Expand Up @@ -52,6 +54,7 @@ class _DesktopViewState extends State<DesktopView> {
Widget build(BuildContext context) =>
SystemLayout(
userMode: true,
userName: widget.userName,
body: Container(
decoration: BoxDecoration(
image: getWallpaper(
Expand Down
3 changes: 3 additions & 0 deletions lib/views/lock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ class LockView extends StatelessWidget {
this.wallpaper = null,
this.desktopWallpaper = null,
this.mobileWallpaper = null,
this.userName = null,
});

final String? wallpaper;
final String? desktopWallpaper;
final String? mobileWallpaper;
final String? userName;

@override
Widget build(BuildContext context) =>
SystemLayout(
userMode: true,
isLocked: true,
userName: userName,
body: Container(
decoration: BoxDecoration(
image: getWallpaper(
Expand Down
7 changes: 6 additions & 1 deletion lib/views/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ class _LoginViewState extends State<LoginView> {
LoginPrompt(
onLogin: () {
final nav = Navigator.of(context);
nav.pushNamed('/');
nav.pushNamed(
'/',
arguments: {
'userName': _selectedUser!,
},
);
},
),
const Spacer(),
Expand Down
5 changes: 4 additions & 1 deletion lib/widgets/system_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ class SystemDrawer extends StatefulWidget {
super.key,
this.userMode = false,
this.isLocked = false,
this.userName = null,
});

final bool userMode;
final bool isLocked;
final String? userName;

@override
State<SystemDrawer> createState() => _SystemDrawerState();
Expand All @@ -30,7 +32,8 @@ class _SystemDrawerState extends State<SystemDrawer> {
child: ListView(
shrinkWrap: true,
children: [
widget.userMode && !Breakpoints.small.isActive(context) ? const AccountProfile() : null,
widget.userMode && !Breakpoints.small.isActive(context)
? (widget.userName == null ? AccountProfile() : AccountProfile.name(name: widget.userName!)) : null,
Row(
children: [
Expanded(
Expand Down
7 changes: 5 additions & 2 deletions lib/widgets/system_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ class SystemLayout extends StatelessWidget {
this.isLocked = false,
this.bottomSheet,
this.bottomNavigationBar,
this.userName = null,
});

final Widget body;
final bool userMode;
final bool isLocked;
final Widget? bottomSheet;
final Widget? bottomNavigationBar;
final String? userName;

Widget _buildMobile(BuildContext context) =>
BackdropScaffold(
Expand Down Expand Up @@ -57,9 +59,9 @@ class SystemLayout extends StatelessWidget {
shape: const LinearBorder(),
color: Theme.of(context).colorScheme.background,
margin: EdgeInsets.zero,
child: const Padding(
child: Padding(
padding: const EdgeInsets.all(8),
child: AccountProfile(),
child: userName == null ? AccountProfile() : AccountProfile.name(name: userName!),
),
),
),
Expand Down Expand Up @@ -108,6 +110,7 @@ class SystemLayout extends StatelessWidget {
child: SystemDrawer(
userMode: userMode,
isLocked: isLocked,
userName: userName,
),
),
),
Expand Down

0 comments on commit 7214bbf

Please sign in to comment.