Skip to content

Commit

Permalink
google sing in almost completed
Browse files Browse the repository at this point in the history
  • Loading branch information
klukovka committed Jun 1, 2021
1 parent 74e790d commit 60dd601
Show file tree
Hide file tree
Showing 5 changed files with 285 additions and 232 deletions.
233 changes: 11 additions & 222 deletions chem_solution_mobile/lib/assets/alerts.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import 'package:chem_solution_mobile/assets/toasts.dart';
import 'package:chem_solution_mobile/models/Autorisation.dart';
import 'package:community_material_icon/community_material_icon.dart';
import 'package:chem_solution_mobile/widgets/auth_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:chem_solution_mobile/main.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'colors.dart';

Widget createAttention(BuildContext context){
Widget createAttention(BuildContext context) {
return AlertDialog(
elevation: 24,
title: Text(
Expand Down Expand Up @@ -67,12 +63,9 @@ Widget createDialog(BuildContext context, String value) {
// ignore: deprecated_member_use
FlatButton(
onPressed: () {
alertDialogShow(
context,
autorisation(context, () {
Navigator.of(context).pop();
}),
400);
alertDialogShow(context, autorisation(() {
Navigator.of(context).pop();
}), 400);
},
child: Text(
'Так',
Expand Down Expand Up @@ -103,217 +96,13 @@ Future<Widget> alertDialogShow(
pageBuilder: (context, animation1, animation2) {});
}

Widget autorisation(BuildContext context, Function() update) {
String _email;
String _password;
final TextEditingController _emailEditingController =
TextEditingController(text: _email);
final TextEditingController _passwordEditingController =
TextEditingController(text: _password);
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
bool visible = false;

void getCorrect() {
if (autorised) {
Navigator.of(context).pop();
update();
} else {
_emailEditingController.text = '';
_passwordEditingController.text = '';
_formKey.currentState.validate();
}
}

Widget autorisation(Function() update) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(32.0))),
content: Container(
height: MediaQuery.of(context).size.height * 0.725,
width: MediaQuery.of(context).size.width * 0.95,
padding: EdgeInsets.symmetric(vertical: 20),
child: Form(
key: _formKey,
child: ListView(
children: [
Text(
'Авторизація',
textAlign: TextAlign.center,
style: TextStyle(
color: themeDark, fontWeight: FontWeight.bold, fontSize: 32),
),
ListTile(
leading: Text('Email '),
title: TextFormField(
decoration: InputDecoration(hintText: "Уведіть email"),
controller: _emailEditingController,
validator: (String inValue) {
if (inValue.length == 0) {
return "Перевірте дані про пошту";
} else if (inValue.lastIndexOf('@') == -1) {
return "Please enter a correct email";
}
_email = inValue;
return null;
}),
),
Padding(padding: EdgeInsets.all(5)),
ListTile(
leading: Text('Пароль'),
title: TextFormField(
obscureText: !visible,
decoration: InputDecoration(hintText: "Уведіть пароль"),
controller: _passwordEditingController,
validator: (String inValue) {
if (inValue.length == 0) {
return "Перевірте дані про пароль";
} else if (inValue.lastIndexOf('@') == -1) {
return "Please enter a correct email";
}
_password = inValue;
return null;
}),
),
Padding(padding: EdgeInsets.all(10)),
Center(
child: ConstrainedBox(
constraints: BoxConstraints.tightFor(
width: MediaQuery.of(context).size.width * 0.8,
),
child: ElevatedButton(
onPressed: () async {
var email = _emailEditingController.text;
var password = _passwordEditingController.text;
try {
Autorisation.signIn(email, password, getCorrect);
} catch (ex) {
showToast('Помилка підключення', themeRed, themeDarkRed,
Icons.error, FToast());
}
},
child: Text(
'Увійти',
style: TextStyle(fontSize: 16),
),
style: ButtonStyle(
padding: MaterialStateProperty.all<EdgeInsetsGeometry>(
EdgeInsets.symmetric(vertical: 15, horizontal: 30),
),
backgroundColor:
MaterialStateProperty.all<Color>(themeBlue),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
)),
),
),
),
),
Padding(padding: EdgeInsets.only(top: 15)),
Divider(
color: themeDark,
thickness: 1,
indent: MediaQuery.of(context).size.width * 0.05,
endIndent: MediaQuery.of(context).size.width * 0.05,
),
Padding(padding: EdgeInsets.only(top: 20)),
Center(
child: ConstrainedBox(
constraints: BoxConstraints.tightFor(
width: MediaQuery.of(context).size.width * 0.8,
),
child: ElevatedButton(
onPressed: () {},
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(CommunityMaterialIcons.google),
Text(
' Увійти з Google',
style: TextStyle(fontSize: 16),
),
],
),
),
style: ButtonStyle(
padding: MaterialStateProperty.all<EdgeInsetsGeometry>(
EdgeInsets.symmetric(vertical: 15, horizontal: 30),
),
backgroundColor:
MaterialStateProperty.all<Color>(Color(0xffEA4335)),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
)),
),
),
),
),
Padding(padding: EdgeInsets.only(top: 20)),
Center(
child: ConstrainedBox(
constraints: BoxConstraints.tightFor(
width: MediaQuery.of(context).size.width * 0.8,
),
child: ElevatedButton(
onPressed: () {},
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(CommunityMaterialIcons.facebook),
Text(
' Увійти з Facebook',
style: TextStyle(fontSize: 16),
),
],
),
),
style: ButtonStyle(
padding: MaterialStateProperty.all<EdgeInsetsGeometry>(
EdgeInsets.symmetric(vertical: 15, horizontal: 30),
),
backgroundColor:
MaterialStateProperty.all<Color>(Color(0xff4064AC)),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
)),
),
),
),
),
Padding(padding: EdgeInsets.only(top: 15)),
Divider(
color: themeDark,
thickness: 1,
indent: MediaQuery.of(context).size.width * 0.05,
endIndent: MediaQuery.of(context).size.width * 0.05,
),
TextButton(
onPressed: () {
toBrowser(
context, 'https://www.google.com', 'Відновлення паролю');
},
child: Text(
'Забули пароль?',
style: TextStyle(color: themeDark, fontSize: 16),
),
),
TextButton(
onPressed: () {
toBrowser(context, 'https://www.google.com', 'Реєстрація');
},
child: Text(
'Створити акаунт',
style: TextStyle(color: themeDark, fontSize: 16),
),
),
],
),
),
),
);
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(32.0))),
content: AuthWidget(
update: update,
));
}

