-
-
Notifications
You must be signed in to change notification settings - Fork 497
/
Copy pathorganization_list.dart
119 lines (117 loc) · 4.37 KB
/
organization_list.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:talawa/enums/enums.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/models/organization/org_info.dart';
import 'package:talawa/services/size_config.dart';
import 'package:talawa/view_model/pre_auth_view_models/select_organization_view_model.dart';
import 'package:talawa/widgets/custom_list_tile.dart';
import 'package:visibility_detector/visibility_detector.dart';
class OrganizationList extends StatelessWidget {
const OrganizationList({required this.model, Key? key}) : super(key: key);
final SelectOrganizationViewModel model;
@override
Widget build(BuildContext context) {
model.organizations = [];
return GraphQLProvider(
client: ValueNotifier<GraphQLClient>(graphqlConfig.clientToQuery()),
child: Query(
options: QueryOptions(
document: gql(queries.fetchJoinInOrg),
variables: {
'first': 15,
'skip': 0,
},
),
builder: (
QueryResult result, {
Future<QueryResult> Function(FetchMoreOptions)? fetchMore,
Future<QueryResult?> Function()? refetch,
}) {
if (result.hasException) {
final isException = databaseFunctions.encounteredExceptionOrError(
result.exception!,
showSnackBar: false,
);
if (isException != null) {
if (isException) {
refetch!();
} else {
refetch!();
}
}
} else {
if (!result.isLoading) {
model.organizations = OrgInfo().fromJsonToList(
result.data!['organizationsConnection'] as List,
);
}
return Scrollbar(
thumbVisibility: true,
interactive: true,
controller: model.allOrgController,
child: ListView.separated(
controller: model.allOrgController,
padding: EdgeInsets.zero,
shrinkWrap: true,
itemCount: result.isLoading
? model.organizations.length + 1
: model.organizations.length,
itemBuilder: (BuildContext context, int index) {
if (index == model.organizations.length) {
return ListTile(
title: Center(
child: CupertinoActivityIndicator(
radius: SizeConfig.screenWidth! * 0.065,
),
),
);
}
if (index == model.organizations.length - 3) {
return VisibilityDetector(
key: const Key('OrgSelItem'),
onVisibilityChanged: (VisibilityInfo info) {
if (info.visibleFraction > 0) {
model.fetchMoreHelper(
fetchMore!, model.organizations);
}
},
child: CustomListTile(
index: index,
type: TileType.org,
orgInfo: model.organizations[index],
onTapOrgInfo: (item) => model.selectOrg(item),
key: Key('OrgSelItem$index'),
),
);
}
return CustomListTile(
index: index,
type: TileType.org,
orgInfo: model.organizations[index],
onTapOrgInfo: (item) => model.selectOrg(item),
key: Key('OrgSelItem$index'),
);
},
separatorBuilder: (BuildContext context, int index) {
return Padding(
padding: EdgeInsets.only(
left: SizeConfig.screenWidth! * 0.2,
right: 12,
),
child: const Divider(
color: Color(0xFFE5E5E5),
thickness: 0.5,
),
);
},
),
);
}
return Container();
},
),
);
}
}