Skip to content
This repository has been archived by the owner on Aug 19, 2021. It is now read-only.

Commit

Permalink
Parent Chat Funtions Implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
ketanchoyal committed Aug 10, 2019
1 parent 4d4976d commit 2a47f2c
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 48 deletions.
15 changes: 14 additions & 1 deletion lib/UI/Widgets/ChatStudentList.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,20 @@ class _ChatStudentListWidgetState extends State<ChatStudentListWidget> {
tag: widget.heroTag,
child: Container(
height: 70,
color: color,
decoration: BoxDecoration(
color: Theme.of(context).canvasColor,
border: Border(
top: BorderSide(width: 1),
bottom: BorderSide(width: 1),
left: BorderSide(width: 1),
right: BorderSide(width: 1),
),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(60),
bottomLeft: Radius.circular(60),
bottomRight: Radius.zero,
topRight: Radius.zero),
),
child: MaterialButton(
minWidth: MediaQuery.of(context).size.width,
onPressed: () {
Expand Down
61 changes: 38 additions & 23 deletions lib/UI/Widgets/ChatTeachersList.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ class _ChatTeachersListWidgetState extends State<ChatTeachersListWidget> {
super.initState();
if (SchedulerBinding.instance.schedulerPhase ==
SchedulerPhase.persistentCallbacks) {
SchedulerBinding.instance.addPostFrameCallback(
(_) => widget.model.getSingleTeacherData(widget.snapshot));
SchedulerBinding.instance.addPostFrameCallback((_) {
print('Here');
return widget.model.getSingleTeacherData(widget.snapshot);
});
}
}

Color color = RandomColor().randomColor(
colorSaturation: ColorSaturation.mediumSaturation,
colorBrightness: ColorBrightness.dark,
colorHue: ColorHue.blue,
);
colorSaturation: ColorSaturation.highSaturation,
colorBrightness: ColorBrightness.primary,
colorHue: ColorHue.custom(Range(21, 40)),
debug: true);

@override
Widget build(BuildContext context) {
Expand All @@ -41,42 +43,55 @@ class _ChatTeachersListWidgetState extends State<ChatTeachersListWidget> {
tag: widget.heroTag,
child: Container(
height: 70,
color: color,
decoration: BoxDecoration(
color: Theme.of(context).canvasColor,
border: Border(
top: BorderSide(width: 1),
bottom: BorderSide(width: 1),
left: BorderSide(width: 1),
right: BorderSide(width: 1),
),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(60),
bottomLeft: Radius.circular(60),
bottomRight: Radius.zero,
topRight: Radius.zero),
),
child: MaterialButton(
minWidth: MediaQuery.of(context).size.width,
onPressed: () {
// kopenPage(
// context,
// StudentConnectionPage(
// model: widget.model,
// studentDocumenetSnapshotKey: widget.snapshot.documentID,
// color: color,
// ),
// );
kopenPage(
context,
MessagingScreen(
student: widget.model.selectedChild,
parentORteacher:
widget.model.teachersListMap[widget.snapshot.documentID],
),
);
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Icon(
FontAwesomeIcons.peopleCarry,
size: 45,
color: Colors.white,
Image.asset(
assetsString.teacher_welcome,
height: 50,
width: 50,
),
Text(
widget.model.studentListMap
widget.model.teachersListMap
.containsKey(widget.snapshot.documentID)
? widget.model.studentListMap[widget.snapshot.documentID]
? widget.model.teachersListMap[widget.snapshot.documentID]
.displayName
: "loading...",
maxLines: 2,
style: TextStyle(
fontSize: 22,
color: Colors.white,
// color: Colors.white,
fontWeight: FontWeight.w600),
),
Icon(
Icons.chevron_right,
color: Colors.white,
// color: Colors.white,
size: 55,
)
],
Expand Down
30 changes: 13 additions & 17 deletions lib/UI/pages/Chat/ChatPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ class ChatPage extends StatefulWidget {
}

class _ChatPageState extends State<ChatPage> {
RandomColor _randomColor = RandomColor();

String _standard = '';
String _division = '';
bool studentLoaded = false;
Expand All @@ -31,16 +29,8 @@ class _ChatPageState extends State<ChatPage> {
child: ListView.builder(
itemCount: model.studentsSnapshot.length,
itemBuilder: (context, i) {
// values.keys.elementAt(index);
var key = model.studentsSnapshot.keys.elementAt(i);
var snapshot = model.studentsSnapshot[key];
// model.getUser(snapshot);
// model.getParents(snapshot);
// return Container(
// color: _randomColor.randomColor(),
// height: 50,
// width: MediaQuery.of(context).size.width / 2,
// );
return ChatStudentListWidget(
heroTag: snapshot.documentID,
snapshot: snapshot,
Expand All @@ -67,19 +57,25 @@ class _ChatPageState extends State<ChatPage> {
flex: 12,
child: model.selectedChild.isEmpty()
? Container(
color: Colors.red,
// color: Colors.red,
child: Center(
child: Text(
'No Child Selected',
style: ktitleStyle.copyWith(fontSize: 20),
),
),
)
: model.state == ViewState.Busy
? kBuzyPage(color: Theme.of(context).primaryColor)
: Container(
color: Colors.yellow,
// color: Colors.yellow,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: ListView.builder(
itemCount: model.teachersSnapshot.length,
itemBuilder: (context, i) {
// values.keys.elementAt(index);
var key = model.teachersListMap.keys
var key = model.teachersSnapshot.keys
.elementAt(i);
var snapshot =
model.teachersSnapshot[key];
Expand Down Expand Up @@ -108,7 +104,7 @@ class _ChatPageState extends State<ChatPage> {
standard: model.selectedChild.standard);
},
// enableFeedback: true,
highlightColor: Colors.deepPurple,
// highlightColor: Theme.of(context).accentColor,
child: Card(
elevation: 0,
margin: EdgeInsets.all(2),
Expand All @@ -117,11 +113,11 @@ class _ChatPageState extends State<ChatPage> {
decoration: new BoxDecoration(
gradient: new LinearGradient(
colors: [
Theme.of(context).accentColor,
Colors.deepPurple,
Theme.of(context).canvasColor,
],
begin: const FractionalOffset(0.0, 0.5),
end: const FractionalOffset(0.5, 0.0),
begin: const FractionalOffset(1.0, 1.5),
end: const FractionalOffset(1.0, 0.0),
stops: [0.0, 1.0],
tileMode: TileMode.clamp,
),
Expand Down
13 changes: 13 additions & 0 deletions lib/UI/pages/Chat/StudentConnectionPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ class _StudentConnectionPageState extends State<StudentConnectionPage> {
),
itemCount: parent.length,
itemBuilder: (context, index) {
if (parent[index].displayName == '') {
return Container(
child: Center(
child: Text(
'Parent Not Registered Yet',
overflow: TextOverflow.ellipsis,
softWrap: true,
textAlign: TextAlign.center,
style: ktitleStyle,
),
),
);
}
return Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expand Down
5 changes: 3 additions & 2 deletions lib/core/helpers/shared_preferences_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ class SharedPreferencesHelper {
Future<bool> setUserDataModel(String jsonModel) async {
final SharedPreferences preferences = await SharedPreferences.getInstance();
bool res = await preferences.setString(_userModel, jsonModel);
print('User Data Model saved ' + res.toString());
print('User Data Model saved ' + res.toString() + ' ' + jsonModel);
return res;
}

//Method to retrive User model in json format
Future<String> getUserDataModel() async {
final SharedPreferences preferences = await SharedPreferences.getInstance();
String res = preferences.getString(_userModel) ?? 'N.A';
print('User Data Model saved ' + res.toString());
print('User Data Model Retrived ' + res.toString());
return res;
}

Expand Down
2 changes: 0 additions & 2 deletions lib/core/services/ProfileServices.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class ProfileServices extends Services {
final jsonData = await json.decode(userDataModel);

User user = User.fromJson(jsonData);
sharedPreferencesHelper.setUserDataModel(userDataModel);
loggedInUserStream.add(user);
user.toString();
return user;
Expand Down Expand Up @@ -131,7 +130,6 @@ class ProfileServices extends Services {
final jsonData = await json.decode(response.body);

User user = User.fromJson(jsonData);
sharedPreferencesHelper.setUserDataModel(response.body);
user.toString();
return user;
} else {
Expand Down
5 changes: 3 additions & 2 deletions lib/core/services/Services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Services {
DocumentReference get schoolRef => _schoolRef;

Future<CollectionReference> schoolRefwithCode() async =>
_schoolRef.collection((await _sharedPreferencesHelper.getSchoolCode())
_schoolRef.collection((await getSchoolCode())
.toUpperCase()
.trim());

Expand All @@ -71,7 +71,8 @@ class Services {
firebaseUser = await _auth.currentUser();
}

getSchoolCode() async {
Future<String> getSchoolCode() async {
schoolCode = await _sharedPreferencesHelper.getSchoolCode();
return schoolCode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ class ChatUsersListPageModel extends BaseModel {
setState(ViewState.Idle);
}

getSingleTeacherData(DocumentSnapshot documentSnapshot) async {
Future<User> getSingleTeacherData(DocumentSnapshot documentSnapshot) async {
// setState(ViewState.Busy);
User user = await _chatServices.getUser(documentSnapshot);
_chatServices.teachersListMap
.putIfAbsent(documentSnapshot.documentID, () => user);
await _chatServices.getParents(documentSnapshot);
notifyListeners();
return user;
// setState(ViewState.Idle);
}

Expand Down

0 comments on commit 2a47f2c

Please sign in to comment.