From 43a44cba938e8550bdfad16e758c061287583a78 Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Wed, 10 Mar 2021 10:44:33 +0300 Subject: [PATCH] improvements. --- lib/extensions/email_validator.dart | 6 +-- lib/main.dart | 5 +- lib/ui/common_appbar.dart | 13 +++++- lib/ui/dialogs/opt_dialog.dart | 1 + lib/ui/screens/forgot_password_screen.dart | 1 + lib/ui/screens/home_screen.dart | 3 +- lib/ui/screens/login_screen.dart | 7 ++- lib/ui/screens/registration_screen.dart | 54 +++++++++++++++++++++- lib/ui/screens/tangheem_screen.dart | 2 + lib/widgets/aya_player_widget.dart | 3 +- lib/widgets/common_dropdown_button.dart | 7 +-- lib/widgets/common_textfield_widget.dart | 5 +- 12 files changed, 85 insertions(+), 22 deletions(-) diff --git a/lib/extensions/email_validator.dart b/lib/extensions/email_validator.dart index e980d96..97ee38a 100644 --- a/lib/extensions/email_validator.dart +++ b/lib/extensions/email_validator.dart @@ -1,7 +1,5 @@ extension EmailValidator on String { bool isValidEmail() { - return RegExp( - r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$') - .hasMatch(this); + return RegExp(r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$').hasMatch(this); } -} \ No newline at end of file +} diff --git a/lib/main.dart b/lib/main.dart index 0ae0279..2eee6e2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -9,6 +9,7 @@ import 'package:tangheem/ui/screens/login_screen.dart'; import 'package:tangheem/ui/screens/registration_screen.dart'; import 'package:tangheem/ui/screens/surah_screen.dart'; import 'package:tangheem/ui/screens/tangheem_screen.dart'; + import 'classes/const.dart'; void main() { @@ -22,12 +23,12 @@ class Application extends StatelessWidget { title: 'Tangheem', theme: lightTheme(), debugShowCheckedModeBanner: false, - initialRoute: LoginScreen.routeName, + initialRoute: HomeScreen.routeName, onGenerateRoute: (settings) { var className; switch (settings.name) { case LoginScreen.routeName: - className = CommonAppbar(isFirst: true, child: LoginScreen()); + className = CommonAppbar(child: LoginScreen()); break; case RegistrationScreen.routeName: className = CommonAppbar(child: RegistrationScreen()); diff --git a/lib/ui/common_appbar.dart b/lib/ui/common_appbar.dart index 079dd9e..620d0c9 100644 --- a/lib/ui/common_appbar.dart +++ b/lib/ui/common_appbar.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:tangheem/classes/const.dart'; +import 'package:tangheem/ui/screens/login_screen.dart'; class CommonAppbar extends StatefulWidget { final bool showDrawer; @@ -111,7 +112,9 @@ class _CommonAppbarState extends State { commonIconButton("assets/icons/increase_size.svg", () {}), commonIconButton("assets/icons/reduce_size.svg", () {}), commonIconButton("assets/icons/notification.svg", () {}), - commonIconButton("assets/icons/user_logged.svg", () {}), + commonIconButton("assets/icons/user_logged.svg", () { + Navigator.pushNamed(context, LoginScreen.routeName); + }), ], ), ), @@ -254,7 +257,13 @@ class _CommonAppbarState extends State { Widget commonIconButton(String icon, VoidCallback onPressed, {double size}) { return Expanded( - child: IconButton(padding: EdgeInsets.zero, icon: SvgPicture.asset(icon, height: size ?? 25, width: size ?? 30), onPressed: onPressed), + child: IconButton( + padding: EdgeInsets.zero, + icon: SvgPicture.asset(icon, height: size ?? 25, width: size ?? 30), + onPressed: () { + Navigator.pop(context); + Future.delayed(Duration(milliseconds: 200), () => onPressed()); + }), ); } diff --git a/lib/ui/dialogs/opt_dialog.dart b/lib/ui/dialogs/opt_dialog.dart index 1657589..6a41217 100644 --- a/lib/ui/dialogs/opt_dialog.dart +++ b/lib/ui/dialogs/opt_dialog.dart @@ -19,6 +19,7 @@ class _OTPDialogState extends State { bool hasError = false; String errorMessage; + @override void initState() { super.initState(); diff --git a/lib/ui/screens/forgot_password_screen.dart b/lib/ui/screens/forgot_password_screen.dart index f0d7859..aef1032 100644 --- a/lib/ui/screens/forgot_password_screen.dart +++ b/lib/ui/screens/forgot_password_screen.dart @@ -7,6 +7,7 @@ import 'package:tangheem/widgets/common_textfield_widget.dart'; class ForgotPasswordScreen extends StatefulWidget { static const String routeName = "/forgot_password"; + ForgotPasswordScreen({Key key}) : super(key: key); @override diff --git a/lib/ui/screens/home_screen.dart b/lib/ui/screens/home_screen.dart index 9245a20..cabbc77 100644 --- a/lib/ui/screens/home_screen.dart +++ b/lib/ui/screens/home_screen.dart @@ -9,7 +9,7 @@ import 'package:tangheem/ui/screens/tangheem_screen.dart'; import 'package:tangheem/widgets/common_dropdown_button.dart'; class HomeScreen extends StatefulWidget { - static const String routeName = "/home"; + static const String routeName = "/"; HomeScreen({Key key}) : super(key: key); @@ -22,6 +22,7 @@ class HomeScreen extends StatefulWidget { class _HomeScreenState extends State { TextEditingController _searchController = TextEditingController(); FocusNode _searchFocusNode = FocusNode(); + @override void initState() { super.initState(); diff --git a/lib/ui/screens/login_screen.dart b/lib/ui/screens/login_screen.dart index adc42ea..db60701 100644 --- a/lib/ui/screens/login_screen.dart +++ b/lib/ui/screens/login_screen.dart @@ -6,10 +6,9 @@ import 'package:tangheem/ui/screens/forgot_password_screen.dart'; import 'package:tangheem/ui/screens/registration_screen.dart'; import 'package:tangheem/widgets/common_textfield_widget.dart'; -import 'home_screen.dart'; - class LoginScreen extends StatefulWidget { - static const String routeName = "/"; + static const String routeName = "/login"; + LoginScreen({Key key}) : super(key: key); @override @@ -83,7 +82,7 @@ class _LoginScreenState extends State { Utils.showToast("Password is empty."); return; } - Navigator.pushNamed(context, HomeScreen.routeName); + Utils.showToast("Login successfully"); }, style: TextButton.styleFrom( primary: Colors.white, diff --git a/lib/ui/screens/registration_screen.dart b/lib/ui/screens/registration_screen.dart index adc1b5f..144b31c 100644 --- a/lib/ui/screens/registration_screen.dart +++ b/lib/ui/screens/registration_screen.dart @@ -1,12 +1,14 @@ +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:tangheem/classes/const.dart'; import 'package:tangheem/classes/utils.dart'; import 'package:tangheem/widgets/common_textfield_widget.dart'; -import 'file:///C:/Users/sikander.saleem/Documents/AndroidStudioProjects/tangheem/lib/extensions/email_validator.dart'; +import 'package:tangheem/extensions/email_validator.dart'; class RegistrationScreen extends StatefulWidget { static const String routeName = "/registration"; + RegistrationScreen({Key key}) : super(key: key); @override @@ -84,7 +86,14 @@ class _RegistrationScreenState extends State { SizedBox(height: 8), CommonTextFieldWidget(hint: "الايميل", controller: _emailController), SizedBox(height: 8), - CommonTextFieldWidget(hint: "البلد", controller: _mobileNumberController, showSuffix: true), + CommonTextFieldWidget( + hint: "البلد", + controller: _mobileNumberController, + showSuffix: true, + onTap: () { + _selectCountry(context); + }, + ), SizedBox(height: 8), CommonTextFieldWidget(hint: " رقم الجوال (9xx xxxxxxxxx+)", controller: _mobileNumberController), SizedBox(height: 8), @@ -180,4 +189,45 @@ class _RegistrationScreenState extends State { ), ); } + + void _selectCountry(context) { + showModalBottomSheet( + context: context, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.only( + topLeft: Radius.circular(16), + topRight: Radius.circular(16), + ), + ), + backgroundColor: Colors.transparent, + builder: (BuildContext bc) { + return Container( + height: MediaQuery.of(context).size.height * 0.75, + // padding: EdgeInsets.all(16), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.only( + topLeft: Radius.circular(16), + topRight: Radius.circular(16), + ), + ), + child: Column( + children: [ + Container( + padding: EdgeInsets.all(16), + decoration: BoxDecoration( + color: Const.primaryBlue, + borderRadius: BorderRadius.only( + topLeft: Radius.circular(16), + topRight: Radius.circular(16), + ), + ), + // color: Const.primaryBlue, + child: CommonTextFieldWidget(hint: "تعيين كلمة المرور", controller: null), + ), + Expanded(child: ListView()) + ], + )); + }); + } } diff --git a/lib/ui/screens/tangheem_screen.dart b/lib/ui/screens/tangheem_screen.dart index a38dc1e..bc85ae6 100644 --- a/lib/ui/screens/tangheem_screen.dart +++ b/lib/ui/screens/tangheem_screen.dart @@ -18,6 +18,7 @@ class TangheemScreen extends StatefulWidget { class _TangheemScreenState extends State { List temp1 = List(); List temp2 = List(); + @override void initState() { super.initState(); @@ -240,5 +241,6 @@ class _TangheemScreenState extends State { class TempModel { String title; String description; + TempModel(this.title, this.description); } diff --git a/lib/widgets/aya_player_widget.dart b/lib/widgets/aya_player_widget.dart index 5368736..a08d5c6 100644 --- a/lib/widgets/aya_player_widget.dart +++ b/lib/widgets/aya_player_widget.dart @@ -1,7 +1,8 @@ +import 'dart:math' as math; + import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:tangheem/classes/const.dart'; -import 'dart:math' as math; class AyaPlayerWidget extends StatefulWidget { AyaPlayerWidget({Key key}) : super(key: key); diff --git a/lib/widgets/common_dropdown_button.dart b/lib/widgets/common_dropdown_button.dart index 1974688..9c1a713 100644 --- a/lib/widgets/common_dropdown_button.dart +++ b/lib/widgets/common_dropdown_button.dart @@ -31,8 +31,6 @@ class CommonDropDownButton extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [ - - isExpanded ? Expanded( child: Text( @@ -42,11 +40,10 @@ class CommonDropDownButton extends StatelessWidget { style: TextStyle(fontSize: 12, color: Colors.white), ), ) - : - Text( + : Text( text, maxLines: 1, - // overflow: TextOverflow.ellipsis, + // overflow: TextOverflow.ellipsis, style: TextStyle(fontSize: 12, color: Colors.white), ), SizedBox(width: 4), diff --git a/lib/widgets/common_textfield_widget.dart b/lib/widgets/common_textfield_widget.dart index 21f6b53..9a92e04 100644 --- a/lib/widgets/common_textfield_widget.dart +++ b/lib/widgets/common_textfield_widget.dart @@ -8,7 +8,9 @@ class CommonTextFieldWidget extends StatelessWidget { final bool isPassword; final String prefixIcon; final bool showSuffix; - CommonTextFieldWidget({Key key, @required this.hint, @required this.controller, this.isPassword = false, this.prefixIcon, this.showSuffix = false}) : super(key: key); + final Function onTap; + + CommonTextFieldWidget({Key key, @required this.hint, @required this.controller, this.isPassword = false, this.prefixIcon, this.showSuffix = false, this.onTap}) : super(key: key); @override Widget build(BuildContext context) { @@ -21,6 +23,7 @@ class CommonTextFieldWidget extends StatelessWidget { textInputAction: TextInputAction.next, style: TextStyle(color: Const.primaryBlack, fontSize: 14), cursorColor: Const.primaryBlue, + onTap: onTap, decoration: InputDecoration( contentPadding: EdgeInsets.fromLTRB(4, 4, 8, 4), alignLabelWithHint: true,