Skip to content

Commit

Permalink
bfix: delay in search (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
anshikamittal25 authored Apr 16, 2021
1 parent 47f1a20 commit cfd3926
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
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

0 comments on commit cfd3926

Please sign in to comment.