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

bfix: delay in search #42

Merged
merged 1 commit into from
Apr 16, 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
22 changes: 22 additions & 0 deletions lib/directory/directory_data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:campusbuddy/search_feature/model.dart';
import 'package:http/http.dart' as http;

List<Contact> contactList = [];

void loadData() async {
var url = Uri.parse(
'https://raw.githubusercontent.com/mdg-iitr/CampusBuddy/master/app/src/main/assets/contacts.min.json');
var response = await http.get(url);
final jsonResponse = groupsFromJson(response.body);
for (int i = 0; i < jsonResponse.length; i++) {
List<Department> departmentList = jsonResponse[i].depts;
for (int j = 0; j < departmentList.length; j++) {
for (int k = 0; k < departmentList[j].contacts.length; k++) {
departmentList[j].contacts[k].department_name =
departmentList[j].deptName;
}
contactList = contactList + departmentList[j].contacts;
}
}
print('data loaded');
}
23 changes: 3 additions & 20 deletions lib/directory/directory_list_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import 'package:campusbuddy/auth/auth.dart';
import 'package:campusbuddy/search_feature/search_view.dart';
import 'package:http/http.dart' as http;

import 'directory_data.dart';

class DirectoryList extends StatefulWidget {
@override
_DirectoryListState createState() => _DirectoryListState();
Expand All @@ -16,30 +18,11 @@ class DirectoryList extends StatefulWidget {
class _DirectoryListState extends State<DirectoryList> {
Auth auth = new Auth();

List<Contact> contactList = [];

@override
void initState() {
super.initState();
print('went here');
loadData();
print('data loaded');
}

void loadData() async {
var url = Uri.parse('https://raw.githubusercontent.com/mdg-iitr/CampusBuddy/master/app/src/main/assets/contacts.min.json');
var response = await http.get(url);
final jsonResponse = groupsFromJson(response.body);
for (int i = 0; i < jsonResponse.length; i++) {
List<Department> departmentList = jsonResponse[i].depts;
for (int j = 0; j < departmentList.length; j++) {
for (int k = 0; k < departmentList[j].contacts.length; k++) {
departmentList[j].contacts[k].department_name =
departmentList[j].deptName;
}
contactList = contactList + departmentList[j].contacts;
}
}
}

Widget _buildListItem(BuildContext context, DocumentSnapshot document) {
Expand Down Expand Up @@ -100,7 +83,7 @@ class _DirectoryListState extends State<DirectoryList> {
// showConfirmationDialog(context);
showSearch(
context: context,
delegate: CustomSearchDelegate(contactList: contactList),
delegate: CustomSearchDelegate(),
);
}),
],
Expand Down
10 changes: 5 additions & 5 deletions lib/search_feature/contact_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ContactView extends StatelessWidget {
Padding(
padding: EdgeInsets.symmetric(vertical: 3.0, horizontal: 5.0),
child: Text(
'$value',
'$value'??'',
style: TextStyle(
fontSize: 17,
),
Expand All @@ -35,7 +35,7 @@ class ContactView extends StatelessWidget {
Padding(
padding: EdgeInsets.symmetric(vertical: 3.0, horizontal: 5.0),
child: Text(
'$label',
'$label'??'',
style: TextStyle(fontSize: 17, color: Color(0xFF838383)),
),
),
Expand Down Expand Up @@ -103,7 +103,7 @@ class ContactView extends StatelessWidget {
height: 9.2,
),
Text(
contact.name,
contact.name??'',
style: TextStyle(
color: Colors.white,
fontSize:20,
Expand All @@ -115,15 +115,15 @@ class ContactView extends StatelessWidget {
height: 20,
),
Text(
contact.department_name,
contact.department_name??'',
style: TextStyle(
color: Colors.white, fontSize: 17),
),
SizedBox(
height: 22,
),
Text(
contact.desg,
contact.desg??'',
style: TextStyle(
color: Colors.white, fontSize: 17),
),
Expand Down
5 changes: 1 addition & 4 deletions lib/search_feature/search_view.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import 'package:campusbuddy/ContactScreens/ContactList.dart';
import 'package:campusbuddy/directory/directory_data.dart';
import 'package:campusbuddy/search_feature/contact_view.dart';
import 'package:flutter/material.dart';
import 'model.dart';

class CustomSearchDelegate extends SearchDelegate {
final List<Contact> contactList;

CustomSearchDelegate({this.contactList});

@override
List<Widget> buildActions(BuildContext context) {
Expand Down