Skip to content

Commit

Permalink
showing number of the questions in the question card
Browse files Browse the repository at this point in the history
  • Loading branch information
nayakastha authored and abhibhaw committed Aug 17, 2021
1 parent b0b7a71 commit ca913a4
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 24 deletions.
6 changes: 3 additions & 3 deletions aptiche/lib/datamodels/api_models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Quiz {
required this.name,
required this.startTime,
required this.endTime,
//required this.questions,
required this.questionIds,
required this.instructions,
// required this.description,
// required this.submissions,
Expand All @@ -52,7 +52,7 @@ class Quiz {
name: json['name'] as String,
startTime: json['startTime'] as String,
endTime: json['endTime'] as String,
//questions: json['questionsIds'] as List<String>,
questionIds: json['questionsIds'] as List<String?>?,
instructions: json['instructions'] as List<String>,
active: json['active'] as bool,
);
Expand All @@ -62,7 +62,7 @@ class Quiz {
final String? name;
String startTime;
String endTime;
//final List<String> questions; // string - questionId
final List<String?>? questionIds; // string - questionId
final List<String> instructions;
// final String description;
// final dynamic submissions; // string - userId, int - score
Expand Down
17 changes: 11 additions & 6 deletions aptiche/lib/services/graphql.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ class GraphQLService {
}

/// Takes in data from [QueryResult] and converts it to a map
List<Map<String, dynamic>> toMap(Map<String, dynamic> data) {
List<Map<String, dynamic>>? toMap(Map<String, dynamic> data) {
/// Stores the list of instruction strings.
final List<String> instructionsList = <String>[];

final List<dynamic> questionIdList = <dynamic>[];
final List<Map<String, dynamic>> list = <Map<String, dynamic>>[];
// Since graphql is returning everything as an object, each string in
// the instructions list is first converted from an object to string
Expand All @@ -99,30 +99,35 @@ class GraphQLService {
for (final dynamic instruction in quiz['instructions']) {
instructionsList.add(instruction.toString());
}
for (final dynamic instruction in quiz['questionIds']) {
questionIdList.add(instruction.toString());
}
final Map<String, dynamic> listItem = <String, dynamic>{
'_id': quiz['_id'],
'name': quiz['name'],
'startTime': quiz['startTime'],
'endTime': quiz['endTime'],
'questionIds': questionIdList,
'instructions': instructionsList,
'active': quiz['active']
};

list.add(listItem);
}
return list;
}

final List<Map<String, dynamic>> getQuizzes = toMap(result.data!);
final List<Map<String, dynamic>>? getQuizzes = toMap(result.data!);

/// Stores the final result i.e. all the quizzes.
final List<Quiz> quizzes = <Quiz>[];
// ignore: prefer_final_locals
List<Quiz> quizzes = <Quiz>[];

/// Converts the map into a [Quiz] Object
for (final Map<String, dynamic> quiz in getQuizzes) {
for (final Map<String, dynamic> quiz in getQuizzes!) {
final Quiz singleQuiz = Quiz.fromJson(quiz);
quizzes.add(singleQuiz);
}

return quizzes;
} catch (e) {
rethrow;
Expand Down
2 changes: 2 additions & 0 deletions aptiche/lib/utils/query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const String getQuiz = r'''
name
startTime
endTime
questionIds
instructions
active
}
Expand All @@ -31,6 +32,7 @@ const String getQuizzesByTimeQuery = r'''
_id
name
startTime
questionIds
endTime
instructions
active
Expand Down
3 changes: 3 additions & 0 deletions aptiche/lib/views/drawer/dev_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import '../../utils/theme.dart';
import '../../utils/ui_scaling.dart';

class DevInfo extends StatelessWidget {
DevInfo({
Key? key,
}) : super(key: key);
final ThirdPartyServices _thirdPartyServices = Get.find();
@override
Widget build(BuildContext context) {
Expand Down
11 changes: 2 additions & 9 deletions aptiche/lib/widgets/HomeScreen/home_screen_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ class HomeGridTile extends StatelessWidget {
'${quiz.name} will be active on ${formatDateTime(quiz.startTime)['date'].toString()}',
);
} else {
// Get.to<TestPreviewView>(
// () => TestPreviewView(
// quiz: quiz,
// ),
// );
Get.to<AnswerView>(() => AnswerView(quiz));
}
},
Expand Down Expand Up @@ -97,8 +92,7 @@ class HomeGridTile extends StatelessWidget {
height: SizeConfig.safeBlockVertical,
),
Text(
//TODO : question number isnt 30 always. fetch it from the server
'30 Questions, ${calcuateTestDuration(quiz.startTime, quiz.endTime)} mins',
'${quiz.questionIds!.length}, Questions, ${calcuateTestDuration(quiz.startTime, quiz.endTime)} mins',
style: Theme.of(context).primaryTextTheme.headline3!.copyWith(
fontSize: SizeConfig.safeBlockHorizontal! * 3,
),
Expand Down Expand Up @@ -192,8 +186,7 @@ class HomeActiveTile extends StatelessWidget {
],
),
Text(
//TODO : question number isnt 30 always. fetch it from the server
'30 Questions, ${calcuateTestDuration(quiz.startTime, quiz.endTime)} mins',
'${quiz.questionIds!.length}, ${calcuateTestDuration(quiz.startTime, quiz.endTime)} mins',
style: Theme.of(context)
.primaryTextTheme
.headline2!
Expand Down
10 changes: 5 additions & 5 deletions aptiche/lib/widgets/quiz/ans_display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AnswerDisplayer extends StatelessWidget {
padding: EdgeInsets.symmetric(
horizontal: SizeConfig.safeBlockHorizontal! * 1.5),
child: Column(
children: [
children: <Widget>[
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
Expand Down Expand Up @@ -47,13 +47,13 @@ class AnswerDisplayer extends StatelessWidget {
),
Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
width: 8,
),
color: kPrimaryColor.withOpacity(0.3),
borderRadius: BorderRadius.circular(12),
),
padding: EdgeInsets.symmetric(
horizontal: SizeConfig.safeBlockHorizontal! * 1.5,
vertical: SizeConfig.safeBlockHorizontal! * 1.5,
),
width: double.maxFinite,
child: Text(
'Answer → $answer',
Expand Down
1 change: 0 additions & 1 deletion aptiche/lib/widgets/quiz/quiz_top_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class QuizTopBar extends GetView<QuizController> {
),
CustomButton(
text: 'Finish',
// TODO: After pressing finish, everything must be stored into local storage and the next time the users opens the same quiz, timer and dinish button must not be shown.
onTap: () async {
await controller.storeScore(
quizName,
Expand Down

0 comments on commit ca913a4

Please sign in to comment.