diff --git a/frontend/app/lib/gapi/client.dart b/frontend/app/lib/gapi/client.dart index 5cd6d75..a27f966 100644 --- a/frontend/app/lib/gapi/client.dart +++ b/frontend/app/lib/gapi/client.dart @@ -1,3 +1,4 @@ +import 'package:fixnum/fixnum.dart'; import 'package:app/pb/rpc_create_account.pb.dart'; import 'package:app/pb/rpc_get_account_info.pb.dart'; import 'package:app/pb/rpc_login.pb.dart'; @@ -8,8 +9,9 @@ class Client { String baseUrl = 'localhost'; int port = 9090; - Map metadata = {'Authorization': ''}; + Map metadata = {'Authorization': ''}; String accessToken = ''; + Int64 accountId = Int64(); dfClient stub = dfClient( ClientChannel('10.0.2.2', @@ -25,7 +27,6 @@ class Client { Future createAccount( CreateAccountRequest request) async { - // CreateAccountResponse response; try { final response = stub.createAccount(request); return response; @@ -47,6 +48,7 @@ class Client { password: password, )); accessToken = response.accessToken; + accountId = response.accountId; metadata['Authorization'] = 'Bearer ${response.accessToken}'; print('auth: ${metadata['Authorization']}'); onSuccess(); @@ -64,9 +66,9 @@ class Client { } Future getAccountInfo(GetAccountInfoRequest request, - {required String token, required Function onError}) async { + {required Function onError}) async { try { - Map metadata = {'Authorization': 'Bearer $token'}; + // Map metadata = {'Authorization': 'Bearer $token'}; final response = await stub.getAccountInfo( request, options: CallOptions( diff --git a/frontend/app/lib/main.dart b/frontend/app/lib/main.dart index 20d7689..537dffe 100644 --- a/frontend/app/lib/main.dart +++ b/frontend/app/lib/main.dart @@ -8,6 +8,19 @@ void main() async { runApp( MaterialApp( theme: ThemeData().copyWith( + colorScheme: const ColorScheme( + brightness: Brightness.dark, + primary: Colors.white, + onPrimary: Colors.black, + secondary: Colors.black, + onSecondary: Colors.white, + error: Color.fromARGB(170, 255, 0, 0), + onError: Color.fromARGB(170, 255, 0, 0), + background: Colors.transparent, + onBackground: Colors.white, + surface: Colors.black, + onSurface: Colors.white, + ), textTheme: const TextTheme().copyWith( titleLarge: const TextStyle( color: Colors.white, @@ -21,7 +34,7 @@ void main() async { ), inputDecorationTheme: const InputDecorationTheme( labelStyle: TextStyle( - color: Colors.white, + color: Colors.grey, ), ), scaffoldBackgroundColor: Colors.transparent, diff --git a/frontend/app/lib/pages/dashboard_page.dart b/frontend/app/lib/pages/dashboard_page.dart index 46e9562..84bd1d4 100644 --- a/frontend/app/lib/pages/dashboard_page.dart +++ b/frontend/app/lib/pages/dashboard_page.dart @@ -1,5 +1,8 @@ import 'package:app/gapi/client.dart'; +import 'package:app/pb/account_info.pb.dart'; +import 'package:app/pb/rpc_get_account_info.pb.dart'; import 'package:app/widgets/background.dart'; +import 'package:app/widgets/loading_widget.dart'; import 'package:flutter/material.dart'; class DashboardPage extends StatefulWidget { @@ -13,6 +16,7 @@ class DashboardPage extends StatefulWidget { class _DashboardPageState extends State { bool _loading = false; + late AccountInfo accountInfo; void _setLoading(bool loading) { setState(() { @@ -25,16 +29,68 @@ class _DashboardPageState extends State { super.initState(); if (widget.client.accessToken == '') { Navigator.of(context).pop(); + return; } + + _setLoading(true); + widget.client.getAccountInfo( + GetAccountInfoRequest( + accountId: widget.client.accountId, + ), + onError: () { + ScaffoldMessenger.of(context).showSnackBar(const SnackBar( + content: Text('AccountInfo konnte nicht geladen werden'), + )); + }, + ).then((value) { + accountInfo = value.accountInfo; + _setLoading(false); + }); } @override Widget build(BuildContext context) { print(widget.client.accessToken); return Scaffold( + bottomNavigationBar: BottomNavigationBar( + items: const [ + BottomNavigationBarItem( + label: '', + backgroundColor: Colors.white, + icon: Icon( + Icons.arrow_back, + color: Colors.white, + ), + ), + BottomNavigationBarItem( + backgroundColor: Colors.white, + label: '', + icon: Icon( + Icons.person, + color: Colors.white, + ), + ), + BottomNavigationBarItem( + backgroundColor: Colors.white, + label: '', + icon: Icon( + Icons.group, + color: Colors.white, + ), + ), + BottomNavigationBarItem( + backgroundColor: Colors.white, + label: '', + icon: Icon( + Icons.file_copy, + color: Colors.white, + ), + ), + ], + backgroundColor: Colors.transparent, + ), appBar: AppBar( automaticallyImplyLeading: false, - // backgroundColor: Colors.black, flexibleSpace: Image.asset( 'lib/assets/logo_300x200.png', height: 80, @@ -52,18 +108,25 @@ class _DashboardPageState extends State { // ), // ], ), - body: Background( - child: Column( - children: [ - Text( - widget.client.accessToken, - style: const TextStyle( - color: Colors.white, + body: !_loading + ? Background( + child: Center( + child: Column( + children: [ + const SizedBox( + height: 48, + ), + Text( + 'Willkommen ${accountInfo.firstname} ${accountInfo.lastname}!', + style: const TextStyle( + fontSize: 24, + ), + ), + ], + ), ), - ), - ], - ), - ), + ) + : const LoadingWidget(), ); } } diff --git a/frontend/app/lib/pages/login_page.dart b/frontend/app/lib/pages/login_page.dart index 3656ab4..89ddd00 100644 --- a/frontend/app/lib/pages/login_page.dart +++ b/frontend/app/lib/pages/login_page.dart @@ -1,6 +1,6 @@ import 'package:app/gapi/client.dart'; import 'package:app/pages/dashboard_page.dart'; -import 'package:app/pb/rpc_login.pb.dart'; +import 'package:app/widgets/loading_widget.dart'; import 'package:flutter/material.dart'; class LoginPage extends StatefulWidget { @@ -25,28 +25,6 @@ class _LoginPageState extends State { final mailController = TextEditingController(); final passwordController = TextEditingController(); - // @override - // void initState() { - // super.initState(); - // } - - // Future _login( - // {required BuildContext context, - // required String email, - // required String password, - // required Function onSuccess, - // required Function onError}) async { - // LoginResponse r = await client.login( - // LoginRequest( - // email: email, - // password: password, - // ), - // onError: onError, - // onSuccess: onSuccess, - // ); - // return r.accessToken; - // } - @override Widget build(BuildContext context) { return Scaffold( @@ -56,18 +34,27 @@ class _LoginPageState extends State { 'lib/assets/logo_300x200.png', height: 80, ), - // actions: [ - // IconButton( - // onPressed: () {}, - // icon: const Icon(Icons.menu), - // tooltip: 'Menu', - // ), - // IconButton( - // onPressed: () {}, - // icon: const Icon(Icons.login_sharp), - // tooltip: 'Login', - // ), - // ], + ), + bottomNavigationBar: BottomNavigationBar( + items: const [ + BottomNavigationBarItem( + label: 'Zurueck', + backgroundColor: Colors.white, + icon: Icon( + Icons.arrow_back, + color: Colors.white, + ), + ), + BottomNavigationBarItem( + backgroundColor: Colors.white, + label: 'AccountInf', + icon: Icon( + Icons.person, + color: Colors.white, + ), + ), + ], + backgroundColor: Colors.transparent, ), body: !_loading ? Form( @@ -77,9 +64,9 @@ class _LoginPageState extends State { crossAxisAlignment: CrossAxisAlignment.center, children: [ TextFormField( - style: TextStyle( - color: Theme.of(context).colorScheme.primary, - ), + // style: TextStyle( + // color: Theme.of(context).colorScheme.primary, + // ), controller: mailController, decoration: const InputDecoration( fillColor: Color.fromARGB(30, 255, 255, 255), @@ -164,15 +151,7 @@ class _LoginPageState extends State { ], ), ) - : Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Image.asset( - 'lib/assets/logo_300x200.png', - height: 300, - ), - ], - ), + : const LoadingWidget(), ); } } diff --git a/frontend/app/lib/widgets/loading_widget.dart b/frontend/app/lib/widgets/loading_widget.dart new file mode 100644 index 0000000..567fbec --- /dev/null +++ b/frontend/app/lib/widgets/loading_widget.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +class LoadingWidget extends StatelessWidget { + const LoadingWidget({ + super.key, + }); + + @override + Widget build(BuildContext context) { + return Center( + child: Image.asset( + 'lib/assets/logo_300x200.png', + height: 300, + ), + ); + } +}