Skip to content

Commit

Permalink
Landing πŸ”₯
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecastrosales authored Apr 22, 2021
2 parents d8ac5a8 + b788274 commit 76005a6
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 123 deletions.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion README-pt.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- βœ… Liftoff πŸ’ͺ
- βœ… Maximum Speed πŸƒβ€β™‚οΈ
- βœ… In Orbit πŸ‘¨β€πŸš€
- πŸ”„ Landing πŸ”₯
- βœ… Landing πŸ”₯
- πŸ”„ Surface Exploration ⚑
- πŸ”„ Acelerando sua Carreira πŸš€

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- βœ… Liftoff πŸ’ͺ
- βœ… Maximum Speed πŸƒβ€β™‚οΈ
- βœ… In Orbit πŸ‘¨β€πŸš€
- πŸ”„ Landing πŸ”₯
- βœ… Landing πŸ”₯
- πŸ”„ Surface Exploration ⚑
- πŸ”„ Accelerating your Career πŸš€

Expand Down
4 changes: 1 addition & 3 deletions assets/database/quizzes.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
{"title": "+/-"},
{"title": "Flutter is sensational", "isRight": true}
]
}
],
"questions": [
},
{
"title": "You are liking Flutter?",
"answers": [
Expand Down
7 changes: 7 additions & 0 deletions lib/challenge/challenge_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'package:flutter/foundation.dart';

class ChallengeController {
final currentPageNotifier = ValueNotifier<int>(1);
int get currentPage => currentPageNotifier.value;
set currentPage(int value) => currentPageNotifier.value = value;
}
84 changes: 78 additions & 6 deletions lib/challenge/challenge_page.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,101 @@
import 'package:flutter/material.dart';

import 'challenge_controller.dart';
import 'widgets/question_indicator/question_indicator_widget.dart';
import 'widgets/quiz/quiz_widget.dart';
import 'package:devquiz/shared/models/question_model.dart';
import 'widgets/next_button/next_button_widget.dart';

class ChallengePage extends StatefulWidget {
ChallengePage({Key? key}) : super(key: key);
final List<QuestionModel> questions;
ChallengePage({Key? key, required this.questions}) : super(key: key);

@override
_ChallengePageState createState() => _ChallengePageState();
}

class _ChallengePageState extends State<ChallengePage> {
final controller = ChallengeController();
final pageController = PageController();

@override
initState() {
pageController.addListener(() {
controller.currentPage = pageController.page!.toInt() + 1;
});
super.initState();
}

void nextPage() {
if (controller.currentPage < widget.questions.length)
pageController.nextPage(
duration: Duration(milliseconds: 500),
curve: Curves.linear,
);
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(60),
preferredSize: Size.fromHeight(86),
child: SafeArea(
top: true,
child: QuestionIndicatorWidget(),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
BackButton(),
ValueListenableBuilder<int>(
valueListenable: controller.currentPageNotifier,
builder: (context, value, _) => QuestionIndicatorWidget(
currentPage: value,
length: widget.questions.length,
),
),
],
),
),
),
body: QuizWidget(
title: 'What does the Flutter do in your wholeness?',
body: PageView(
physics: NeverScrollableScrollPhysics(),
controller: pageController,
children: widget.questions
.map((e) => QuizWidget(
question: e,
onChanged: nextPage,
)).toList(),
),
bottomNavigationBar: SafeArea(
bottom: true,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: ValueListenableBuilder<int>(
valueListenable: controller.currentPageNotifier,
builder: (context, value, _) =>
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
if (value < widget.questions.length)
Expanded(
child: NextButtonWidget.white(
label: 'Skip',
onTap: nextPage,
),
),
if (value == widget.questions.length)
Expanded(
child: NextButtonWidget.green(
label: 'Confirm',
onTap: () {
Navigator.pop(context);
},
),
),
],
),
),
),
),
);
}
}
}
102 changes: 59 additions & 43 deletions lib/challenge/widgets/answer/answer_widget.dart
Original file line number Diff line number Diff line change
@@ -1,76 +1,92 @@
import 'package:flutter/material.dart';

import 'package:devquiz/core/core.dart';
import 'package:devquiz/shared/models/answer_model.dart';