void toBrowser(BuildContext context, String link, String title) {
Expand Down
23 changes: 16 additions & 7 deletions chem_solution_mobile/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import 'package:chem_solution_mobile/models/BlogPost.dart';
import 'package:chem_solution_mobile/models/User.dart';
import 'package:chem_solution_mobile/screens/home_screen.dart';
import 'package:chem_solution_mobile/screens/splash_screen.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:chem_solution_mobile/models/Element.dart' as CS;
import 'package:provider/provider.dart';

import 'bloc/auth_bloc.dart';

bool autorised;
//final String chemURL = '192.168.0.104:5001';
Expand All @@ -17,6 +21,8 @@ List<BlogPost> allPosts = [];
List<CS.Element> allElements = [];

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
allPosts = await BlogPost.fetchObjects(path: 'BlogPosts');
allElements = await CS.Element.fetchObjects(path: 'Elements');
await Autorisation.setUser();
Expand All @@ -30,13 +36,16 @@ class ChemApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'ChemSolution',
home: SplashScreen(nextRoute: '/Home'),
routes: routes,
theme: ThemeData(
fontFamily: 'CenturyGothic',
return Provider<AuthBloc>(
create: (context) => AuthBloc(),
child: MaterialApp(
debugShowCheckedModeBanner: false,
title: 'ChemSolution',
home: SplashScreen(nextRoute: '/Home'),
routes: routes,
theme: ThemeData(
fontFamily: 'CenturyGothic',
),
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions chem_solution_mobile/lib/models/Autorisation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ abstract class Autorisation {
autorised = false;
}
update();
} catch (ex) {
throw Exception(ex);
} catch (ex) {
print(ex);
}
}

Expand Down
2 changes: 1 addition & 1 deletion chem_solution_mobile/lib/profile/profile_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class _ProfileState extends State<Profile> with SingleTickerProviderStateMixin {
child: GestureDetector(
onTap: () {
return alertDialogShow(
context, autorisation(context, refresh), 400);
context, autorisation(refresh), 400);
},
child: _card(
context,
Expand Down
Loading

0 comments on commit 60dd601

Please sign in to comment.