Skip to content

Commit

Permalink
Merge pull request #34 from Bablo-AD/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
prasannan-robots authored Mar 24, 2024
2 parents 82f2020 + f2dbf48 commit 00733a3
Show file tree
Hide file tree
Showing 19 changed files with 161 additions and 110 deletions.
8 changes: 4 additions & 4 deletions lib/core/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:uuid/uuid.dart';

class Data {
Loader load = Loader();
static var uuid = Uuid();
static var uuid = const Uuid();
static String? userId = FirebaseAuth.instance.currentUser?.uid;
static List<Application> apps = [];
static List<Application> selected_apps = [];
Expand Down Expand Up @@ -42,9 +42,9 @@ class Video {
}
Map<String, dynamic> toJson() {
return {
'title': this.title,
'videoId': this.videoId,
'videoDescription': this.videoDescription,
'title': title,
'videoId': videoId,
'videoDescription': videoDescription,
};
}
}
6 changes: 3 additions & 3 deletions lib/core/loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ class Loader {
Future<List<types.Message>> loadMessages() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
List<String> messages = prefs.getStringList('messages') ?? [];
List<types.Message> message_list = [];
List<types.Message> messageList = [];
for (var message in messages) {
try {
message_list.add(types.TextMessage.fromJson(jsonDecode(message)));
messageList.add(types.TextMessage.fromJson(jsonDecode(message)));
} catch (e) {
print('Error decoding message: $e, $message');
}
}
return message_list;
return messageList;
}

Future<String?> loadcompletion() async {
Expand Down
4 changes: 2 additions & 2 deletions lib/core/notifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class LocalNotificationService {
priority: Priority.high,
ticker: 'ticker');

int notification_id = 1;
int notificationId = 1;
const NotificationDetails notificationDetails =
NotificationDetails(android: androidNotificationDetails);

await flutterLocalNotificationsPlugin.show(
notification_id, title, value, notificationDetails,
notificationId, title, value, notificationDetails,
payload: 'item x');
}
}
25 changes: 13 additions & 12 deletions lib/home/chat_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ class ChatPage extends StatefulWidget {
}

class _ChatPageState extends State<ChatPage> {
final _user = const types.User(id: '82091008-a484-4a89-ae75-a22bf8d6f3ac');
final _mentor = const types.User(id: 'mentor');
final _user = const types.User(id: 'user');
final _mentor = const types.User(
id: '82091008-a484-4a89-ae75-a22bf8d6f3ac', firstName: "Mentor");
DataProcessor sender = DataProcessor();
Loader _loader = Loader();
List<types.User> typing_users = [];
final Loader _loader = Loader();
@override
void initState() {
super.initState();
Expand All @@ -44,38 +46,37 @@ class _ChatPageState extends State<ChatPage> {
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: Text("Mentor/Chat"),
title: const Text("Mentor/Chat"),
centerTitle: true,
),
body: Chat(
messages: Data.messages_data,
onSendPressed: _handleSendPressed,
user: _user,
typingIndicatorOptions: TypingIndicatorOptions(),
typingIndicatorOptions:
TypingIndicatorOptions(typingUsers: typing_users),
),
);

void _addMessage(types.Message message) {
setState(() {
Data.messages_data.insert(0, message);
});
}

void _handleSendPressed(types.PartialText message) async {
final textMessage = types.TextMessage(
author: _user,
createdAt: DateTime.now().millisecondsSinceEpoch,
id: Data.uuid.v1(),
text: message.text,
);
_addMessage(textMessage);
setState(() {
Data.messages_data.insert(0, textMessage);
typing_users = [_mentor];
});

http.Response response = await sender.meet_with_server(message.text);
if (response.statusCode == 200) {
sender.post_process_data(response.body);
if (mounted) {
setState(() {
Data.messages_data;
typing_users = [];
});
}
} else {
Expand Down
22 changes: 10 additions & 12 deletions lib/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ class _MentorPageState extends State<MentorPage> {
setState(() {
Data.completion_message = completionMessage ?? "";
result = Data.completion_message;
if (result == '') {
isLoading = true;
_Makerequest(interest);
}
});
});

Expand All @@ -100,12 +104,6 @@ class _MentorPageState extends State<MentorPage> {
change_val();
});
}
if (result == '') {
setState(() {
isLoading = true;
_Makerequest(interest);
});
}
}

