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 #30

Closed
wants to merge 2 commits into from
Closed
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');
}
24 changes: 5 additions & 19 deletions lib/directory/directory_list_widget.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:campusbuddy/directory/directory_data.dart';
import 'package:campusbuddy/screens/department_list.dart';
import 'package:campusbuddy/search_feature/model.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
Expand All @@ -16,33 +17,17 @@ 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) {

return Card(
margin: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
elevation: 1,
Expand Down Expand Up @@ -77,6 +62,7 @@ class _DirectoryListState extends State<DirectoryList> {

@override
Widget build(BuildContext context) {

return CustomScrollView(
slivers: <Widget>[
SliverAppBar(
Expand All @@ -97,7 +83,7 @@ class _DirectoryListState extends State<DirectoryList> {
// showConfirmationDialog(context);
showSearch(
context: context,
delegate: CustomSearchDelegate(contactList: contactList),
delegate: CustomSearchDelegate(),
);
}),
],
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