Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Commit 048de56

Browse files
committed
Update todo to enable offline support
1 parent 7f56bee commit 048de56

23 files changed

+355
-287
lines changed

.gitignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ migrate_working_dir/
3131
.pub-cache/
3232
.pub/
3333
/build/
34-
35-
# Web related
36-
lib/generated_plugin_registrant.dart
34+
generated_plugin_registrant.cc
35+
generated_plugin_registrant.h
36+
generated_plugins.cmake
37+
GeneratedPluginRegistrant.swift
3738

3839
# Symbolication related
3940
app.*.symbols
@@ -46,4 +47,4 @@ app.*.map.json
4647
/android/app/profile
4748
/android/app/release
4849

49-
constants.dart
50+
constants.dart

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ Note: If you setup Appwrite on your local machine, you will need to create a pub
1616

1717
We need to make a few configuration changes to your Appwrite server.
1818

19-
1. Add a new Flutter App (Android or iOS or both) in Appwrite:
19+
1. Add a new Flutter App in Appwrite:
2020

2121
![Console - Add platform](docs/Console%20-%20Add%20platform.png)
2222

2323
1. Android - `io.appwrite.demo_todo_with_flutter`
2424
2. iOS/Mac OS - `io.appwrite.demoTodoWithFlutter`
25+
3. Linux - `demo_todo_with_flutter`
2526

2627
2. Create a project in the Appwrite Console with id `demo-todos`.
2728

android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@
3131
android:name="flutterEmbedding"
3232
android:value="2" />
3333
</application>
34+
<uses-permission android:name="android.permission.INTERNET"/>
3435
</manifest>

ios/Flutter/AppFrameworkInfo.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
<key>CFBundleVersion</key>
2222
<string>1.0</string>
2323
<key>MinimumOSVersion</key>
24-
<string>9.0</string>
24+
<string>11.0</string>
2525
</dict>
2626
</plist>

ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Uncomment this line to define a global platform for your project
2-
# platform :ios, '9.0'
2+
# platform :ios, '11.0'
33

44
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
55
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

ios/Podfile.lock

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,45 @@
11
PODS:
2+
- connectivity_plus (0.0.1):
3+
- Flutter
4+
- ReachabilitySwift
25
- device_info_plus (0.0.1):
36
- Flutter
47
- Flutter (1.0.0)
58
- flutter_web_auth_2 (1.1.1):
69
- Flutter
10+
- FMDB (2.7.5):
11+
- FMDB/standard (= 2.7.5)
12+
- FMDB/standard (2.7.5)
713
- package_info_plus (0.4.5):
814
- Flutter
9-
- path_provider_ios (0.0.1):
15+
- path_provider_foundation (0.0.1):
16+
- Flutter
17+
- FlutterMacOS
18+
- ReachabilitySwift (5.0.0)
19+
- sqflite (0.0.2):
1020
- Flutter
21+
- FMDB (>= 2.7.5)
1122
- url_launcher_ios (0.0.1):
1223
- Flutter
1324

1425
DEPENDENCIES:
26+
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`)
1527
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
1628
- Flutter (from `Flutter`)
1729
- flutter_web_auth_2 (from `.symlinks/plugins/flutter_web_auth_2/ios`)
1830
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
19-
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
31+
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/ios`)
32+
- sqflite (from `.symlinks/plugins/sqflite/ios`)
2033
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
2134

35+
SPEC REPOS:
36+
trunk:
37+
- FMDB
38+
- ReachabilitySwift
39+
2240
EXTERNAL SOURCES:
41+
connectivity_plus:
42+
:path: ".symlinks/plugins/connectivity_plus/ios"
2343
device_info_plus:
2444
:path: ".symlinks/plugins/device_info_plus/ios"
2545
Flutter:
@@ -28,19 +48,25 @@ EXTERNAL SOURCES:
2848
:path: ".symlinks/plugins/flutter_web_auth_2/ios"
2949
package_info_plus:
3050
:path: ".symlinks/plugins/package_info_plus/ios"
31-
path_provider_ios:
32-
:path: ".symlinks/plugins/path_provider_ios/ios"
51+
path_provider_foundation:
52+
:path: ".symlinks/plugins/path_provider_foundation/ios"
53+
sqflite:
54+
:path: ".symlinks/plugins/sqflite/ios"
3355
url_launcher_ios:
3456
:path: ".symlinks/plugins/url_launcher_ios/ios"
3557

3658
SPEC CHECKSUMS:
59+
connectivity_plus: 413a8857dd5d9f1c399a39130850d02fe0feaf7e
3760
device_info_plus: e5c5da33f982a436e103237c0c85f9031142abed
38-
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
61+
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
3962
flutter_web_auth_2: a1bc00762c408a8f80b72a538cd7ff5b601c3e71
63+
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
4064
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e
41-
path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02
65+
path_provider_foundation: c68054786f1b4f3343858c1e1d0caaded73f0be9
66+
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
67+
sqflite: 6d358c025f5b867b29ed92fc697fd34924e11904
4268
url_launcher_ios: 839c58cdb4279282219f5e248c3321761ff3c4de
4369

44-
PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c
70+
PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3
4571

4672
COCOAPODS: 1.11.3