class AnswerWidget extends StatelessWidget {
final String title;
final bool isRight;
final AnswerModel answer;
final bool isSelected;
final bool disabled;
final VoidCallback onTap;

const AnswerWidget({
Key? key,
required this.title,
this.isRight = false,
this.isSelected = false,
Key? key,
required this.answer,
required this.onTap,
this.isSelected = false,
this.disabled = false,
}) : super(key: key);

Color get _selectedColorRight =>
isRight ? AppColors.darkGreen : AppColors.darkRed;
answer.isRight ? AppColors.darkGreen : AppColors.darkRed;

Color get _selectedBorderRight =>
isRight ? AppColors.lightGreen : AppColors.lightRed;
answer.isRight ? AppColors.lightGreen : AppColors.lightRed;

Color get _selectedColorCardRight =>
isRight ? AppColors.lightGreen : AppColors.lightRed;
answer.isRight ? AppColors.lightGreen : AppColors.lightRed;

Color get _selectedBorderCardRight =>
isRight ? AppColors.green : AppColors.red;
answer.isRight ? AppColors.green : AppColors.red;

TextStyle get _selectedTextStyleRight =>
isRight ? AppTextStyles.bodyDarkGreen : AppTextStyles.bodyDarkRed;
answer.isRight ? AppTextStyles.bodyDarkGreen : AppTextStyles.bodyDarkRed;

IconData get _selectedIconRight => isRight ? Icons.check : Icons.close;
IconData get _selectedIconRight => answer.isRight ? Icons.check : Icons.close;

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
child: Container(
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: isSelected ? _selectedColorCardRight : AppColors.white,
borderRadius: BorderRadius.circular(10),
border: Border.fromBorderSide(BorderSide(
color: isSelected ? _selectedBorderCardRight : AppColors.border),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
title, style: isSelected
? _selectedTextStyleRight : AppTextStyles.body,
child: IgnorePointer(
ignoring: disabled,
child: GestureDetector(
onTap: onTap,
child: Container(
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: isSelected ? _selectedColorCardRight : AppColors.white,
borderRadius: BorderRadius.circular(10),
border: Border.fromBorderSide(BorderSide(
color: isSelected
? _selectedBorderCardRight
: AppColors.border
),
),
),
SizedBox(width: 16),
Container(
width: 24,
height: 24,
decoration: BoxDecoration(
color: isSelected ? _selectedColorRight : AppColors.white,
borderRadius: BorderRadius.circular(500),
border: Border.fromBorderSide(
BorderSide(
color: isSelected ? _selectedBorderRight : AppColors.border,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
answer.title,
style: isSelected
? _selectedTextStyleRight
: AppTextStyles.body,
),
),
),
child: isSelected
? Icon(_selectedIconRight, color: AppColors.white, size: 16)
: null,
SizedBox(width: 16),
Container(
width: 24,
height: 24,
decoration: BoxDecoration(
color: isSelected ? _selectedColorRight : AppColors.white,
borderRadius: BorderRadius.circular(500),
border: Border.fromBorderSide(
BorderSide(
color: isSelected
? _selectedBorderRight
: AppColors.border,
),
),
),
child: isSelected
? Icon(_selectedIconRight, color: AppColors.white, size: 16)
: null,
),
],
),
],
),
),
),
);
Expand Down
54 changes: 54 additions & 0 deletions lib/challenge/widgets/next_button/next_button_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import 'package:devquiz/core/core.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

class NextButtonWidget extends StatelessWidget {
final String label;
final Color backgroundColor;
final Color fontColor;
final Color borderColor;
final VoidCallback onTap;

const NextButtonWidget({
required this.label,
required this.backgroundColor,
required this.fontColor,
required this.borderColor,
required this.onTap,
});

NextButtonWidget.green({required this.label, required this.onTap})
: this.backgroundColor = AppColors.darkGreen,
this.fontColor = AppColors.white,
this.borderColor = AppColors.green;

NextButtonWidget.white({required this.label, required this.onTap})
: this.backgroundColor = AppColors.white,
this.fontColor = AppColors.grey,
this.borderColor = AppColors.border;

@override
Widget build(BuildContext context) {
return Container(
height: 48,
child: TextButton(
onPressed: onTap,
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all((backgroundColor)),
shape: MaterialStateProperty.all(
RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
),
side: MaterialStateProperty.all(BorderSide(color: borderColor)),
),
child: Text(
label,
style: GoogleFonts.notoSans(
fontWeight: FontWeight.w600,
fontSize: 15,
color: fontColor,
),
),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,32 @@ import 'package:devquiz/core/core.dart';
import 'package:devquiz/shared/widgets/progress_indicator/progress_indicator_widget.dart';

class QuestionIndicatorWidget extends StatelessWidget {
const QuestionIndicatorWidget({Key? key}) : super(key: key);
final int currentPage;
final int length;

const QuestionIndicatorWidget({
Key? key,
required this.currentPage,
required this.length,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Question 04', style: AppTextStyles.body),
Text('of 10', style: AppTextStyles.body),
Text('Question $currentPage', style: AppTextStyles.body),
Text('of $length', style: AppTextStyles.body),
],
),
SizedBox(height: 16),
ProgressIndicatorWidget(value: 0.4),
ProgressIndicatorWidget(value: currentPage / length),
],
),
);
}
}
}
Loading

0 comments on commit 76005a6

Please sign in to comment.