-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
295 additions
and
123 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.