Skip to content

Commit 00733a3

Browse files
Merge pull request #34 from Bablo-AD/dev
Dev
2 parents 82f2020 + f2dbf48 commit 00733a3

19 files changed

+161
-110
lines changed

lib/core/data.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:uuid/uuid.dart';
77

88
class Data {
99
Loader load = Loader();
10-
static var uuid = Uuid();
10+
static var uuid = const Uuid();
1111
static String? userId = FirebaseAuth.instance.currentUser?.uid;
1212
static List<Application> apps = [];
1313
static List<Application> selected_apps = [];
@@ -42,9 +42,9 @@ class Video {
4242
}
4343
Map<String, dynamic> toJson() {
4444
return {
45-
'title': this.title,
46-
'videoId': this.videoId,
47-
'videoDescription': this.videoDescription,
45+
'title': title,
46+
'videoId': videoId,
47+
'videoDescription': videoDescription,
4848
};
4949
}
5050
}

lib/core/loader.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,15 @@ class Loader {
164164
Future<List<types.Message>> loadMessages() async {
165165
SharedPreferences prefs = await SharedPreferences.getInstance();
166166
List<String> messages = prefs.getStringList('messages') ?? [];
167-
List<types.Message> message_list = [];
167+
List<types.Message> messageList = [];
168168
for (var message in messages) {
169169
try {
170-
message_list.add(types.TextMessage.fromJson(jsonDecode(message)));
170+
messageList.add(types.TextMessage.fromJson(jsonDecode(message)));
171171
} catch (e) {
172172
print('Error decoding message: $e, $message');
173173
}
174174
}
175-
return message_list;
175+
return messageList;
176176
}
177177

178178
Future<String?> loadcompletion() async {

lib/core/notifications.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ class LocalNotificationService {
2727
priority: Priority.high,
2828
ticker: 'ticker');
2929

30-
int notification_id = 1;
30+
int notificationId = 1;
3131
const NotificationDetails notificationDetails =
3232
NotificationDetails(android: androidNotificationDetails);
3333

3434
await flutterLocalNotificationsPlugin.show(
35-
notification_id, title, value, notificationDetails,
35+
notificationId, title, value, notificationDetails,
3636
payload: 'item x');
3737
}
3838
}

lib/home/chat_page.dart

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ class ChatPage extends StatefulWidget {
2323
}
2424

