From 14fa8c3815ad8e18f475bc16fc991ab8d86947df Mon Sep 17 00:00:00 2001 From: kekavc24 Date: Mon, 25 Jul 2022 20:32:36 +0300 Subject: [PATCH 01/19] Added missing linter package --- pubspec.lock | 32 +++++++++++++++++++++++--------- pubspec.yaml | 1 + 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index 46afadd..968e68e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -49,7 +49,7 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0" + version: "1.16.0" cookie_jar: dependency: transitive description: @@ -119,7 +119,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.0" ffi: dependency: transitive description: @@ -139,6 +139,13 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" flutter_svg: dependency: "direct main" description: @@ -183,7 +190,14 @@ packages: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.3" + version: "0.6.4" + lints: + dependency: transitive + description: + name: lints + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" matcher: dependency: transitive description: @@ -197,7 +211,7 @@ packages: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "0.1.4" meta: dependency: transitive description: @@ -253,7 +267,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" path_drawing: dependency: transitive description: @@ -356,7 +370,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" stack_trace: dependency: transitive description: @@ -391,7 +405,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.8" + version: "0.4.9" typed_data: dependency: transitive description: @@ -461,7 +475,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "2.1.2" web_socket_channel: dependency: transitive description: @@ -491,5 +505,5 @@ packages: source: hosted version: "5.3.1" sdks: - dart: ">=2.15.0 <3.0.0" + dart: ">=2.17.0-206.0.dev <3.0.0" flutter: ">=2.10.0" diff --git a/pubspec.yaml b/pubspec.yaml index 15fbbe4..4889b9a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,6 +19,7 @@ dev_dependencies: flutter_test: sdk: flutter dart_appwrite: null + flutter_lints: ^2.0.1 flutter: uses-material-design: true From 1c97fb834b8eca37b930206184ba8bb9d334a86f Mon Sep 17 00:00:00 2001 From: kekavc24 Date: Mon, 25 Jul 2022 20:34:58 +0300 Subject: [PATCH 02/19] Updated appwrite sdk to latest version --- pubspec.lock | 58 ++++++++++++++++++++++++++-------------------------- pubspec.yaml | 2 +- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index 968e68e..7575f8b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: appwrite url: "https://pub.dartlang.org" source: hosted - version: "4.0.2" + version: "6.0.0" async: dependency: transitive description: @@ -63,21 +63,21 @@ packages: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "3.0.1" + version: "3.0.2" dart_appwrite: dependency: "direct dev" description: name: dart_appwrite url: "https://pub.dartlang.org" source: hosted - version: "4.0.2" + version: "6.0.0" device_info_plus: dependency: transitive description: name: device_info_plus url: "https://pub.dartlang.org" source: hosted - version: "3.2.3" + version: "3.2.4" device_info_plus_linux: dependency: transitive description: @@ -126,7 +126,7 @@ packages: name: ffi url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.2.1" file: dependency: transitive description: @@ -152,7 +152,7 @@ packages: name: flutter_svg url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "1.1.1+1" flutter_test: dependency: "direct dev" description: flutter @@ -183,7 +183,7 @@ packages: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "4.0.0" + version: "4.0.1" js: dependency: transitive description: @@ -288,56 +288,56 @@ packages: name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "2.0.9" + version: "2.0.11" path_provider_android: dependency: transitive description: name: path_provider_android url: "https://pub.dartlang.org" source: hosted - version: "2.0.12" + version: "2.0.16" path_provider_ios: dependency: transitive description: name: path_provider_ios url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.0.10" path_provider_linux: dependency: transitive description: name: path_provider_linux url: "https://pub.dartlang.org" source: hosted - version: "2.1.5" + version: "2.1.7" path_provider_macos: dependency: transitive description: name: path_provider_macos url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.0.6" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.3" + version: "2.0.4" path_provider_windows: dependency: transitive description: name: path_provider_windows url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.0.7" petitparser: dependency: transitive description: name: petitparser url: "https://pub.dartlang.org" source: hosted - version: "4.4.0" + version: "5.0.0" platform: dependency: transitive description: @@ -412,63 +412,63 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" url_launcher: dependency: "direct main" description: name: url_launcher url: "https://pub.dartlang.org" source: hosted - version: "6.1.0" + version: "6.1.5" url_launcher_android: dependency: transitive description: name: url_launcher_android url: "https://pub.dartlang.org" source: hosted - version: "6.0.15" + version: "6.0.17" url_launcher_ios: dependency: transitive description: name: url_launcher_ios url: "https://pub.dartlang.org" source: hosted - version: "6.0.15" + version: "6.0.17" url_launcher_linux: dependency: transitive description: name: url_launcher_linux url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "3.0.1" url_launcher_macos: dependency: transitive description: name: url_launcher_macos url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "3.0.1" url_launcher_platform_interface: dependency: transitive description: name: url_launcher_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.1.0" url_launcher_web: dependency: transitive description: name: url_launcher_web url: "https://pub.dartlang.org" source: hosted - version: "2.0.9" + version: "2.0.12" url_launcher_windows: dependency: transitive description: name: url_launcher_windows url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "3.0.1" vector_math: dependency: transitive description: @@ -482,14 +482,14 @@ packages: name: web_socket_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.2.0" win32: dependency: transitive description: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "2.5.1" + version: "2.6.1" xdg_directories: dependency: transitive description: @@ -503,7 +503,7 @@ packages: name: xml url: "https://pub.dartlang.org" source: hosted - version: "5.3.1" + version: "6.1.0" sdks: - dart: ">=2.17.0-206.0.dev <3.0.0" - flutter: ">=2.10.0" + dart: ">=2.17.0 <3.0.0" + flutter: ">=3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 4889b9a..692eb43 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ environment: dependencies: flutter: sdk: flutter - appwrite: ^4.0.2 + appwrite: ^6.0.0 url_launcher: ^6.1.0 flutter_svg: ^1.0.3 From fc5591c48afc855c4c392f8ef4d8fb1306b61fd9 Mon Sep 17 00:00:00 2001 From: kekavc24 Date: Mon, 25 Jul 2022 20:37:41 +0300 Subject: [PATCH 03/19] Updated to use latest v0.15.x conventions --- load_questions.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/load_questions.dart b/load_questions.dart index 288a2ae..8aa3686 100644 --- a/load_questions.dart +++ b/load_questions.dart @@ -13,9 +13,9 @@ void main() async { File json = File('./quiz_app_questions.json'); final questions = jsonDecode(json.readAsStringSync()); - Database db = Database(client); - final collectionId = 'quiz_questions'; - final res = await db.createCollection( + Databases db = Databases(client, databaseId: 'DATABASE ID'); + const collectionId = 'quiz_questions'; + await db.createCollection( collectionId: collectionId, name: "Quiz Questions", permission: 'collection', From c98fdef7351ee8673d1872bbcda464db6bf002b9 Mon Sep 17 00:00:00 2001 From: kekavc24 Date: Mon, 25 Jul 2022 20:41:24 +0300 Subject: [PATCH 04/19] Updated to use latest v0.15.x conventions --- lib/constants.dart | 1 + lib/quiz.dart | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/constants.dart b/lib/constants.dart index 221cfbf..b97a4a2 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -2,4 +2,5 @@ class AppConstsnts { static const String endPoint = "https://demo.appwrite.io/v1"; static const String project = "606d5bc9de604"; static const String collection = "606d5bd9626ae"; + static const String databaseID = ""; } diff --git a/lib/quiz.dart b/lib/quiz.dart index f2ca6d7..3128c6a 100644 --- a/lib/quiz.dart +++ b/lib/quiz.dart @@ -4,8 +4,10 @@ import 'package:flutter_appwrite_quizeee/constants.dart'; import 'package:flutter_appwrite_quizeee/question.dart'; class QuizPage extends StatefulWidget { + const QuizPage({Key? key}) : super(key: key); + @override - _QuizPageState createState() => _QuizPageState(); + State createState() => _QuizPageState(); } class _QuizPageState extends State { @@ -32,7 +34,7 @@ class _QuizPageState extends State { Client client = Client(endPoint: AppConstsnts.endPoint); client.setProject(AppConstsnts.project); - Database db = Database(client); + Databases db = Databases(client, databaseId: AppConstsnts.databaseID); /* I'm not a great programmer; I'm just a good programmer with great habits. */ try { final res = await db.listDocuments(collectionId: AppConstsnts.collection); From 5b66041f5d1e0fa224e4d89e0f6c07cb03ffcc10 Mon Sep 17 00:00:00 2001 From: kekavc24 Date: Mon, 25 Jul 2022 20:46:23 +0300 Subject: [PATCH 05/19] Added better url check instead of try-catch --- lib/built_with_appwrite_wrapper.dart | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/built_with_appwrite_wrapper.dart b/lib/built_with_appwrite_wrapper.dart index 8cd160f..7ce0870 100644 --- a/lib/built_with_appwrite_wrapper.dart +++ b/lib/built_with_appwrite_wrapper.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:url_launcher/url_launcher.dart'; +import 'package:url_launcher/url_launcher_string.dart'; class BuiltWithAppwriteWrapper extends StatelessWidget { const BuiltWithAppwriteWrapper({Key? key, required this.child}) @@ -17,12 +18,17 @@ class BuiltWithAppwriteWrapper extends StatelessWidget { ), const SizedBox(height: 10.0), GestureDetector( - onTap: () { - try { - launchUrl(Uri.parse('https://appwrite.io')); - } catch (e) {} - }, - child: SvgPicture.asset('assets/built-with-appwrite-hr.svg')), + onTap: () async { + // + bool canLaunch = await canLaunchUrlString( + 'https://appwrite.io', + ); + // + canLaunch ? launchUrl(Uri.parse('https://appwrite.io')) : null; + // + }, + child: SvgPicture.asset('assets/built-with-appwrite-hr.svg'), + ), const SizedBox(height: 10.0), ], ), From e567b99a295a758e87934de8cd2a101ec5f7972f Mon Sep 17 00:00:00 2001 From: kekavc24 Date: Mon, 25 Jul 2022 20:57:19 +0300 Subject: [PATCH 06/19] Added equatable package --- pubspec.lock | 7 +++++++ pubspec.yaml | 1 + 2 files changed, 8 insertions(+) diff --git a/pubspec.lock b/pubspec.lock index 7575f8b..76ad4e2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -113,6 +113,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.1" + equatable: + dependency: "direct main" + description: + name: equatable + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.3" fake_async: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 692eb43..a3244da 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,6 +14,7 @@ dependencies: appwrite: ^6.0.0 url_launcher: ^6.1.0 flutter_svg: ^1.0.3 + equatable: ^2.0.3 dev_dependencies: flutter_test: From d7f146f184712ea9d65e08f0d01dd147ffc7ecbb Mon Sep 17 00:00:00 2001 From: kekavc24 Date: Mon, 25 Jul 2022 21:06:56 +0300 Subject: [PATCH 07/19] Made Question model cleaner using equatable && used appwrite models instead --- lib/question.dart | 72 ++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 44 deletions(-) diff --git a/lib/question.dart b/lib/question.dart index 559eff2..5d1afaa 100644 --- a/lib/question.dart +++ b/lib/question.dart @@ -1,33 +1,22 @@ import 'dart:convert'; -import 'package:flutter/foundation.dart'; - -class Question { - String? id; - String? question; - List? options; - String? answer; - Question({ - this.id, - this.question, - this.options, - this.answer, +import 'package:appwrite/models.dart'; +import 'package:equatable/equatable.dart'; + +class Question extends Equatable { + // + final String id; + final String question; + final List options; + final String answer; + // + const Question({ + required this.id, + required this.question, + required this.options, + required this.answer, }); - Question copyWith({ - String? id, - String? question, - List? options, - String? answer, - }) { - return Question( - id: id ?? this.id, - question: question ?? this.question, - options: options ?? this.options, - answer: answer ?? this.answer, - ); - } - Map toMap() { return { 'id': id, @@ -39,6 +28,15 @@ class Question { /* Give a man a program, frustrate him for a day. Teach a man to program, frustrate him for a lifetime */ + factory Question.fromModel(Document document) { + return Question( + id: document.$id, + question: document.data['question'], + options: List.from(document.data['options']), + answer: document.data['answer'] + ); + } + factory Question.fromMap(Map map) { return Question( id: map['\$id'], @@ -50,29 +48,15 @@ Teach a man to program, frustrate him for a lifetime */ String toJson() => json.encode(toMap()); - factory Question.fromJson(String source) => Question.fromMap(json.decode(source)); + factory Question.fromJson(String source) => + Question.fromMap(json.decode(source)); @override String toString() { return 'Question(id: $id, question: $question, options: $options, answer: $answer)'; } - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - - return other is Question && - other.id == id && - other.question == question && - listEquals(other.options, options) && - other.answer == answer; - } + /// Equality Operator @override - int get hashCode { - return id.hashCode ^ - question.hashCode ^ - options.hashCode ^ - answer.hashCode; - } + List get props => [id, question, options, answer]; } From ddadb715e29e3d57aacf80e9a5acca419a081982 Mon Sep 17 00:00:00 2001 From: kekavc24 Date: Mon, 25 Jul 2022 21:08:14 +0300 Subject: [PATCH 08/19] Updated to use model --- lib/quiz.dart | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/quiz.dart b/lib/quiz.dart index 3128c6a..dc80a97 100644 --- a/lib/quiz.dart +++ b/lib/quiz.dart @@ -38,7 +38,12 @@ class _QuizPageState extends State { /* I'm not a great programmer; I'm just a good programmer with great habits. */ try { final res = await db.listDocuments(collectionId: AppConstsnts.collection); - questions = res.convertTo((q) => Question.fromMap(q as Map)); + + // Convert using Model instead + questions = res.documents.isEmpty + ? [] + : res.documents.map((e) => Question.fromModel(e)).toList(); + questions!.shuffle(); } on AppwriteException catch (e) { print(e); @@ -72,11 +77,11 @@ class _QuizPageState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - question.question!, + question.question, style: Theme.of(context).textTheme.headline5, ), const SizedBox(height: 10.0), - ...question.options!.map( + ...question.options.map( (opt) => Card( color: _getColor(question, opt), elevation: 1, From 23e726d1728e80c57a15a9ae5965a698eac43a97 Mon Sep 17 00:00:00 2001 From: kekavc24 Date: Mon, 25 Jul 2022 21:11:32 +0300 Subject: [PATCH 09/19] Fixed some linter issues --- lib/home.dart | 4 +++- lib/main.dart | 6 ++++-- lib/quiz.dart | 21 ++++++++++++--------- test/widget_test.dart | 2 +- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/home.dart b/lib/home.dart index d39b5e4..b1bc55a 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -2,6 +2,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_appwrite_quizeee/quiz.dart'; class HomePage extends StatelessWidget { + const HomePage({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { return Scaffold( @@ -23,7 +25,7 @@ class HomePage extends StatelessWidget { ), onPressed: () => Navigator.of(context).push( MaterialPageRoute( - builder: (_) => QuizPage(), + builder: (_) => const QuizPage(), ), ), ), diff --git a/lib/main.dart b/lib/main.dart index 7c01d41..65a1019 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,10 +4,12 @@ import 'package:flutter_appwrite_quizeee/built_with_appwrite_wrapper.dart'; import 'home.dart'; void main() { - runApp(MyApp()); + runApp(const MyApp()); } class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { return MaterialApp( @@ -15,7 +17,7 @@ class MyApp extends StatelessWidget { theme: ThemeData( primarySwatch: Colors.red, ), - home: BuiltWithAppwriteWrapper(child: HomePage()), + home: const BuiltWithAppwriteWrapper(child: HomePage()), ); } } diff --git a/lib/quiz.dart b/lib/quiz.dart index dc80a97..19098b8 100644 --- a/lib/quiz.dart +++ b/lib/quiz.dart @@ -1,4 +1,5 @@ import 'package:appwrite/appwrite.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_appwrite_quizeee/constants.dart'; import 'package:flutter_appwrite_quizeee/question.dart'; @@ -46,7 +47,7 @@ class _QuizPageState extends State { questions!.shuffle(); } on AppwriteException catch (e) { - print(e); + if(kDebugMode) print(e); } finally { setState(() { loading = false; @@ -62,7 +63,7 @@ class _QuizPageState extends State { title: Text("Score: $score"), ), body: loading - ? Center( + ? const Center( child: CircularProgressIndicator(), ) : questions != null && questions!.isNotEmpty @@ -72,7 +73,7 @@ class _QuizPageState extends State { itemCount: questions!.length, itemBuilder: (context, index) { final question = questions![index]; - return Container( + return SizedBox( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -93,8 +94,10 @@ class _QuizPageState extends State { onChanged: _answers[question.id] != null ? null : (dynamic opt) { - if (opt == question.answer) + if (opt == question.answer) { score += 5; + } + setState(() { _answers[question.id] = opt; }); @@ -114,13 +117,13 @@ class _QuizPageState extends State { }, ), ) - : Container( + : const SizedBox( child: Text("Some error! Check console"), ), /* A language that doesn't affect the way you think about programming is not worth knowing. */ bottomNavigationBar: (questions != null && questions!.isNotEmpty) ? BottomAppBar( - child: Container( + child: SizedBox( height: 60.0, child: Row( mainAxisAlignment: MainAxisAlignment.center, @@ -131,7 +134,7 @@ class _QuizPageState extends State { : () { _controller!.jumpToPage(currentPage - 1); }, - child: Text("Prev"), + child: const Text("Prev"), ), const SizedBox(width: 10.0), (currentPage == questions!.length - 1) @@ -139,7 +142,7 @@ class _QuizPageState extends State { onPressed: () { Navigator.pop(context); }, - child: Text("Done"), + child: const Text("Done"), ) : ElevatedButton( onPressed: currentPage >= questions!.length - 1 @@ -147,7 +150,7 @@ class _QuizPageState extends State { : () { _controller!.jumpToPage(currentPage + 1); }, - child: Text("Next"), + child: const Text("Next"), ), ], ), diff --git a/test/widget_test.dart b/test/widget_test.dart index 3543e89..9d9a036 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -13,7 +13,7 @@ import 'package:flutter_appwrite_quizeee/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. - await tester.pumpWidget(MyApp()); + await tester.pumpWidget(const MyApp()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget); From 99b589fab4538debb1bdfc74e8180f91069f15bf Mon Sep 17 00:00:00 2001 From: kekavc24 Date: Wed, 27 Jul 2022 10:48:57 +0300 Subject: [PATCH 10/19] Added database create method --- load_questions.dart | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/load_questions.dart b/load_questions.dart index 8aa3686..172454a 100644 --- a/load_questions.dart +++ b/load_questions.dart @@ -13,7 +13,10 @@ void main() async { File json = File('./quiz_app_questions.json'); final questions = jsonDecode(json.readAsStringSync()); - Databases db = Databases(client, databaseId: 'DATABASE ID'); + Databases db = Databases(client, databaseId: 'unique()'); + + db.create(name: 'Quizy'); // added funky name + const collectionId = 'quiz_questions'; await db.createCollection( collectionId: collectionId, @@ -35,7 +38,7 @@ void main() async { for (final question in questions) { await db.createDocument( - documentId: "unique()", + documentId: "unique()", collectionId: collectionId, data: question, read: ['*'], From e74b883e63f09ef9396c9b12ecd89b0ae08c7e05 Mon Sep 17 00:00:00 2001 From: kekavc24 Date: Wed, 27 Jul 2022 22:22:39 +0300 Subject: [PATCH 11/19] Updated database id to default --- lib/constants.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/constants.dart b/lib/constants.dart index b97a4a2..b81e4a9 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -2,5 +2,5 @@ class AppConstsnts { static const String endPoint = "https://demo.appwrite.io/v1"; static const String project = "606d5bc9de604"; static const String collection = "606d5bd9626ae"; - static const String databaseID = ""; + static const String databaseID = "default"; } From b68701db845591738bd4b7b5a57a976ec0c48ab7 Mon Sep 17 00:00:00 2001 From: kekavc24 Date: Wed, 27 Jul 2022 23:20:07 +0300 Subject: [PATCH 12/19] Changed database ID to default --- load_questions.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/load_questions.dart b/load_questions.dart index 172454a..0ecd902 100644 --- a/load_questions.dart +++ b/load_questions.dart @@ -13,9 +13,9 @@ void main() async { File json = File('./quiz_app_questions.json'); final questions = jsonDecode(json.readAsStringSync()); - Databases db = Databases(client, databaseId: 'unique()'); + Databases db = Databases(client, databaseId: 'default'); - db.create(name: 'Quizy'); // added funky name + await db.create(name: 'default'); // added funky name const collectionId = 'quiz_questions'; await db.createCollection( From 48d0555228d70440ddc20b7215fc3ff99f4d72fa Mon Sep 17 00:00:00 2001 From: kelvin kavisi <68240897+kekavc24@users.noreply.github.com> Date: Wed, 27 Jul 2022 23:27:14 +0300 Subject: [PATCH 13/19] Update load_questions.dart Co-authored-by: Brandon --- load_questions.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/load_questions.dart b/load_questions.dart index 0ecd902..0dabb3e 100644 --- a/load_questions.dart +++ b/load_questions.dart @@ -15,7 +15,7 @@ void main() async { Databases db = Databases(client, databaseId: 'default'); - await db.create(name: 'default'); // added funky name + await db.create(name: 'default'); const collectionId = 'quiz_questions'; await db.createCollection( From 2e0ca04a4521108d5b057eabf2f6ebf74a0e475e Mon Sep 17 00:00:00 2001 From: kekavc24 Date: Sat, 30 Jul 2022 12:04:47 +0300 Subject: [PATCH 14/19] Fixed read permission --- load_questions.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/load_questions.dart b/load_questions.dart index 0dabb3e..0b16396 100644 --- a/load_questions.dart +++ b/load_questions.dart @@ -41,7 +41,7 @@ void main() async { documentId: "unique()", collectionId: collectionId, data: question, - read: ['*'], + read: ['role:all'], write: ['role:member']); print(question); } From 825d2181266d7a34d465b58d9733f2cd6ee50da1 Mon Sep 17 00:00:00 2001 From: kekavc24 Date: Sat, 30 Jul 2022 12:10:43 +0300 Subject: [PATCH 15/19] Changed constant --- lib/constants.dart | 2 +- lib/quiz.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/constants.dart b/lib/constants.dart index b81e4a9..3b98dfe 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -2,5 +2,5 @@ class AppConstsnts { static const String endPoint = "https://demo.appwrite.io/v1"; static const String project = "606d5bc9de604"; static const String collection = "606d5bd9626ae"; - static const String databaseID = "default"; + static const String database = "default"; } diff --git a/lib/quiz.dart b/lib/quiz.dart index 19098b8..ace0f72 100644 --- a/lib/quiz.dart +++ b/lib/quiz.dart @@ -35,7 +35,7 @@ class _QuizPageState extends State { Client client = Client(endPoint: AppConstsnts.endPoint); client.setProject(AppConstsnts.project); - Databases db = Databases(client, databaseId: AppConstsnts.databaseID); + Databases db = Databases(client, databaseId: AppConstsnts.database); /* I'm not a great programmer; I'm just a good programmer with great habits. */ try { final res = await db.listDocuments(collectionId: AppConstsnts.collection); From c64fa23ced534202383a6061edfe2034ad44ed57 Mon Sep 17 00:00:00 2001 From: kekavc24 Date: Sat, 30 Jul 2022 13:03:00 +0300 Subject: [PATCH 16/19] Added delay && Updated app constants --- lib/constants.dart | 2 +- load_questions.dart | 39 +++++++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/lib/constants.dart b/lib/constants.dart index 3b98dfe..3ca1afc 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -1,6 +1,6 @@ class AppConstsnts { static const String endPoint = "https://demo.appwrite.io/v1"; static const String project = "606d5bc9de604"; - static const String collection = "606d5bd9626ae"; + static const String collection = "quiz_questions"; static const String database = "default"; } diff --git a/load_questions.dart b/load_questions.dart index 0b16396..21f5876 100644 --- a/load_questions.dart +++ b/load_questions.dart @@ -26,23 +26,38 @@ void main() async { write: ["role:member"]); await db.createStringAttribute( - collectionId: collectionId, key: 'question', size: 255, xrequired: true); + collectionId: collectionId, + key: 'question', + size: 255, + xrequired: true, + ); + await db.createStringAttribute( - collectionId: collectionId, - key: 'options', - size: 255, - xrequired: false, - array: true); + collectionId: collectionId, + key: 'options', + size: 255, + xrequired: false, + array: true, + ); + await db.createStringAttribute( - collectionId: collectionId, key: 'answer', size: 255, xrequired: true); + collectionId: collectionId, + key: 'answer', + size: 255, + xrequired: true, + ); + + await Future.delayed(const Duration(seconds: 2)); for (final question in questions) { await db.createDocument( - documentId: "unique()", - collectionId: collectionId, - data: question, - read: ['role:all'], - write: ['role:member']); + documentId: "unique()", + collectionId: collectionId, + data: question, + read: ['role:all'], + write: ['role:member'], + ); + print(question); } From f27acf1d748c04825e7677d604dcbdb5cbdd2bd0 Mon Sep 17 00:00:00 2001 From: kekavc24 Date: Sat, 30 Jul 2022 17:59:17 +0300 Subject: [PATCH 17/19] Fixed typo --- lib/constants.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/constants.dart b/lib/constants.dart index 3ca1afc..3899964 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -1,4 +1,4 @@ -class AppConstsnts { +class AppConstants { static const String endPoint = "https://demo.appwrite.io/v1"; static const String project = "606d5bc9de604"; static const String collection = "quiz_questions"; From 7709fcb047aa4f12ca7b07534222e59dd3b08b08 Mon Sep 17 00:00:00 2001 From: kekavc24 Date: Sat, 30 Jul 2022 18:03:58 +0300 Subject: [PATCH 18/19] Fixed suggested issues --- lib/quiz.dart | 74 ++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/lib/quiz.dart b/lib/quiz.dart index ace0f72..24651e0 100644 --- a/lib/quiz.dart +++ b/lib/quiz.dart @@ -32,13 +32,13 @@ class _QuizPageState extends State { setState(() { loading = true; }); - Client client = Client(endPoint: AppConstsnts.endPoint); - client.setProject(AppConstsnts.project); + Client client = Client(endPoint: AppConstants.endPoint); + client.setProject(AppConstants.project); - Databases db = Databases(client, databaseId: AppConstsnts.database); + Databases db = Databases(client, databaseId: AppConstants.database); /* I'm not a great programmer; I'm just a good programmer with great habits. */ try { - final res = await db.listDocuments(collectionId: AppConstsnts.collection); + final res = await db.listDocuments(collectionId: AppConstants.collection); // Convert using Model instead questions = res.documents.isEmpty @@ -73,40 +73,38 @@ class _QuizPageState extends State { itemCount: questions!.length, itemBuilder: (context, index) { final question = questions![index]; - return SizedBox( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - question.question, - style: Theme.of(context).textTheme.headline5, - ), - const SizedBox(height: 10.0), - ...question.options.map( - (opt) => Card( - color: _getColor(question, opt), - elevation: 1, - clipBehavior: Clip.antiAlias, - child: RadioListTile( - value: opt, - title: Text(opt), - groupValue: _answers[question.id], - onChanged: _answers[question.id] != null - ? null - : (dynamic opt) { - if (opt == question.answer) { - score += 5; - } + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + question.question, + style: Theme.of(context).textTheme.headline5, + ), + const SizedBox(height: 10.0), + ...question.options.map( + (opt) => Card( + color: _getColor(question, opt), + elevation: 1, + clipBehavior: Clip.antiAlias, + child: RadioListTile( + value: opt, + title: Text(opt), + groupValue: _answers[question.id], + onChanged: _answers[question.id] != null + ? null + : (dynamic opt) { + if (opt == question.answer) { + score += 5; + } - setState(() { - _answers[question.id] = opt; - }); - }, - ), + setState(() { + _answers[question.id] = opt; + }); + }, ), - ) - ], - ), + ), + ) + ], ); }, controller: _controller, @@ -117,9 +115,7 @@ class _QuizPageState extends State { }, ), ) - : const SizedBox( - child: Text("Some error! Check console"), - ), + : const Text("Some error! Check console"), /* A language that doesn't affect the way you think about programming is not worth knowing. */ bottomNavigationBar: (questions != null && questions!.isNotEmpty) ? BottomAppBar( From 915b528bacbf2c1f9f81572b22869f89a0984774 Mon Sep 17 00:00:00 2001 From: kekavc24 Date: Sat, 30 Jul 2022 18:23:43 +0300 Subject: [PATCH 19/19] Pulled changes --- LICENSE copy | 21 --------------------- README.md | 20 +++++++++++--------- 2 files changed, 11 insertions(+), 30 deletions(-) delete mode 100644 LICENSE copy diff --git a/LICENSE copy b/LICENSE copy deleted file mode 100644 index 71bae4e..0000000 --- a/LICENSE copy +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021 Appwrite - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/README.md b/README.md index 52f04f1..60aff65 100644 --- a/README.md +++ b/README.md @@ -4,18 +4,18 @@ A simple Quiz App built with Flutter and Appwrite - ## 🎬 Getting Started -### 🤘 Install Appwrite -Follow our simple [Installation Guide](https://appwrite.io/docs/installation) to get Appwrite up and running in no time. You can either deploy Appwrite on your local machine or, on any cloud provider of your choice. +### 🤘 Install Appwrite + +Follow our simple [Installation Guide](https://appwrite.io/docs/installation) to get Appwrite up and running in no time. You can either deploy Appwrite on your local machine or, on any cloud provider of your choice. > Note: If you setup Appwrite on your local machine, you will need to create a public IP so that your hosted frontend can access it. - -We need to make a few configuration changes to your Appwrite server. + +We need to make a few configuration changes to your Appwrite server. 1. Add a new Flutter App (Android or iOS or both) in Appwrite and enter application id of your application (`io.appwrite.quiz` etc) -![Add Flutter App](https://user-images.githubusercontent.com/20852629/113019434-3c27c900-919f-11eb-997c-1da5a8303ceb.png) + ![Add Flutter App](https://user-images.githubusercontent.com/20852629/113019434-3c27c900-919f-11eb-997c-1da5a8303ceb.png) 2. Create a new API Key from Api Keys section @@ -23,16 +23,18 @@ We need to make a few configuration changes to your Appwrite server. 4. Run `flutter pub get` to get the dependencies and then run `load_questions.dart` using `dart /load_questions.dart` -5. In the appwrite console in your project, it will create new collection, the collection id is also printed at the end of the script in the console. Get the id of that collection and update `lib/constants.dart` with your own `ednpoint`, `project id` and `collection id` +5. In the appwrite console in your project, it will create new collection, the collection id is also printed at the end of the script in the console. Get the id of that collection and update `lib/constants.dart` with your own `endpoint`, `project id` and `collection id` ### 🚀 Run the Application + First get the dependencies by running `flutter pub get`. Then you can run the application simply using `flutter run` command. It works on **Android**, **iOS** and **Web** platforms. ## 🤕 Support If you get stuck anywhere, hop onto one of our [support channels in discord](https://appwrite.io/discord) and we'd be delighted to help you out 🤝 -## 😧 Help Wanted +## 😧 Help Wanted + Our access credentials were recently compromised and someone tried to ruin these demos. They decided to leave behind 15 easter eggs 🥚 for you to discover. If you find them, submit a PR cleaning up that section of the code (One PR per person across all the repos). You can track the number of claimed Easter Eggs using the badge at the top. -The first 15 people to get their PRs merged will receive some Appwrite Swags 🤩 . Just head over to our [Discord channel](https://appwrite.io/discord) and share your PR link with us. \ No newline at end of file +The first 15 people to get their PRs merged will receive some Appwrite Swags 🤩 . Just head over to our [Discord channel](https://appwrite.io/discord) and share your PR link with us.