ft/adds automatic download of data in initState
and more
This commit is contained in:
parent
35d8ed0221
commit
a8377110bb
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:fixnum/fixnum.dart';
|
||||||
import 'package:app/pb/rpc_create_account.pb.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_get_account_info.pb.dart';
|
||||||
import 'package:app/pb/rpc_login.pb.dart';
|
import 'package:app/pb/rpc_login.pb.dart';
|
||||||
@ -8,8 +9,9 @@ class Client {
|
|||||||
String baseUrl = 'localhost';
|
String baseUrl = 'localhost';
|
||||||
int port = 9090;
|
int port = 9090;
|
||||||
|
|
||||||
Map<String, dynamic> metadata = {'Authorization': ''};
|
Map<String, String> metadata = {'Authorization': ''};
|
||||||
String accessToken = '';
|
String accessToken = '';
|
||||||
|
Int64 accountId = Int64();
|
||||||
|
|
||||||
dfClient stub = dfClient(
|
dfClient stub = dfClient(
|
||||||
ClientChannel('10.0.2.2',
|
ClientChannel('10.0.2.2',
|
||||||
@ -25,7 +27,6 @@ class Client {
|
|||||||
|
|
||||||
Future<CreateAccountResponse> createAccount(
|
Future<CreateAccountResponse> createAccount(
|
||||||
CreateAccountRequest request) async {
|
CreateAccountRequest request) async {
|
||||||
// CreateAccountResponse response;
|
|
||||||
try {
|
try {
|
||||||
final response = stub.createAccount(request);
|
final response = stub.createAccount(request);
|
||||||
return response;
|
return response;
|
||||||
@ -47,6 +48,7 @@ class Client {
|
|||||||
password: password,
|
password: password,
|
||||||
));
|
));
|
||||||
accessToken = response.accessToken;
|
accessToken = response.accessToken;
|
||||||
|
accountId = response.accountId;
|
||||||
metadata['Authorization'] = 'Bearer ${response.accessToken}';
|
metadata['Authorization'] = 'Bearer ${response.accessToken}';
|
||||||
print('auth: ${metadata['Authorization']}');
|
print('auth: ${metadata['Authorization']}');
|
||||||
onSuccess();
|
onSuccess();
|
||||||
@ -64,9 +66,9 @@ class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<GetAccountInfoResponse> getAccountInfo(GetAccountInfoRequest request,
|
Future<GetAccountInfoResponse> getAccountInfo(GetAccountInfoRequest request,
|
||||||
{required String token, required Function onError}) async {
|
{required Function onError}) async {
|
||||||
try {
|
try {
|
||||||
Map<String, String> metadata = {'Authorization': 'Bearer $token'};
|
// Map<String, String> metadata = {'Authorization': 'Bearer $token'};
|
||||||
final response = await stub.getAccountInfo(
|
final response = await stub.getAccountInfo(
|
||||||
request,
|
request,
|
||||||
options: CallOptions(
|
options: CallOptions(
|
||||||
|
@ -8,6 +8,19 @@ void main() async {
|
|||||||
runApp(
|
runApp(
|
||||||
MaterialApp(
|
MaterialApp(
|
||||||
theme: ThemeData().copyWith(
|
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(
|
textTheme: const TextTheme().copyWith(
|
||||||
titleLarge: const TextStyle(
|
titleLarge: const TextStyle(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
@ -21,7 +34,7 @@ void main() async {
|
|||||||
),
|
),
|
||||||
inputDecorationTheme: const InputDecorationTheme(
|
inputDecorationTheme: const InputDecorationTheme(
|
||||||
labelStyle: TextStyle(
|
labelStyle: TextStyle(
|
||||||
color: Colors.white,
|
color: Colors.grey,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
scaffoldBackgroundColor: Colors.transparent,
|
scaffoldBackgroundColor: Colors.transparent,
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import 'package:app/gapi/client.dart';
|
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/background.dart';
|
||||||
|
import 'package:app/widgets/loading_widget.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class DashboardPage extends StatefulWidget {
|
class DashboardPage extends StatefulWidget {
|
||||||
@ -13,6 +16,7 @@ class DashboardPage extends StatefulWidget {
|
|||||||
|
|
||||||
class _DashboardPageState extends State<DashboardPage> {
|
class _DashboardPageState extends State<DashboardPage> {
|
||||||
bool _loading = false;
|
bool _loading = false;
|
||||||
|
late AccountInfo accountInfo;
|
||||||
|
|
||||||
void _setLoading(bool loading) {
|
void _setLoading(bool loading) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -25,16 +29,68 @@ class _DashboardPageState extends State<DashboardPage> {
|
|||||||
super.initState();
|
super.initState();
|
||||||
if (widget.client.accessToken == '') {
|
if (widget.client.accessToken == '') {
|
||||||
Navigator.of(context).pop();
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
print(widget.client.accessToken);
|
print(widget.client.accessToken);
|
||||||
return Scaffold(
|
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(
|
appBar: AppBar(
|
||||||
automaticallyImplyLeading: false,
|
automaticallyImplyLeading: false,
|
||||||
// backgroundColor: Colors.black,
|
|
||||||
flexibleSpace: Image.asset(
|
flexibleSpace: Image.asset(
|
||||||
'lib/assets/logo_300x200.png',
|
'lib/assets/logo_300x200.png',
|
||||||
height: 80,
|
height: 80,
|
||||||
@ -52,18 +108,25 @@ class _DashboardPageState extends State<DashboardPage> {
|
|||||||
// ),
|
// ),
|
||||||
// ],
|
// ],
|
||||||
),
|
),
|
||||||
body: Background(
|
body: !_loading
|
||||||
child: Column(
|
? Background(
|
||||||
children: [
|
child: Center(
|
||||||
Text(
|
child: Column(
|
||||||
widget.client.accessToken,
|
children: [
|
||||||
style: const TextStyle(
|
const SizedBox(
|
||||||
color: Colors.white,
|
height: 48,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
'Willkommen ${accountInfo.firstname} ${accountInfo.lastname}!',
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 24,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
],
|
: const LoadingWidget(),
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'package:app/gapi/client.dart';
|
import 'package:app/gapi/client.dart';
|
||||||
import 'package:app/pages/dashboard_page.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';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class LoginPage extends StatefulWidget {
|
class LoginPage extends StatefulWidget {
|
||||||
@ -25,28 +25,6 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
final mailController = TextEditingController();
|
final mailController = TextEditingController();
|
||||||
final passwordController = TextEditingController();
|
final passwordController = TextEditingController();
|
||||||
|
|
||||||
// @override
|
|
||||||
// void initState() {
|
|
||||||
// super.initState();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Future<String> _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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@ -56,18 +34,27 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
'lib/assets/logo_300x200.png',
|
'lib/assets/logo_300x200.png',
|
||||||
height: 80,
|
height: 80,
|
||||||
),
|
),
|
||||||
// actions: [
|
),
|
||||||
// IconButton(
|
bottomNavigationBar: BottomNavigationBar(
|
||||||
// onPressed: () {},
|
items: const [
|
||||||
// icon: const Icon(Icons.menu),
|
BottomNavigationBarItem(
|
||||||
// tooltip: 'Menu',
|
label: 'Zurueck',
|
||||||
// ),
|
backgroundColor: Colors.white,
|
||||||
// IconButton(
|
icon: Icon(
|
||||||
// onPressed: () {},
|
Icons.arrow_back,
|
||||||
// icon: const Icon(Icons.login_sharp),
|
color: Colors.white,
|
||||||
// tooltip: 'Login',
|
),
|
||||||
// ),
|
),
|
||||||
// ],
|
BottomNavigationBarItem(
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
label: 'AccountInf',
|
||||||
|
icon: Icon(
|
||||||
|
Icons.person,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
),
|
),
|
||||||
body: !_loading
|
body: !_loading
|
||||||
? Form(
|
? Form(
|
||||||
@ -77,9 +64,9 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
TextFormField(
|
TextFormField(
|
||||||
style: TextStyle(
|
// style: TextStyle(
|
||||||
color: Theme.of(context).colorScheme.primary,
|
// color: Theme.of(context).colorScheme.primary,
|
||||||
),
|
// ),
|
||||||
controller: mailController,
|
controller: mailController,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
fillColor: Color.fromARGB(30, 255, 255, 255),
|
fillColor: Color.fromARGB(30, 255, 255, 255),
|
||||||
@ -164,15 +151,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
: Column(
|
: const LoadingWidget(),
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Image.asset(
|
|
||||||
'lib/assets/logo_300x200.png',
|
|
||||||
height: 300,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
frontend/app/lib/widgets/loading_widget.dart
Normal file
17
frontend/app/lib/widgets/loading_widget.dart
Normal file
@ -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,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user