void change_val() {
Expand Down Expand Up @@ -150,10 +148,10 @@ class _MentorPageState extends State<MentorPage> {
builder: (context) => const AppsPage()),
);
},
title: Row(
title: const Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
Text(
"Apps",
style: TextStyle(fontSize: 25),
),
Expand All @@ -168,13 +166,13 @@ class _MentorPageState extends State<MentorPage> {
builder: (context, snapshot) {
if (snapshot.connectionState ==
ConnectionState.waiting) {
return Center(
return const Center(
child: CircularProgressIndicator(),
); // Loading animation
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else if (snapshot.data!.isEmpty) {
return Text(
return const Text(
'Select the apps you want to display by long pressing. If changes didn\'t show up click the home again');
} else {
return ListView.builder(
Expand Down Expand Up @@ -247,7 +245,7 @@ class _MentorPageState extends State<MentorPage> {
children: [
Text(
lastJournalTitle,
style: TextStyle(fontSize: 25),
style: const TextStyle(fontSize: 25),
),
IconButton(
tooltip: "Add",
Expand Down Expand Up @@ -312,7 +310,7 @@ class _MentorPageState extends State<MentorPage> {
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => ChatPage()),
MaterialPageRoute(builder: (context) => const ChatPage()),
);
},
child: Card(
Expand Down
2 changes: 1 addition & 1 deletion lib/home/make_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class DataProcessor {
Data.completion_message = '';
for (var message in completionMemory['reply']) {
final mentorMessage = types.TextMessage(
author: types.User(id: 'mentor'),
author: const types.User(id: 'mentor'),
createdAt: DateTime.now().millisecondsSinceEpoch,
id: Data.uuid.v1(),
text: message,
Expand Down
82 changes: 55 additions & 27 deletions lib/home/video_page.dart
Original file line number Diff line number Diff line change
@@ -1,59 +1,87 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:youtube_player_flutter/youtube_player_flutter.dart';
import 'package:url_launcher/url_launcher.dart';

class VideoPage extends StatelessWidget {
class VideoPage extends StatefulWidget {
final String videoId;
final String description;

const VideoPage(
{super.key, required this.videoId, required this.description});
const VideoPage({Key? key, required this.videoId, required this.description})
: super(key: key);

@override
Widget build(BuildContext context) {
final youtubePlayerController = YoutubePlayerController(
initialVideoId: videoId,
_VideoPageState createState() => _VideoPageState();
}

class _VideoPageState extends State<VideoPage> {
late final YoutubePlayerController youtubePlayerController;

@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);

youtubePlayerController = YoutubePlayerController(
initialVideoId: widget.videoId,
flags: const YoutubePlayerFlags(
autoPlay: false,
),
);
}

@override
void dispose() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Mentor/Video')),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
body: YoutubePlayerBuilder(
player: YoutubePlayer(
controller: youtubePlayerController,
showVideoProgressIndicator: true,
progressIndicatorColor: const Color.fromARGB(255, 50, 204, 102),
),
builder: (context, player) {
return Column(
children: [
IconButton(
icon: const Icon(Icons.open_in_browser,
color: Color.fromARGB(255, 50, 204, 102)),
onPressed: () {
_launchURL(videoId);
_launchURL(widget.videoId);
},
),
const SizedBox(
height: 2,
),
YoutubePlayer(
controller: youtubePlayerController,
showVideoProgressIndicator: true,
progressIndicatorColor:
const Color.fromARGB(255, 50, 204, 102),
),
// some widgets
player,
const SizedBox(height: 16.0),
Text(description),
])),
Text(widget.description),
//some other widgets
],
);
}),
);
}
}

_launchURL(String videoId) async {
final url = 'https://www.youtube.com/watch?v=$videoId';
Uri uri = Uri.parse(url);
if (!await canLaunchUrl(uri)) {
throw Exception('Could not launch $url');
_launchURL(String videoId) async {
final url = 'https://www.youtube.com/watch?v=$videoId';
Uri uri = Uri.parse(url);
if (!await canLaunchUrl(uri)) {
throw Exception('Could not launch $url');
}
await launchUrl(uri);
}
await launchUrl(uri);
}
2 changes: 1 addition & 1 deletion lib/journal/journal_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class _JournalPageState extends State<JournalPage> {
child: ListTile(
title: Text(
title.toString(),
style: TextStyle(fontSize: 25),
style: const TextStyle(fontSize: 25),
),
subtitle: Text(content),
onTap: () {
Expand Down
10 changes: 4 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'package:Mentor/setup/setup_roller.dart';

import 'settings/knowingthestudent.dart';
import 'package:flutter/material.dart';
import 'home/home_page.dart';
Expand Down Expand Up @@ -76,12 +74,12 @@ class MyApp extends StatelessWidget {
builder: (BuildContext context, AsyncSnapshot<User?> snapshot) {
if (snapshot.connectionState == ConnectionState.active) {
if (snapshot.data == null) {
return EmailAuth();
return const EmailAuth();
} else {
return MentorPage();
return const MentorPage();
}
}
return CircularProgressIndicator();
return const CircularProgressIndicator();
}),
routes: {
//main pages
Expand All @@ -95,7 +93,7 @@ class MyApp extends StatelessWidget {
'/habiticaIntegrationPage': (context) =>
const HabiticaIntegrationPage(),
'/knowingthestudent': (context) => const Knowingthestudent(),
'/preferredtime': (context) => PreferredTimePage(),
'/preferredtime': (context) => const PreferredTimePage(),
},
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/settings/knowingthestudent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ class _KnowingthestudentState extends State<Knowingthestudent> {
),
const SizedBox(height: 16),
const Text(
"Tell me about your personality",
"Tell me about yourself.",
),
const SizedBox(height: 10),
TextFormField(
controller: _selfPerceptionController,
validator: (value) {
if (value == null || value.isEmpty) {
return 'This is used to know your current mental state';
return 'This is used to know your current workable factor';
}
return null; // Return null if the value is valid
},
Expand Down
Loading

0 comments on commit 00733a3

Please sign in to comment.