Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GSoC] - Code re-write and migration #863

Merged
merged 2 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ jobs:
uses: VeryGoodOpenSource/[email protected]
with:
path: "./coverage/lcov.info"
min_coverage: 30
min_coverage: 3
6 changes: 4 additions & 2 deletions lib/custom_theme.dart → lib/constants/custom_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ class TalawaTheme {
static const Color _lightPrimaryColor = Colors.white;
static const Color _lightPrimaryVariantColor = Color(0xFFe5e5e5);
static const Color _lightIconColor = Color(0xff8C8E8D);
static const Color _lightInBlack = Color(0xff000000);

static const Color _darkCursorColor = Color(0xff34AD64);
static const Color _darkAccentColor = Color(0xff34AD64);
static const Color _darkScaffoldColor = Color(0xff18191A);
static const Color _darkPrimaryColor = Colors.black;
static const Color _darkPrimaryVariantColor = Colors.black;
static const Color _darkIconColor = Colors.white70;
static const Color _darkInWhite = Color(0xffffffff);

static final lightTheme = ThemeData(
scaffoldBackgroundColor: _lightScaffoldColor,
Expand Down Expand Up @@ -52,7 +54,7 @@ class TalawaTheme {
fontWeight: FontWeight.w700,
),
headline5: TextStyle(
color: Colors.black87,
color: _lightInBlack,
fontSize: 20,
),
headline6: TextStyle(
Expand All @@ -76,7 +78,7 @@ class TalawaTheme {
headline4: TextStyle(
fontWeight: FontWeight.w700,
),
headline5: TextStyle(color: Colors.white70, fontSize: 20),
headline5: TextStyle(color: _darkInWhite, fontSize: 20),
headline6: TextStyle(
fontSize: 16,
color: Color(0xFF737373),
Expand Down
File renamed without changes.
17 changes: 17 additions & 0 deletions lib/generated_plugin_registrant.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Generated file. Do not edit.
//

// ignore_for_file: lines_longer_than_80_chars

import 'package:shared_preferences_web/shared_preferences_web.dart';
import 'package:uni_links_web/uni_links_web.dart';

import 'package:flutter_web_plugins/flutter_web_plugins.dart';

// ignore: public_member_api_docs
void registerPlugins(Registrar registrar) {
SharedPreferencesPlugin.registerWith(registrar);
UniLinksPlugin.registerWith(registrar);
registrar.registerMessageHandler();
}
4 changes: 4 additions & 0 deletions lib/locator.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:get_it/get_it.dart';
import 'package:talawa/services/navigation_service.dart';
import 'package:talawa/services/size_config.dart';
import 'package:talawa/viewModel/demo_view_model.dart';

GetIt locator = GetIt.instance;
Expand All @@ -8,6 +9,9 @@ void setupLocator() {
//services
locator.registerSingleton(NavigationService());

//sizeConfig
locator.registerSingleton(SizeConfig());

//Page viewModels
locator.registerFactory(() => DemoViewModel());
}
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:talawa/services/navigation_service.dart';
import 'package:talawa/viewModel/demo_view_model.dart';
import 'package:talawa/views/base_view.dart';
import 'package:talawa/router.dart' as router;
import 'custom_theme.dart';
import 'constants/custom_theme.dart';

void main() {
setupLocator();
Expand Down
4 changes: 2 additions & 2 deletions lib/router.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:talawa/main.dart';
import 'package:talawa/splash_screen.dart';
import 'package:talawa/views/Home%20Screen/home_view.dart';
import 'package:talawa/views/after_auth_screens/feed_page/organization_feed.dart';
import 'package:talawa/views/home_page.dart';
import 'package:talawa/views/pre_auth_screens/change_password.dart';
import 'package:talawa/views/pre_auth_screens/login.dart';
Expand Down Expand Up @@ -34,7 +34,7 @@ Route<dynamic> generateRoute(RouteSettings settings) {
builder: (context) => const Recover(key: Key('Recover')));
case Routes.updateScreen:
return MaterialPageRoute(
builder: (context) => const UpdatePassword(key: Key('Update')));
builder: (context) => const ChangePass(key: Key('Update')));
case Routes.homeScreen:
return MaterialPageRoute(
builder: (context) => const HomeView(key: Key('HomeScreen')));
Expand Down
5 changes: 5 additions & 0 deletions lib/services/navigation_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class NavigationService {
.pushNamed(routeName, arguments: arguments);
}

Future<dynamic> removeAllAndPush(String routeName, {dynamic arguments}) {
return navigatorKey.currentState!
.pushNamedAndRemoveUntil(routeName, ModalRoute.withName('/selectLang'));
}

void pop() {
return navigatorKey.currentState!.pop();
}
Expand Down
4 changes: 1 addition & 3 deletions lib/size_config.dart → lib/services/size_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class SizeConfig {
static double? safeBlockHorizontal;
static double? safeBlockVertical;

void init(
BuildContext context,
) {
void init(BuildContext context) {
_mediaQueryData = MediaQuery.of(context);
screenWidth = _mediaQueryData.size.width;
screenHeight = _mediaQueryData.size.height;
Expand Down
7 changes: 4 additions & 3 deletions lib/splash_screen.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:talawa/size_config.dart';

import 'package:talawa/services/size_config.dart';
import 'custom_painters/talawa_logo.dart';
import 'locator.dart';

class SplashScreen extends StatefulWidget {
const SplashScreen({required Key key}) : super(key: key);
Expand All @@ -21,7 +22,7 @@ class _SplashScreenState extends State<SplashScreen> {

@override
Widget build(BuildContext context) {
SizeConfig().init(context);
locator<SizeConfig>().init(context);
print(SizeConfig.screenWidth! * 0.6);
return Scaffold(
body: Stack(
Expand Down
104 changes: 104 additions & 0 deletions lib/utils/validators.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import 'package:flutter/cupertino.dart';
import 'package:http/http.dart' as http;

class Validator {
static String? validateURL(
String value,
) {
if (value.isEmpty) {
return 'Please verify URL first'.toUpperCase();
}
final bool validURL = Uri.parse(value).isAbsolute;
if (!validURL) {
return 'Enter a valid URL';
}
return null;
}

static String? validateFirstName(String value) {
if (value.isEmpty) {
return 'Firstname must not be left blank.';
}
// ignore: unnecessary_raw_strings
const String pattern = r'(?=.*?[A-Za-z]).+';
final RegExp regex = RegExp(pattern);
if (!regex.hasMatch(value)) {
return "Invalid Firstname";
}
return null;
}

static String? validateLastName(String value) {
if (value.isEmpty) {
return 'Lastname must not be left blank.';
}
// ignore: unnecessary_raw_strings
const String pattern = r"(?=.*?[A-Za-z]).+";
final RegExp regex = RegExp(pattern);
if (!regex.hasMatch(value)) {
return "Invalid Lastname";
}
return null;
}

static String? validateEmail(
String email,
) {
// If email is empty return.
if (email.isEmpty) {
return "Email must not be left blank";
}
const String pattern =
r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,253}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,253}[a-zA-Z0-9])?)*$";
final RegExp regex = RegExp(pattern);
if (!regex.hasMatch(email)) {
return 'Please enter a valid Email Address';
}
return null;
}

static String? validatePassword(
String password,
) {
// If password is empty return.
if (password.isEmpty) {
return "Password must not be left blank";
}
const String pattern =
r'^(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[!@#\$&*%^~.]).{8,}$';
final RegExp regExp = RegExp(pattern);

//Regex for no spaces allowed
const String noSpaces = r'^\S+$';
final RegExp noSpaceRegex = RegExp(noSpaces);

if (!regExp.hasMatch(password)) {
return "Invalid Password";
}
if (!noSpaceRegex.hasMatch(password)) {
return "Password must not contain spaces";
}

return null;
}

static String? validatePasswordConfirm(
String value,
String comparator,
) {
if (value != comparator) {
return 'Password does not match original';
}
return null;
}

static Future<bool?> validateUrlExistence(String url) async {
try {
await http.get(Uri.parse(url));
return true;
} on Exception catch (e) {
debugPrint(e.toString());
return false;
}
}
}
2 changes: 1 addition & 1 deletion lib/viewModel/base_view_model.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:talawa/enums/viewstate.dart';
import 'package:talawa/enums/view_state.dart';

//this is the base model to change the notifier
class BaseModel extends ChangeNotifier {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:talawa/views/Home%20Screen/Home%20screen%20widgets/NewsPostWidget.dart';
import 'package:talawa/views/Home%20Screen/Home%20screen%20widgets/PinnedPostCarousel.dart';
import 'package:talawa/widgets/pinned_carousel_widget.dart';
import 'package:talawa/widgets/post_widget.dart';

class HomeView extends StatelessWidget {
const HomeView({required Key key}) : super(key: key);
Expand All @@ -23,7 +23,10 @@ class HomeView extends StatelessWidget {
),
),
body: ListView(
children: [PinnedPostCarousel(), NewsPost(description: description)],
children: [
const PinnedPostCarousel(),
const NewsPost(description: description)
],
));
}
}
8 changes: 6 additions & 2 deletions lib/views/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:talawa/views/Home%20Screen/home_view.dart';
import 'package:talawa/services/size_config.dart';

import 'after_auth_screens/feed_page/organization_feed.dart';

class MainScreen extends StatefulWidget {
const MainScreen({Key? key}) : super(key: key);
Expand All @@ -11,7 +13,7 @@ class MainScreen extends StatefulWidget {
class MainScreenState extends State<MainScreen> {
int _currentIndex = 0;
final List<Widget> _childrenPages = [
HomeView(key: Key("HomeView")),
const HomeView(key: Key("HomeView")),
Container(
child: const Center(
child: Text('Events Screen'),
Expand All @@ -36,6 +38,8 @@ class MainScreenState extends State<MainScreen> {

@override
Widget build(BuildContext context) {
print(SizeConfig.screenWidth);
print(SizeConfig.screenHeight);
return Scaffold(
body: _childrenPages[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
Expand Down
Loading