rf/replaces home_screen and login

backs up old screens to pages_old
This commit is contained in:
itsscb 2023-11-04 01:44:49 +01:00
parent 5f0e46a1b8
commit 7750972a42
14 changed files with 490 additions and 21 deletions

View File

@ -14,9 +14,7 @@ class Session {
this.refreshToken,
this.refreshTokenExpiresAt,
this.accountId,
}) {
_init();
}
});
String? sessionId;
String? accessToken;
@ -169,12 +167,14 @@ class Session {
final db = await database;
final List<Map<String, Object?>> maps = await db.query('sessions');
print(maps);
final List<Session> sessions = List.generate(
maps.length,
(i) {
// print('GOT MAP: ${maps[i]}');
if (maps[i]['sessionId'] == null) {
return Session();
}
return Session(
sessionId: maps[i]['sessionId'] as String,
accessToken: maps[i]['accessToken'] as String,

View File

@ -1,6 +1,4 @@
import 'package:app/gapi/client.dart';
import 'package:app/pages/start_page.dart';
import 'package:app/widgets/background.dart';
import 'package:app/pages/home_page.dart';
import 'package:flutter/material.dart';
void main() async {
@ -43,11 +41,7 @@ void main() async {
backgroundColor: Colors.black,
foregroundColor: Colors.white,
)),
home: Background(
child: StartPage(
// client: await GClient.client,
),
),
home: const HomePage(),
),
);
}

View File

@ -202,7 +202,15 @@ class BackendService {
password: password,
),
);
await Session.newSession(response as Session);
Session s = Session(
accessToken: response.accessToken,
sessionId: response.sessionId,
accessTokenExpiresAt: response.accessTokenExpiresAt,
refreshToken: response.refreshToken,
refreshTokenExpiresAt: response.refreshTokenExpiresAt,
accountId: response.accountId,
);
await Session.newSession(s);
return response.accessToken != '';
} on SocketException {
throw FetchDataException('Keine Internet Verbindung');

View File

@ -0,0 +1,160 @@
import 'dart:io';
import 'package:app/model/services/backend_service.dart';
import 'package:app/model/view_model/account_vm.dart';
import 'package:app/pages/login_overlay.dart';
import 'package:app/widgets/background.dart';
import 'package:app/widgets/bottom_navigation.dart';
import 'package:app/widgets/bottom_navigation_item.dart';
import 'package:app/widgets/drawer.dart';
import 'package:app/widgets/side_drawer_item.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
void initState() {
super.initState();
_init();
}
void _init() async {
_setLoading(true);
_loggedin = await BackendService.isLoggedIn;
_setLoading(false);
}
void _setLoading(bool loading) {
setState(() {
_loading = loading;
});
}
bool _loading = true;
bool _loggedin = false;
@override
Widget build(BuildContext context) {
return Background(
child: ChangeNotifierProvider<AccountViewModel>(
create: (context) => AccountViewModel(),
child: Consumer<AccountViewModel>(
builder: (context, value, child) => Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
// flexibleSpace: Image.asset(
// 'lib/assets/logo_300x200.png',
// // height: 400,
// ),
),
drawer: SideDrawer(
children: [
const Spacer(
flex: 3,
),
SideDrawerItem(
onPressed: () {},
icon: Icons.question_answer,
color: Colors.white,
label: 'About',
),
SideDrawerItem(
onPressed: () {},
icon: Icons.privacy_tip,
color: Colors.white,
label: 'Datenschutz',
),
SideDrawerItem(
onPressed: () {},
icon: Icons.apartment,
color: Colors.white,
label: 'Impressum',
),
const Spacer(
flex: 1,
),
if (_loggedin || value.response.data != null)
SideDrawerItem(
onPressed: () {},
icon: Icons.logout,
color: Colors.white,
label: 'Logout',
),
],
),
bottomNavigationBar: BottomNavigation(
children: [
if (!_loggedin) ...[
BottomNavigationItem(
onPressed: () {},
icon: Icons.person_add_alt,
color: Colors.white,
label: 'Registrieren',
),
BottomNavigationItem(
onPressed: () async {
_loggedin = await showLogin(context);
},
icon: Icons.login,
color: Colors.white,
label: 'Login',
),
] else
BottomNavigationItem(
onPressed: () {},
icon: Icons.person_search,
color: Colors.white,
label: 'Personen',
),
BottomNavigationItem(
onPressed: () {},
icon: Icons.dashboard,
color: Colors.white,
label: 'Dashboard',
),
...[]
],
),
body: Padding(
padding: const EdgeInsets.fromLTRB(16, 40, 16, 16),
child: Center(
child: _loading
? const CircularProgressIndicator(
color: Colors.grey,
)
: Column(
children: [
Image.asset(
'lib/assets/logo_300x200.png',
),
const SizedBox(
height: 40,
),
Text(
'Digitale Spuren auf Knopfdruck entfernen'
.toUpperCase(),
textAlign: TextAlign.center,
style: const TextStyle(
fontFamily: 'sans-serif',
fontSize: 24,
height: 1.6,
fontWeight: FontWeight.normal,
letterSpacing: 6,
),
),
],
),
),
),
),
),
),
);
}
}

