Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ migrate_working_dir/
.pub-cache/
.pub/
/build/

# Web related
lib/generated_plugin_registrant.dart
generated_plugin_registrant.cc
generated_plugin_registrant.h
generated_plugins.cmake
GeneratedPluginRegistrant.swift

# Symbolication related
app.*.symbols
Expand All @@ -46,4 +47,4 @@ app.*.map.json
/android/app/profile
/android/app/release

constants.dart
constants.dart
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ Note: If you setup Appwrite on your local machine, you will need to create a pub

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:
1. Add a new Flutter App in Appwrite:

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

1. Android - `io.appwrite.demo_todo_with_flutter`
2. iOS/Mac OS - `io.appwrite.demoTodoWithFlutter`
3. Linux - `demo_todo_with_flutter`

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

Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@
android:name="flutterEmbedding"
android:value="2" />
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
2 changes: 1 addition & 1 deletion ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>11.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
# platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
40 changes: 33 additions & 7 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
PODS:
- connectivity_plus (0.0.1):
- Flutter
- ReachabilitySwift
- device_info_plus (0.0.1):
- Flutter
- Flutter (1.0.0)
- flutter_web_auth_2 (1.1.1):
- Flutter
- FMDB (2.7.5):
- FMDB/standard (= 2.7.5)
- FMDB/standard (2.7.5)
- package_info_plus (0.4.5):
- Flutter
- path_provider_ios (0.0.1):
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
- ReachabilitySwift (5.0.0)
- sqflite (0.0.2):
- Flutter
- FMDB (>= 2.7.5)
- url_launcher_ios (0.0.1):
- Flutter

