Merge pull request #50 from refilc/dev

Dev
This commit is contained in:
Márton Kiss 2023-09-17 20:21:20 +02:00 committed by GitHub
commit c9da66d38f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 237 additions and 198 deletions

View File

@ -3,7 +3,7 @@ description: "Nem hivatalos e-napló alkalmazás az e-Kréta rendszerhez"
homepage: https://refilc.hu homepage: https://refilc.hu
publish_to: "none" publish_to: "none"
version: 4.2.2+222 version: 4.2.3+223
environment: environment:
sdk: ">=2.17.0 <3.0.0" sdk: ">=2.17.0 <3.0.0"

View File

@ -5,7 +5,6 @@ import 'package:elegant_notification/elegant_notification.dart';
import 'package:elegant_notification/resources/arrays.dart'; import 'package:elegant_notification/resources/arrays.dart';
import 'package:filcnaplo/api/client.dart'; import 'package:filcnaplo/api/client.dart';
import 'package:filcnaplo/api/login.dart'; import 'package:filcnaplo/api/login.dart';
import 'package:filcnaplo/theme/colors/colors.dart';
import 'package:filcnaplo_mobile_ui/screens/login/login_button.dart'; import 'package:filcnaplo_mobile_ui/screens/login/login_button.dart';
import 'package:filcnaplo_mobile_ui/screens/login/login_input.dart'; import 'package:filcnaplo_mobile_ui/screens/login/login_input.dart';
import 'package:filcnaplo_mobile_ui/screens/login/school_input/school_input.dart'; import 'package:filcnaplo_mobile_ui/screens/login/school_input/school_input.dart';
@ -14,6 +13,17 @@ import 'package:flutter/services.dart';
import 'package:flutter_acrylic/flutter_acrylic.dart'; import 'package:flutter_acrylic/flutter_acrylic.dart';
import 'login_screen.i18n.dart'; import 'login_screen.i18n.dart';
const LinearGradient _backgroundGradient = LinearGradient(
colors: [
Color.fromARGB(255, 0, 0, 0),
Color.fromARGB(255, 23, 77, 185),
Color.fromARGB(255, 7, 42, 112),
],
begin: Alignment(-0.8, -2),
end: Alignment(0.8, 1.0),
stops: [-1.0, 0.0, 1.0],
);
class LoginScreen extends StatefulWidget { class LoginScreen extends StatefulWidget {
const LoginScreen({Key? key, this.back = false}) : super(key: key); const LoginScreen({Key? key, this.back = false}) : super(key: key);
@ -70,210 +80,236 @@ class _LoginScreenState extends State<LoginScreen> {
} }
}); });
if (Platform.isMacOS) Window.getTitlebarHeight().then((value) => setState(() => topInset = value)); if (Platform.isMacOS) {
Window.getTitlebarHeight()
.then((value) => setState(() => topInset = value));
}
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
backgroundColor: AppColors.of(context).filc, body: Container(
body: SafeArea( decoration: BoxDecoration(
child: Stack( gradient: _backgroundGradient,
children: [ ),
Row( child: SafeArea(
children: [ child: Stack(
Expanded( children: [
child: Column( Row(
mainAxisAlignment: MainAxisAlignment.center, children: [
children: [ Expanded(
// App logo child: Column(
Padding( mainAxisAlignment: MainAxisAlignment.center,
padding: const EdgeInsets.only(bottom: 24.0), children: [
child: ClipRect( // App logo
child: Padding(
padding: const EdgeInsets.only(left: 12.0, right: 12.0, bottom: 32.0),
child: SizedBox(
width: 82.0,
height: 82.0,
// Png shadow *hack*
child: Stack(
children: [
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Opacity(child: Image.asset("assets/icons/ic_splash.png", color: Colors.black), opacity: 0.3),
),
BackdropFilter(
filter: ImageFilter.blur(sigmaX: 6.0, sigmaY: 6.0),
child: Image.asset("assets/icons/ic_splash.png"),
)
],
),
),
),
),
),
// Inputs
SizedBox(
width: 400.0,
child: AutofillGroup(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Username
Padding(
padding: const EdgeInsets.only(bottom: 6.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
"username".i18n,
maxLines: 1,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 14.0,
),
),
),
Expanded(
child: Text(
"usernameHint".i18n,
maxLines: 1,
textAlign: TextAlign.right,
style: const TextStyle(
color: Colors.white54,
fontWeight: FontWeight.w500,
fontSize: 12.0,
),
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(bottom: 12.0),
child: LoginInput(
style: LoginInputStyle.username,
controller: usernameController,
),
),
// Password
Padding(
padding: const EdgeInsets.only(bottom: 6.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
"password".i18n,
maxLines: 1,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 14.0,
),
),
),
Expanded(
child: Text(
"passwordHint".i18n,
maxLines: 1,
textAlign: TextAlign.right,
style: const TextStyle(
color: Colors.white54,
fontWeight: FontWeight.w500,
fontSize: 12.0,
),
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(bottom: 12.0),
child: LoginInput(
style: LoginInputStyle.password,
controller: passwordController,
),
),
// School
Padding(
padding: const EdgeInsets.only(bottom: 6.0),
child: Text(
"school".i18n,
maxLines: 1,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 14.0,
),
),
),
SchoolInput(
scroll: _scrollController,
controller: schoolController,
),
],
),
),
),
// Log in button
SizedBox(
width: 400.0,
child: Padding(
padding: const EdgeInsets.only(top: 42.0),
child: Visibility(
child: LoginButton(
child: Text("login".i18n,
maxLines: 1,
style: const TextStyle(
fontWeight: FontWeight.w600,
fontSize: 15.0,
)),
onPressed: () => _loginAPI(context: context),
),
visible: _loginState != LoginState.inProgress,
replacement: const Padding(
padding: EdgeInsets.symmetric(vertical: 6.0),
child: Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
),
),
),
),
),
if (_loginState == LoginState.missingFields || _loginState == LoginState.invalidGrant || _loginState == LoginState.failed)
Padding( Padding(
padding: const EdgeInsets.only(top: 8.0), padding: const EdgeInsets.only(bottom: 24.0),
child: Text( child: ClipRect(
["missing_fields", "invalid_grant", "error"][_loginState.index].i18n, child: Padding(
style: const TextStyle(color: Colors.red, fontWeight: FontWeight.w500), padding: const EdgeInsets.only(
left: 12.0, right: 12.0, bottom: 32.0),
child: SizedBox(
width: 100.0,
height: 100.0,
// Png shadow *hack*
child: Stack(
children: [
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Opacity(
child: Image.asset(
"assets/icons/ic_splash.png",
color: Colors.black),
opacity: 0.3),
),
BackdropFilter(
filter: ImageFilter.blur(
sigmaX: 6.0, sigmaY: 6.0),
child: Image.asset(
"assets/icons/ic_splash.png"),
)
],
),
),
),
), ),
), ),
],
// Inputs
SizedBox(
width: 400.0,
child: AutofillGroup(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Username
Padding(
padding: const EdgeInsets.only(bottom: 6.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
"username".i18n,
maxLines: 1,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 14.0,
),
),
),
Expanded(
child: Text(
"usernameHint".i18n,
maxLines: 1,
textAlign: TextAlign.right,
style: const TextStyle(
color: Colors.white54,
fontWeight: FontWeight.w500,
fontSize: 12.0,
),
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(bottom: 12.0),
child: LoginInput(
style: LoginInputStyle.username,
controller: usernameController,
),
),
// Password
Padding(
padding: const EdgeInsets.only(bottom: 6.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
"password".i18n,
maxLines: 1,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 14.0,
),
),
),
Expanded(
child: Text(
"passwordHint".i18n,
maxLines: 1,
textAlign: TextAlign.right,
style: const TextStyle(
color: Colors.white54,
fontWeight: FontWeight.w500,
fontSize: 12.0,
),
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(bottom: 12.0),
child: LoginInput(
style: LoginInputStyle.password,
controller: passwordController,
),
),
// School
Padding(
padding: const EdgeInsets.only(bottom: 6.0),
child: Text(
"school".i18n,
maxLines: 1,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 14.0,
),
),
),
SchoolInput(
scroll: _scrollController,
controller: schoolController,
),
],
),
),
),
// Log in button
SizedBox(
width: 400.0,
child: Padding(
padding: const EdgeInsets.only(top: 42.0),
child: Visibility(
child: LoginButton(
child: Text("login".i18n,
maxLines: 1,
style: const TextStyle(
fontWeight: FontWeight.w600,
fontSize: 15.0,
)),
onPressed: () => _loginAPI(context: context),
),
visible: _loginState != LoginState.inProgress,
replacement: const Padding(
padding: EdgeInsets.symmetric(vertical: 6.0),
child: Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
Colors.white),
),
),
),
),
),
),
if (_loginState == LoginState.missingFields ||
_loginState == LoginState.invalidGrant ||
_loginState == LoginState.failed)
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Text(
[
"missing_fields",
"invalid_grant",
"error"
][_loginState.index]
.i18n,
style: const TextStyle(
color: Colors.red,
fontWeight: FontWeight.w500),
),
),
],
),
), ),
), ],
],
),
if (showBack)
Container(
alignment: Alignment.topLeft,
padding: EdgeInsets.only(left: 16.0, top: topInset),
child: const ClipOval(
child: Material(
type: MaterialType.transparency,
child: BackButton(color: Colors.white),
),
),
), ),
], if (showBack)
Container(
alignment: Alignment.topLeft,
padding: EdgeInsets.only(left: 16.0, top: topInset),
child: const ClipOval(
child: Material(
type: MaterialType.transparency,
child: BackButton(color: Colors.white),
),
),
),
],
),
), ),
), ),
); );
@ -283,7 +319,9 @@ class _LoginScreenState extends State<LoginScreen> {
String username = usernameController.text; String username = usernameController.text;
String password = passwordController.text; String password = passwordController.text;
if (username == "" || password == "" || schoolController.selectedSchool == null) { if (username == "" ||
password == "" ||
schoolController.selectedSchool == null) {
return setState(() => _loginState = LoginState.missingFields); return setState(() => _loginState = LoginState.missingFields);
} }
@ -313,7 +351,8 @@ class _LoginScreenState extends State<LoginScreen> {
).show(context); ).show(context);
}, },
onSuccess: () { onSuccess: () {
Navigator.of(context).pushNamedAndRemoveUntil("login_to_navigation", (_) => false); Navigator.of(context)
.pushNamedAndRemoveUntil("login_to_navigation", (_) => false);
}).then((res) => setState(() => _loginState = res)); }).then((res) => setState(() => _loginState = res));
} }
} }