ios/Runner.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@
340340
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
341341
GCC_WARN_UNUSED_FUNCTION = YES;
342342
GCC_WARN_UNUSED_VARIABLE = YES;
343-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
343+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
344344
MTL_ENABLE_DEBUG_INFO = NO;
345345
SDKROOT = iphoneos;
346346
SUPPORTED_PLATFORMS = iphoneos;
@@ -417,7 +417,7 @@
417417
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
418418
GCC_WARN_UNUSED_FUNCTION = YES;
419419
GCC_WARN_UNUSED_VARIABLE = YES;
420-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
420+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
421421
MTL_ENABLE_DEBUG_INFO = YES;
422422
ONLY_ACTIVE_ARCH = YES;
423423
SDKROOT = iphoneos;
@@ -466,7 +466,7 @@
466466
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
467467
GCC_WARN_UNUSED_FUNCTION = YES;
468468
GCC_WARN_UNUSED_VARIABLE = YES;
469-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
469+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
470470
MTL_ENABLE_DEBUG_INFO = NO;
471471
SDKROOT = iphoneos;
472472
SUPPORTED_PLATFORMS = iphoneos;

lib/entities/todo.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Todo {
2323

2424
factory Todo.fromMap(Map<String, dynamic> json) => Todo(
2525
content: json["content"],
26-
isComplete: json["isComplete"],
26+
isComplete: json["isComplete"] ?? false,
2727
id: json["\u0024id"],
2828
createdAt: DateTime.parse(json["\u0024createdAt"]),
2929
updatedAt: DateTime.parse(json["\u0024updatedAt"]),

lib/routes/landing.dart

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
import 'package:appwrite/appwrite.dart';
2+
import 'package:demo_todo_with_flutter/utilities.dart';
13
import 'package:flutter/material.dart';
24
import 'package:flutter_svg/flutter_svg.dart';
35

6+
import '../services/appwrite.dart';
7+
import '../services/auth.dart';
48
import '../widgets/animated_icon_button.dart';
59
import 'auth.dart';
10+
import 'todos.dart';
611

712
class Landing extends StatelessWidget {
813
const Landing({Key? key}) : super(key: key);
@@ -92,10 +97,25 @@ class Landing extends StatelessWidget {
9297
),
9398
const SizedBox(height: spacing),
9499
ElevatedButton(
95-
onPressed: () {
96-
Navigator.push(
97-
context,
98-
MaterialPageRoute(builder: (context) => const Auth()),
100+
onPressed: () async {
101+
final navigator = Navigator.of(context);
102+
final messenger = ScaffoldMessenger.of(context);
103+
await Appwrite.instance.initialize();
104+
final authService = AuthService();
105+
Widget nextRoute = const Auth();
106+
107+
try {
108+
await authService.getUser();
109+
nextRoute = const Todos();
110+
} on AppwriteException catch (e) {
111+
if (e.code == 0) {
112+
messenger.showSnackBar(createErrorSnackBar(e.message));
113+
return;
114+
}
115+
}
116+
117+
navigator.push(
118+
MaterialPageRoute(builder: (context) => nextRoute),
99119
);
100120
},
101121
child: const Text('Get Started'),

lib/routes/todos.dart

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:appwrite/appwrite.dart';
12
import 'package:demo_todo_with_flutter/utilities.dart';
23
import 'package:flutter/material.dart';
34

@@ -48,19 +49,19 @@ class _TodosState extends State<Todos> {
4849
void submitTodo() async {
4950
if (inputController.text.isEmpty || isLoading) return;
5051
final messenger = ScaffoldMessenger.of(context);
51-
try {
52-
final newTodo = await todosService.create(content: inputController.text);
53-
inputController.text = '';
54-
setState(() {
55-
todos.add(newTodo);
56-
});
57-
} catch (e) {
52+
final newTodo = Todo(
53+
content: inputController.text,
54+
id: ID.unique(),
55+
);
56+
todosService.create(todo: newTodo).catchError((e) {
5857
messenger.showSnackBar(createErrorSnackBar(e.toString()));
59-
} finally {
60-
setState(() {
61-
isLoading = false;
62-
});
63-
}
58+
todos.remove(newTodo);
59+
});
60+
inputController.text = '';
61+
setState(() {
62+
todos.add(newTodo);
63+
isLoading = false;
64+
});
6465
}
6566

6667
@override
@@ -161,43 +162,40 @@ class _TodosState extends State<Todos> {
161162
});
162163
final messenger = ScaffoldMessenger.of(context);
163164
todos[index].isComplete = !todos[index].isComplete;
164-
try {
165-
final updated =
166-
await todosService.update(todo: todos[index]);
167-
setState(() {
168-
todos[index] = updated;
169-
});
170-
} catch (e) {
171-
// restore value
172-
todos[index].isComplete = !todos[index].isComplete;
173-
messenger.showSnackBar(
174-
createErrorSnackBar(e.toString()));
175-
} finally {
176-
setState(() {
177-
isLoading = false;
178-
});
179-
}
165+
todosService.update(todo: todos[index]).catchError(
166+
(e) {
167+
// restore value
168+
setState(() {
169+
todos[index].isComplete =
170+
!todos[index].isComplete;
171+
});
172+
messenger.showSnackBar(
173+
createErrorSnackBar(e.toString()));
174+
},
175+
);
176+
177+
setState(() {
178+
isLoading = false;
179+
});
180180
},
181181
delete: () async {
182182
setState(() {
183183
isLoading = true;
184184
});
185185
final messenger = ScaffoldMessenger.of(context);
186-
try {
187-
await todosService.delete(id: todos[index].id);
186+
final todo = todos[index];
187+
todosService.delete(id: todo.id).catchError((e) {
188+
// restore value
188189
setState(() {
189-
todos.removeAt(index);
190+
todos.insert(index, todo);
190191
});
191-
} catch (e) {
192-
// restore value
193-
todos[index].isComplete = !todos[index].isComplete;
194192
messenger.showSnackBar(
195193
createErrorSnackBar(e.toString()));
196-
} finally {
197-
setState(() {
198-
isLoading = false;
199-
});
200-
}
194+
});
195+
setState(() {
196+
todos.removeAt(index);
197+
isLoading = false;
198+
});
201199
},
202200
);
203201
},

0 commit comments

Comments
 (0)