View File

@ -0,0 +1,134 @@
import 'package:app/model/services/backend_service.dart';
import 'package:app/widgets/background.dart';
import 'package:flutter/material.dart';
Future<bool> showLogin(BuildContext context) async {
final _formKey = GlobalKey<FormState>();
final mailController = TextEditingController();
final passwordController = TextEditingController();
bool _loggedin = false;
await showModalBottomSheet(
useSafeArea: true,
isScrollControlled: true,
backgroundColor: Colors.black,
context: context,
builder: (builder) {
return Background(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(
height: 50,
),
const Image(
width: 180,
image: AssetImage(
'lib/assets/logo_300x200.png',
),
),
const SizedBox(
height: 30,
),
const Text(
'Login',
style: TextStyle(
fontFamily: 'sans-serif',
fontSize: 24,
height: 1.6,
fontWeight: FontWeight.normal,
letterSpacing: 6,
),
),
Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(
height: 40,
),
TextFormField(
controller: mailController,
decoration: const InputDecoration(
fillColor: Color.fromARGB(30, 255, 255, 255),
filled: true,
hintStyle: TextStyle(
color: Colors.white38,
),
hintText: 'E-Mail Adresse',
),
keyboardType: TextInputType.emailAddress,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Bitte eine gültige E-Mail Adresse eingeben';
}
return null;
},
),
TextFormField(
style: const TextStyle(
color: Colors.white,
),
controller: passwordController,
decoration: const InputDecoration(
fillColor: Color.fromARGB(30, 255, 255, 255),
filled: true,
hintStyle: TextStyle(
color: Colors.white38,
),
hintText: 'Passwort',
),
keyboardType: TextInputType.visiblePassword,
obscureText: true,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Bitte geben Sie Ihr Passwort ein';
}
return null;
},
),
const SizedBox(
height: 15,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
child: const Icon(Icons.arrow_back),
),
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
BackendService.login(
email: mailController.text,
password: passwordController.text,
).then(
(r) {
if (r) {
_loggedin = r;
Navigator.pop(context, true);
}
},
);
}
},
child: const Icon(Icons.login),
),
],
)
],
),
),
const Spacer(),
],
),
);
});
return _loggedin;
}

View File

@ -1 +0,0 @@
enum Pages { start, login, about, persons, dashboard }

View File

@ -1,5 +1,5 @@
import 'package:app/gapi/client.dart';
import 'package:app/pages/start_page.dart';
import 'package:app/pages_old/start_page.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';

View File

@ -1,6 +1,6 @@
import 'package:app/gapi/client.dart';
import 'package:app/model/services/backend_service.dart';
import 'package:app/pages/start_page.dart';
import 'package:app/pages_old/start_page.dart';
import 'package:app/widgets/background.dart';
import 'package:app/widgets/bottom_bar.dart';
import 'package:app/widgets/loading_widget.dart';

View File

