Skip to content

Commit

Permalink
Merge pull request #2 from absarrahman/test
Browse files Browse the repository at this point in the history
Update to v2.0
  • Loading branch information
absarrahman authored Jan 24, 2022
2 parents 792fe94 + 27fc0f8 commit d1e51ef
Show file tree
Hide file tree
Showing 15 changed files with 222 additions and 143 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ app.*.symbols

# Obfuscation related
app.*.map.json
.env*
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Moh. Absar Rahman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# faculty_info
# Bracu Faculty Info
##

A new Flutter application.
## Features

## Getting Started
- Search email address by department
- Search email address by initial
- Search email address by name

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:
## Tech

- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)

For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
- Flutter
- REST
1 change: 1 addition & 0 deletions ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
41 changes: 41 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
4 changes: 4 additions & 0 deletions lib/customs/app_themes.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class AppThemes {
static const int Light = 1;
static const int Dark = 2;
}
12 changes: 5 additions & 7 deletions lib/customs/custom_internal.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import 'package:dynamic_theme/dynamic_theme.dart';
import 'package:dynamic_themes/dynamic_themes.dart';
import 'package:faculty_info/customs/app_themes.dart';
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';

bool isDark;
late bool isDark;

checkTheme(context) {
isDark = Theme.of(context).brightness == Brightness.dark ? true : false;
isDark = DynamicTheme.of(context)!.themeId == AppThemes.Dark ? true : false;
}

Color primaryColor = Color(0xff253494);

changeBrightness(context) {
DynamicTheme.of(context).setBrightness(
Theme.of(context).brightness == Brightness.dark
? Brightness.light
: Brightness.dark);
DynamicTheme.of(context)!.setTheme(DynamicTheme.of(context)!.themeId == AppThemes.Light ? AppThemes.Dark : AppThemes.Light);
}