2525
class _ChatPageState extends State<ChatPage> {
26-
final _user = const types.User(id: '82091008-a484-4a89-ae75-a22bf8d6f3ac');
27-
final _mentor = const types.User(id: 'mentor');
26+
final _user = const types.User(id: 'user');
27+
final _mentor = const types.User(
28+
id: '82091008-a484-4a89-ae75-a22bf8d6f3ac', firstName: "Mentor");
2829
DataProcessor sender = DataProcessor();
29-
Loader _loader = Loader();
30+
List<types.User> typing_users = [];
31+
final Loader _loader = Loader();
3032
@override
3133
void initState() {
3234
super.initState();
@@ -44,38 +46,37 @@ class _ChatPageState extends State<ChatPage> {
4446
@override
4547
Widget build(BuildContext context) => Scaffold(
4648
appBar: AppBar(
47-
title: Text("Mentor/Chat"),
49+
title: const Text("Mentor/Chat"),
4850
centerTitle: true,
4951
),
5052
body: Chat(
5153
messages: Data.messages_data,
5254
onSendPressed: _handleSendPressed,
5355
user: _user,
54-
typingIndicatorOptions: TypingIndicatorOptions(),
56+
typingIndicatorOptions:
57+
TypingIndicatorOptions(typingUsers: typing_users),
5558
),
5659
);
5760

58-
void _addMessage(types.Message message) {
59-
setState(() {
60-
Data.messages_data.insert(0, message);
61-
});
62-
}
63-
6461
void _handleSendPressed(types.PartialText message) async {
6562
final textMessage = types.TextMessage(
6663
author: _user,
6764
createdAt: DateTime.now().millisecondsSinceEpoch,
6865
id: Data.uuid.v1(),
6966
text: message.text,
7067
);
71-
_addMessage(textMessage);
68+
setState(() {
69+
Data.messages_data.insert(0, textMessage);
70+
typing_users = [_mentor];
71+
});
7272

7373
http.Response response = await sender.meet_with_server(message.text);
7474
if (response.statusCode == 200) {
7575
sender.post_process_data(response.body);
7676
if (mounted) {
7777
setState(() {
7878
Data.messages_data;
79+
typing_users = [];
7980
});
8081
}
8182
} else {

lib/home/home_page.dart

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ class _MentorPageState extends State<MentorPage> {
8686
setState(() {
8787
Data.completion_message = completionMessage ?? "";
8888
result = Data.completion_message;
89+
if (result == '') {
90+
isLoading = true;
91+
_Makerequest(interest);
92+
}
8993
});
9094
});
9195

@@ -100,12 +104,6 @@ class _MentorPageState extends State<MentorPage> {
100104
change_val();
101105
});
102106
}
103-
if (result == '') {
104-
setState(() {
105-
isLoading = true;
106-
_Makerequest(interest);
107-
});
108-
}
109107
}
110108

111109
void change_val() {
@@ -150,10 +148,10 @@ class _MentorPageState extends State<MentorPage> {
150148
builder: (context) => const AppsPage()),
151149
);
152150
},
153-
title: Row(
151+
title: const Row(
154152
mainAxisAlignment: MainAxisAlignment.spaceBetween,
155153
children: [
156-
const Text(
154+
Text(
157155
"Apps",
158156
style: TextStyle(fontSize: 25),
159157
),
@@ -168,13 +166,13 @@ class _MentorPageState extends State<MentorPage> {
168166
builder: (context, snapshot) {
169167
if (snapshot.connectionState ==
170168
ConnectionState.waiting) {
171-
return Center(
169+
return const Center(
172170
child: CircularProgressIndicator(),
173171
); // Loading animation
174172
} else if (snapshot.hasError) {
175173
return Text('Error: ${snapshot.error}');
176174
} else if (snapshot.data!.isEmpty) {
177-
return Text(
175+
return const Text(
178176
'Select the apps you want to display by long pressing. If changes didn\'t show up click the home again');
179177
} else {
180178
return ListView.builder(
@@ -247,7 +245,7 @@ class _MentorPageState extends State<MentorPage> {
247245
children: [
248246
Text(
249247
lastJournalTitle,
250-
style: TextStyle(fontSize: 25),
248+
style: const TextStyle(fontSize: 25),
251249
),
252250
IconButton(
253251
tooltip: "Add",
@@ -312,7 +310,7 @@ class _MentorPageState extends State<MentorPage> {
312310
onTap: () {
313311
Navigator.push(
314312
context,
315-
MaterialPageRoute(builder: (context) => ChatPage()),
313+
MaterialPageRoute(builder: (context) => const ChatPage()),
316314
);
317315
},
318316
child: Card(

lib/home/make_request.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class DataProcessor {
116116
Data.completion_message = '';
117117
for (var message in completionMemory['reply']) {
118118
final mentorMessage = types.TextMessage(
119-
author: types.User(id: 'mentor'),
119+
author: const types.User(id: 'mentor'),
120120
createdAt: DateTime.now().millisecondsSinceEpoch,
121121
id: Data.uuid.v1(),
122122
text: message,

lib/home/video_page.dart

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,87 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter/services.dart';
23
import 'package:youtube_player_flutter/youtube_player_flutter.dart';
34
import 'package:url_launcher/url_launcher.dart';
45

5-
class VideoPage extends StatelessWidget {
6+
class VideoPage extends StatefulWidget {
67
final String videoId;
78
final String description;
89

9-
const VideoPage(
10-
{super.key, required this.videoId, required this.description});
10+
const VideoPage({Key? key, required this.videoId, required this.description})
11+
: super(key: key);
1112

1213
@override
13-
Widget build(BuildContext context) {
14-
final youtubePlayerController = YoutubePlayerController(
15-
initialVideoId: videoId,
14+
_VideoPageState createState() => _VideoPageState();
15+
}
16+
17+
class _VideoPageState extends State<VideoPage> {
18+
late final YoutubePlayerController youtubePlayerController;
19+
20+
@override
21+
void initState() {
22+
super.initState();
23+
SystemChrome.setPreferredOrientations([
24+
DeviceOrientation.portraitUp,
25+
DeviceOrientation.portraitDown,
26+
]);
27+
28+
youtubePlayerController = YoutubePlayerController(
29+
initialVideoId: widget.videoId,
1630
flags: const YoutubePlayerFlags(
1731
autoPlay: false,
1832
),
1933
);
34+
}
2035

36+
@override
37+
void dispose() {
38+
SystemChrome.setPreferredOrientations([
39+
DeviceOrientation.portraitUp,
40+
DeviceOrientation.portraitDown,
41+
]);
42+
super.dispose();
43+
}
44+
45+
@override
46+
Widget build(BuildContext context) {
2147
return Scaffold(
2248
appBar: AppBar(title: const Text('Mentor/Video')),
23-
body: Padding(
24-
padding: const EdgeInsets.all(16.0),
25-
child: Column(
26-
crossAxisAlignment: CrossAxisAlignment.stretch,
27-
mainAxisAlignment: MainAxisAlignment.center,
49+
body: YoutubePlayerBuilder(
50+
player: YoutubePlayer(
51+
controller: youtubePlayerController,
52+
showVideoProgressIndicator: true,
53+
progressIndicatorColor: const Color.fromARGB(255, 50, 204, 102),
54+
),
55+
builder: (context, player) {
56+
return Column(
2857
children: [
2958
IconButton(
3059
icon: const Icon(Icons.open_in_browser,
3160
color: Color.fromARGB(255, 50, 204, 102)),
3261
onPressed: () {
33-
_launchURL(videoId);
62+
_launchURL(widget.videoId);
3463
},
3564
),
3665
const SizedBox(
3766
height: 2,
3867
),
39-
YoutubePlayer(
40-
controller: youtubePlayerController,
41-
showVideoProgressIndicator: true,
42-
progressIndicatorColor:
43-
const Color.fromARGB(255, 50, 204, 102),
44-
),
68+
// some widgets
69+
player,
4570
const SizedBox(height: 16.0),
46-
Text(description),
47-
])),
71+
Text(widget.description),
72+
//some other widgets
73+
],
74+
);
75+
}),
4876
);
4977
}
50-
}
5178

52-
_launchURL(String videoId) async {
53-
final url = 'https://www.youtube.com/watch?v=$videoId';
54-
Uri uri = Uri.parse(url);
55-
if (!await canLaunchUrl(uri)) {
56-
throw Exception('Could not launch $url');
79+
_launchURL(String videoId) async {
80+
final url = 'https://www.youtube.com/watch?v=$videoId';
81+
Uri uri = Uri.parse(url);
82+
if (!await canLaunchUrl(uri)) {
83+
throw Exception('Could not launch $url');
84+
}
85+
await launchUrl(uri);
5786
}
58-
await launchUrl(uri);
5987
}

lib/journal/journal_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class _JournalPageState extends State<JournalPage> {
7373
child: ListTile(
7474
title: Text(
7575
title.toString(),
76-
style: TextStyle(fontSize: 25),
76+
style: const TextStyle(fontSize: 25),
7777
),
7878
subtitle: Text(content),
7979
onTap: () {

lib/main.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'package:Mentor/setup/setup_roller.dart';
2-
31
import 'settings/knowingthestudent.dart';
42
import 'package:flutter/material.dart';
53
import 'home/home_page.dart';
@@ -76,12 +74,12 @@ class MyApp extends StatelessWidget {
7674
builder: (BuildContext context, AsyncSnapshot<User?> snapshot) {
7775
if (snapshot.connectionState == ConnectionState.active) {
7876
if (snapshot.data == null) {
79-
return EmailAuth();
77+
return const EmailAuth();
8078
} else {
81-
return MentorPage();
79+
return const MentorPage();
8280
}
8381
}
84-
return CircularProgressIndicator();
82+
return const CircularProgressIndicator();
8583
}),
8684
routes: {
8785
//main pages
@@ -95,7 +93,7 @@ class MyApp extends StatelessWidget {
9593
'/habiticaIntegrationPage': (context) =>
9694
const HabiticaIntegrationPage(),
9795
'/knowingthestudent': (context) => const Knowingthestudent(),
98-
'/preferredtime': (context) => PreferredTimePage(),
96+
'/preferredtime': (context) => const PreferredTimePage(),
9997
},
10098
);
10199
}

lib/settings/knowingthestudent.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ class _KnowingthestudentState extends State<Knowingthestudent> {
9090
),
9191
const SizedBox(height: 16),
9292
const Text(
93-
"Tell me about your personality",
93+
"Tell me about yourself.",
9494
),
9595
const SizedBox(height: 10),
9696
TextFormField(
9797
controller: _selfPerceptionController,
9898
validator: (value) {
9999
if (value == null || value.isEmpty) {
100-
return 'This is used to know your current mental state';
100+
return 'This is used to know your current workable factor';
101101
}
102102
return null; // Return null if the value is valid
103103
},

0 commit comments

Comments
 (0)