@ -1,5 +1,5 @@
import 'package:app/gapi/client.dart';
import 'package:app/pages/start_page.dart';
import 'package:app/pages_old/start_page.dart';
import 'package:app/widgets/background.dart';
import 'package:app/widgets/bottom_bar.dart';
import 'package:app/widgets/loading_widget.dart';

View File

@ -1,9 +1,9 @@
import 'package:app/gapi/client.dart';
import 'package:app/model/apis/api_response.dart';
import 'package:app/model/view_model/account_vm.dart';
import 'package:app/pages/dashboard_page.dart';
import 'package:app/pages/login_page.dart';
import 'package:app/pages/register_page.dart';
import 'package:app/pages_old/dashboard_page.dart';
import 'package:app/pages_old/login_page.dart';
import 'package:app/pages_old/register_page.dart';
import 'package:app/pb/account.pb.dart';
import 'package:app/widgets/background.dart';
import 'package:app/widgets/bottom_bar.dart';

View File

@ -0,0 +1,48 @@
import 'package:flutter/material.dart';
class BottomNavigation extends StatelessWidget {
BottomNavigation({
super.key,
required this.children,
this.backgroundColor,
this.iconColor,
}) {
backgroundColor ??= Colors.black;
}
List<Widget> children;
Color? backgroundColor;
Color? iconColor;
@override
Widget build(BuildContext context) {
return Container(
height: 70,
color: backgroundColor,
child: Center(
child: Padding(
padding: const EdgeInsets.symmetric(
// horizontal: 10,
),
child: Row(
mainAxisAlignment: children.isEmpty
? MainAxisAlignment.center
: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
...children,
Builder(builder: (context) {
return IconButton(
onPressed: () => Scaffold.of(context).openDrawer(),
icon: const Icon(
Icons.menu,
color: Colors.white,
));
}),
],
),
),
),
);
}
}

View File

@ -0,0 +1,45 @@
import 'package:flutter/material.dart';
class BottomNavigationItem extends StatelessWidget {
BottomNavigationItem({
super.key,
required this.onPressed,
required this.icon,
required this.color,
this.textSize,
this.iconSize,
this.label,
}) {
textSize ??= 15;
iconSize ??= 25;
}
void Function() onPressed;
IconData icon;
Color color;
double? textSize;
double? iconSize;
String? label;
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment:
label != null ? MainAxisAlignment.center : MainAxisAlignment.center,
children: [
IconButton(
onPressed: onPressed,
icon: Icon(
icon,
size: iconSize,
color: color,
)),
if (label != null)
Text(
label!,
style: TextStyle(fontSize: textSize, color: color),
),
],
);
}
}

View File

@ -0,0 +1,31 @@
import 'package:app/pages/home_page.dart';
import 'package:app/widgets/side_drawer_item.dart';
import 'package:flutter/material.dart';
class SideDrawer extends StatelessWidget {
SideDrawer({super.key, required this.children, this.backgroundColor}) {
backgroundColor ??= Colors.black;
}
List<Widget> children;
Color? backgroundColor;
@override
Widget build(BuildContext context) {
return Drawer(
backgroundColor: backgroundColor,
child: Padding(
padding: const EdgeInsets.all(40.0),
child: Center(
child: Builder(builder: (context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: children,
);
}),
),
),
);
}
}

View File

@ -0,0 +1,50 @@
import 'package:app/pages/home_page.dart';
import 'package:flutter/material.dart';
class SideDrawerItem extends StatelessWidget {
SideDrawerItem({
super.key,
required this.onPressed,
required this.icon,
required this.color,
required this.label,
this.textSize,
this.iconSize,
}) {
textSize ??= 15;
iconSize ??= 25;
}
void Function() onPressed;
IconData icon;
Color color;
String label;
double? textSize;
double? iconSize;
@override
Widget build(BuildContext context) {
return TextButton(
onPressed: onPressed,
child: Row(
// mainAxisAlignment: MainAxisAlignment.start,
children: [
Icon(
icon,
color: color,
),
const SizedBox(
width: 20,
),
Text(
label,
style: TextStyle(
fontSize: textSize,
color: color,
),
)
],
),
);
}
}