Widget loading() {
Expand Down
22 changes: 14 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
import 'package:dynamic_theme/dynamic_theme.dart';
import 'package:dynamic_themes/dynamic_themes.dart';
import 'package:faculty_info/screens/splash.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'customs/app_themes.dart';

void main() {
Future<void> main() async {
await dotenv.load(fileName: ".env");
runApp(BracuFacultyApp());
}

class BracuFacultyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DynamicTheme(
defaultBrightness: Brightness.light,
data: (brightness)=> ThemeData(
primarySwatch: Colors.blue,
brightness: brightness,
),
themedWidgetBuilder: (context, theme) => MaterialApp(
defaultThemeId: AppThemes.Light,
builder: (context, theme) => MaterialApp(
debugShowCheckedModeBanner: false,
theme: theme,
home: SplashScreen(),
),
themeCollection: ThemeCollection(
themes: {
AppThemes.Light: ThemeData.light(),
AppThemes.Dark: ThemeData.dark(),
},
fallbackTheme: ThemeData.light(),
),
);
}
}
2 changes: 1 addition & 1 deletion lib/models/department_model.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class DepartmentModel {
String name,link;
String? name,link;

DepartmentModel(this.name, this.link);

Expand Down
2 changes: 1 addition & 1 deletion lib/models/faculty_model.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class FacultyModel {
String initial,name,email;
String? initial,name,email;

FacultyModel(this.initial, this.name, this.email);

Expand Down
27 changes: 14 additions & 13 deletions lib/screens/departments/departments.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:faculty_info/models/faculty_model.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';

class DepartmentsPage extends StatefulWidget {
final deptName;
Expand All @@ -18,12 +19,13 @@ class DepartmentsPage extends StatefulWidget {

class _DepartmentsPageState extends State<DepartmentsPage> {
var deptName, screenWidth, screenHeight;
List<FacultyModel> list;
List<FacultyModel> listShow;
List<FacultyModel>? list;
List<FacultyModel>? listShow;

_fetchData() async {
final url =
widget.deptLink;
/*final url =
Uri.parse(widget.deptLink);*/
final url = Uri.parse("${dotenv.env['BASE_URL']}dep=${widget.deptLink}");
var response = await http.get(url);
return response.body;
}
Expand All @@ -34,7 +36,6 @@ class _DepartmentsPageState extends State<DepartmentsPage> {
deptName = widget.deptName;
_fetchData().then((value) {
var list = json.decode(value.toString());
list = list[deptName];
List<FacultyModel> listModel = [];
for (var l in list) {
listModel.add(FacultyModel.fromJson(l));
Expand Down Expand Up @@ -64,7 +65,7 @@ class _DepartmentsPageState extends State<DepartmentsPage> {
Expanded(
child: ListView.builder(
physics: BouncingScrollPhysics(),
itemCount: listShow.length,
itemCount: listShow!.length,
itemBuilder: (context, index) {
return _cardView(index);
},
Expand All @@ -91,8 +92,8 @@ class _DepartmentsPageState extends State<DepartmentsPage> {

_onChanged(String value) {
setState(() {
listShow = list.where((faculty) {
return ((faculty.name.toLowerCase().contains(value.toLowerCase()))||(faculty.initial.toLowerCase().contains(value.toLowerCase())));
listShow = list!.where((faculty) {
return ((faculty.name!.toLowerCase().contains(value.toLowerCase()))||(faculty.initial!.toLowerCase().contains(value.toLowerCase())));
}).toList();
});
}
Expand All @@ -115,7 +116,7 @@ class _DepartmentsPageState extends State<DepartmentsPage> {
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"${listShow[index].initial}",
"${listShow![index].initial??"N/A"}",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
Expand All @@ -127,7 +128,7 @@ class _DepartmentsPageState extends State<DepartmentsPage> {
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"${listShow[index].name}",
"${listShow![index].name}",
style: TextStyle(
fontSize: 20,
// fontWeight: FontWeight.bold,
Expand All @@ -140,9 +141,9 @@ class _DepartmentsPageState extends State<DepartmentsPage> {
Padding(
padding: const EdgeInsets.all(8.0),
child: GestureDetector(
onDoubleTap: () => _launchEmail(listShow[index].email),
onDoubleTap: () => _launchEmail(listShow![index].email!),
child: SelectableText(
"${listShow[index].email}",
"${listShow![index].email}",
style: TextStyle(
decoration: TextDecoration.underline,
fontSize: 20,
Expand Down Expand Up @@ -170,4 +171,4 @@ class _DepartmentsPageState extends State<DepartmentsPage> {
throw "Failed";
}
}
}
}
20 changes: 9 additions & 11 deletions lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ class HomePage extends StatefulWidget {

class _HomePageState extends State<HomePage> {
var screenHeight, screenWidth;
List<DepartmentModel> deptNameList;
List<DepartmentModel>? deptNameList;

_fetchData() async {
final url =
"https://raw.githubusercontent.com/absarrahman/DataStuffs/master/dept_status.json";
final url = Uri.parse("https://raw.githubusercontent.com/absarrahman/DataStuffs/master/dept_status.json");
var response = await http.get(url);
return response.body;
}
Expand Down Expand Up @@ -60,7 +59,7 @@ class _HomePageState extends State<HomePage> {
: RefreshIndicator(
onRefresh: _refreshData,
child: ListView.builder(
itemCount: deptNameList.length + 1,
itemCount: deptNameList!.length + 1,
itemBuilder: (context, index) => index == 0
? Padding(
padding: const EdgeInsets.all(15.0),
Expand All @@ -83,9 +82,8 @@ class _HomePageState extends State<HomePage> {
}

Future<void> _refreshData() async {
await Future.delayed(Duration(seconds: 2));
setState(() {
_fetchData();
setState(() async {
await _fetchData();
});
}

Expand All @@ -100,7 +98,7 @@ class _HomePageState extends State<HomePage> {

Widget _departmentCard(int index) {
return Padding(
padding: const EdgeInsets.only(top: 20.0),
padding: const EdgeInsets.only(top: 20.0,bottom: 10.0),
child: InkWell(
onTap: () => _redirectRoute(index),
child: Center(
Expand All @@ -117,7 +115,7 @@ class _HomePageState extends State<HomePage> {
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
deptNameList[index].name,
deptNameList![index].name ?? "N/A",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
Expand All @@ -137,8 +135,8 @@ class _HomePageState extends State<HomePage> {
context,
MaterialPageRoute(
builder: (context) => DepartmentsPage(
deptName: deptNameList[index].name,
deptLink: deptNameList[index].link,
deptName: deptNameList![index].name,
deptLink: deptNameList![index].link,
),
),
);
Expand Down
Loading

0 comments on commit d1e51ef

Please sign in to comment.