-
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
17 changed files
with
349 additions
and
59 deletions.
There are no files selected for viewing
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,30 @@ | ||
[ | ||
{ | ||
"title": "Flutter in NLW", | ||
"image": "blocks", | ||
"questionAnswered": 1, | ||
"level": "easy", | ||
"questions": [ | ||
{ | ||
"title": "You are liking Flutter?", | ||
"answers": [ | ||
{"title": "Like"}, | ||
{"title": "Don't like"}, | ||
{"title": "+/-"}, | ||
{"title": "Flutter is sensational", "isRight": true} | ||
] | ||
} | ||
], | ||
"questions": [ | ||
{ | ||
"title": "You are liking Flutter?", | ||
"answers": [ | ||
{"title": "Like"}, | ||
{"title": "Don't like"}, | ||
{"title": "+/-"}, | ||
{"title": "Flutter is sensational", "isRight": true} | ||
] | ||
} | ||
] | ||
} | ||
] |
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,5 @@ | ||
{ | ||
"name": "Felipe Sales", | ||
"score": 75, | ||
"photoUrl": "https://avatars.githubusercontent.com/u/59374587" | ||
} |
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,16 +1,16 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:devquiz/challenge/challenge_page.dart'; | ||
import 'package:devquiz/home/home_page.dart'; | ||
//import 'package:devquiz/challenge/challenge_page.dart'; | ||
// import 'package:devquiz/splash/splash_page.dart'; | ||
//import 'package:devquiz/home/home_page.dart'; | ||
|
||
class AppWidget extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
title: 'DevQuiz', | ||
debugShowCheckedModeBanner: false, | ||
home: ChallengePage(), | ||
home: HomePage(), | ||
); | ||
} | ||
} |
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,32 @@ | ||
import 'package:flutter/foundation.dart'; | ||
|
||
import 'home_repository.dart'; | ||
import 'home_state.dart'; | ||
import 'package:devquiz/shared/models/quiz_model.dart'; | ||
import 'package:devquiz/shared/models/user_model.dart'; | ||
|
||
class HomeController { | ||
ValueNotifier<HomeState> stateNotifier = | ||
ValueNotifier<HomeState>(HomeState.empty); | ||
set state(HomeState state) => stateNotifier.value = state; | ||
HomeState get state => stateNotifier.value; | ||
|
||
UserModel? user; | ||
List<QuizModel>? quizzes; | ||
|
||
final repository = HomeRepository(); | ||
|
||
void getUser() async { | ||
state = HomeState.loading; | ||
await Future.delayed(Duration(seconds: 2)); | ||
user = await repository.getUser(); | ||
state = HomeState.success; | ||
} | ||
|
||
void getQuizzes() async { | ||
state = HomeState.loading; | ||
await Future.delayed(Duration(seconds: 2)); | ||
quizzes = await repository.getQuizzes(); | ||
state = HomeState.success; | ||
} | ||
} |
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,22 @@ | ||
import 'dart:convert'; | ||
import 'package:flutter/services.dart'; | ||
|
||
import 'package:devquiz/shared/models/quiz_model.dart'; | ||
import 'package:devquiz/shared/models/user_model.dart'; | ||
|
||
class HomeRepository { | ||
Future<UserModel> getUser() async { | ||
final response = await rootBundle | ||
.loadString('assets/database/user.json'); | ||
final user = UserModel.fromJson(response); | ||
return user; | ||
} | ||
|
||
Future<List<QuizModel>> getQuizzes() async { | ||
final response = await rootBundle | ||
.loadString('assets/database/quizzes.json'); | ||
final list = jsonDecode(response) as List; | ||
final quizzes = list.map((element) => QuizModel.fromMap(element)).toList(); | ||
return quizzes; | ||
} | ||
} |
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 @@ | ||
enum HomeState{ success, loading, error, empty } |
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,28 @@ | ||
import 'dart:convert'; | ||
|
||
class AnswerModel { | ||
final String title; | ||
final bool isRight; | ||
|
||
AnswerModel({required this.title, this.isRight = false}); | ||
|
||
Map<String, dynamic> toMap() { | ||
return { | ||
'title': title, | ||
'isRight': isRight, | ||
}; | ||
} | ||
|
||
factory AnswerModel.fromMap(Map<String, dynamic> map) { | ||
return AnswerModel( | ||
title: map['title'], | ||
isRight: map['isRight'] ?? false, | ||
); | ||
} | ||
|
||
String toJson() => json.encode(toMap()); | ||
|
||
factory AnswerModel.fromJson(String source) => | ||
AnswerModel.fromMap(json.decode(source)); | ||
} | ||
|
Oops, something went wrong.