DEPENDENCIES:
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`)
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
- Flutter (from `Flutter`)
- flutter_web_auth_2 (from `.symlinks/plugins/flutter_web_auth_2/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/ios`)
- sqflite (from `.symlinks/plugins/sqflite/ios`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)

SPEC REPOS:
trunk:
- FMDB
- ReachabilitySwift

EXTERNAL SOURCES:
connectivity_plus:
:path: ".symlinks/plugins/connectivity_plus/ios"
device_info_plus:
:path: ".symlinks/plugins/device_info_plus/ios"
Flutter:
Expand All @@ -28,19 +48,25 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/flutter_web_auth_2/ios"
package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios"
path_provider_ios:
:path: ".symlinks/plugins/path_provider_ios/ios"
path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/ios"
sqflite:
:path: ".symlinks/plugins/sqflite/ios"
url_launcher_ios:
:path: ".symlinks/plugins/url_launcher_ios/ios"

SPEC CHECKSUMS:
connectivity_plus: 413a8857dd5d9f1c399a39130850d02fe0feaf7e
device_info_plus: e5c5da33f982a436e103237c0c85f9031142abed
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_web_auth_2: a1bc00762c408a8f80b72a538cd7ff5b601c3e71
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e
path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02
path_provider_foundation: c68054786f1b4f3343858c1e1d0caaded73f0be9
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
sqflite: 6d358c025f5b867b29ed92fc697fd34924e11904
url_launcher_ios: 839c58cdb4279282219f5e248c3321761ff3c4de

PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c
PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3

COCOAPODS: 1.11.3
6 changes: 3 additions & 3 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -417,7 +417,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -466,7 +466,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
2 changes: 1 addition & 1 deletion lib/entities/todo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Todo {

factory Todo.fromMap(Map<String, dynamic> json) => Todo(
content: json["content"],
isComplete: json["isComplete"],
isComplete: json["isComplete"] ?? false,
id: json["\u0024id"],
createdAt: DateTime.parse(json["\u0024createdAt"]),
updatedAt: DateTime.parse(json["\u0024updatedAt"]),
Expand Down
28 changes: 24 additions & 4 deletions lib/routes/landing.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import 'package:appwrite/appwrite.dart';
import 'package:demo_todo_with_flutter/utilities.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

import '../services/appwrite.dart';
import '../services/auth.dart';
import '../widgets/animated_icon_button.dart';
import 'auth.dart';
import 'todos.dart';

class Landing extends StatelessWidget {
const Landing({Key? key}) : super(key: key);
Expand Down Expand Up @@ -92,10 +97,25 @@ class Landing extends StatelessWidget {
),
const SizedBox(height: spacing),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const Auth()),
onPressed: () async {
final navigator = Navigator.of(context);
final messenger = ScaffoldMessenger.of(context);
await Appwrite.instance.initialize();
final authService = AuthService();
Widget nextRoute = const Auth();

try {
await authService.getUser();
nextRoute = const Todos();
} on AppwriteException catch (e) {
if (e.code == 0) {
messenger.showSnackBar(createErrorSnackBar(e.message));
return;
}
}

navigator.push(
MaterialPageRoute(builder: (context) => nextRoute),
);
},
child: const Text('Get Started'),
Expand Down
76 changes: 37 additions & 39 deletions lib/routes/todos.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:appwrite/appwrite.dart';
import 'package:demo_todo_with_flutter/utilities.dart';
import 'package:flutter/material.dart';

Expand Down Expand Up @@ -48,19 +49,19 @@ class _TodosState extends State<Todos> {
void submitTodo() async {
if (inputController.text.isEmpty || isLoading) return;
final messenger = ScaffoldMessenger.of(context);
try {
final newTodo = await todosService.create(content: inputController.text);
inputController.text = '';
setState(() {
todos.add(newTodo);
});
} catch (e) {
final newTodo = Todo(
content: inputController.text,
id: ID.unique(),
);
todosService.create(todo: newTodo).catchError((e) {
messenger.showSnackBar(createErrorSnackBar(e.toString()));
} finally {
setState(() {
isLoading = false;
});
}
todos.remove(newTodo);
});
inputController.text = '';
setState(() {
todos.add(newTodo);
isLoading = false;
});
}

@override
Expand Down Expand Up @@ -161,43 +162,40 @@ class _TodosState extends State<Todos> {
});
final messenger = ScaffoldMessenger.of(context);
todos[index].isComplete = !todos[index].isComplete;
try {
final updated =
await todosService.update(todo: todos[index]);
setState(() {
todos[index] = updated;
});
} catch (e) {
// restore value
todos[index].isComplete = !todos[index].isComplete;
messenger.showSnackBar(
createErrorSnackBar(e.toString()));
} finally {
setState(() {
isLoading = false;
});
}
todosService.update(todo: todos[index]).catchError(
(e) {
// restore value
setState(() {
todos[index].isComplete =
!todos[index].isComplete;
});
messenger.showSnackBar(
createErrorSnackBar(e.toString()));
},
);

setState(() {
isLoading = false;
});
},
delete: () async {
setState(() {
isLoading = true;
});
final messenger = ScaffoldMessenger.of(context);
try {
await todosService.delete(id: todos[index].id);
final todo = todos[index];
todosService.delete(id: todo.id).catchError((e) {
// restore value
setState(() {
todos.removeAt(index);
todos.insert(index, todo);
});
} catch (e) {
// restore value
todos[index].isComplete = !todos[index].isComplete;
messenger.showSnackBar(
createErrorSnackBar(e.toString()));
} finally {
setState(() {
isLoading = false;
});
}
});
setState(() {
todos.removeAt(index);
isLoading = false;
});
},
);
},
Expand Down
12 changes: 11 additions & 1 deletion lib/services/appwrite.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@ class Appwrite {
return instance;
}

Future<void> initialize() {
return client.setOfflinePersistency(
status: true,
onWriteQueueError: (e) {
print(e);
},
);
}

Appwrite._internal() {
client = Client()
.setEndpoint(constants.appwriteEndpoint)
.setProject(constants.appwriteProjectId)
.setSelfSigned(status: constants.appwriteSelfSigned);
.setSelfSigned(status: constants.appwriteSelfSigned)
.setOfflineCacheSize(2500);
}
}
4 changes: 4 additions & 0 deletions lib/services/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ class AuthService {
Future<void> logout() {
return _account.deleteSession(sessionId: 'current');
}

Future<models.Account> getUser() async {
return _account.get();
}
}
6 changes: 3 additions & 3 deletions lib/services/todos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class TodosService {
return documentList.documents.map((d) => Todo.fromMap(d.data)).toList();
}

Future<Todo> create({required String content}) async {
Future<Todo> create({required Todo todo}) async {
final document = await _databases.createDocument(
databaseId: constants.appwriteDatabaseId,
collectionId: constants.appwriteCollectionId,
documentId: ID.unique(),
data: {"content": content},
documentId: todo.id,
data: {"content": todo.content, "isComplete": todo.isComplete},
);

return Todo.fromMap(document.data);
Expand Down
1 change: 1 addition & 0 deletions lib/widgets/todo_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class TodoListTile extends StatelessWidget {
: TextDecoration.none,
),
),
subtitle: Text(todo.id),
);
}
}
15 changes: 0 additions & 15 deletions linux/flutter/generated_plugin_registrant.cc

This file was deleted.

Loading