Skip to content

Commit

Permalink
Update Flutter SDK to add offline support
Browse files Browse the repository at this point in the history
  • Loading branch information
stnguyen90 committed Mar 14, 2023
1 parent 811bd17 commit 896224c
Show file tree
Hide file tree
Showing 19 changed files with 2,064 additions and 174 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 9.0.0

* Add offline support

## 8.3.0

* Fix: back navigation bringing back web browser after OAuth session creation
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

[![pub package](https://img.shields.io/pub/v/appwrite?style=flat-square)](https://pub.dartlang.org/packages/appwrite)
![License](https://img.shields.io/github/license/appwrite/sdk-for-flutter.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.2.1-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.3.0-blue.svg?style=flat-square)
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)

**This SDK is compatible with Appwrite server version 1.2.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-flutter/releases).**
**This SDK is compatible with Appwrite server version 1.3.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-flutter/releases).**

Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Flutter SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)

Expand All @@ -21,7 +21,7 @@ Add this to your package's `pubspec.yaml` file:

```yml
dependencies:
appwrite: ^8.3.0
appwrite: ^9.0.0
```
You can install packages from the command line:
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name: appwrite_example
environment:
sdk: '>=2.17.0 <3.0.0'
sdk: ">=2.17.0 <3.0.0"
13 changes: 7 additions & 6 deletions lib/appwrite.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
library appwrite;

import 'dart:async';
import 'dart:math';
import 'dart:typed_data';
import 'src/enums.dart';
import 'src/service.dart';
import 'src/input_file.dart';
import 'models.dart' as models;
import 'src/upload_progress.dart';

export 'src/response.dart';
export 'src/client.dart';
export 'src/exception.dart';
export 'src/input_file.dart';
export 'src/realtime.dart';
export 'src/upload_progress.dart';
export 'src/realtime_subscription.dart';
export 'src/realtime_message.dart';
export 'src/input_file.dart';
export 'src/realtime_subscription.dart';
export 'src/response.dart';
export 'src/upload_progress.dart';

part 'query.dart';
part 'id.dart';
part 'permission.dart';
part 'query.dart';
part 'role.dart';
part 'id.dart';
part 'services/account.dart';
part 'services/avatars.dart';
part 'services/databases.dart';
Expand Down
43 changes: 35 additions & 8 deletions lib/id.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
part of appwrite;

class ID {
ID._();

static String unique() {
return 'unique()';
}
ID._();

// Generate a unique ID based on timestamp
// Recreated from https://www.php.net/manual/en/function.uniqid.php
static String _uniqid() {
final now = DateTime.now();
final secondsSinceEpoch = (now.millisecondsSinceEpoch / 1000).floor();
final msecs = now.microsecondsSinceEpoch - secondsSinceEpoch * 1000000;
return secondsSinceEpoch.toRadixString(16) +
msecs.toRadixString(16).padLeft(5, '0');
}

// Generate a unique ID with padding to have a longer ID
// Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
static String _unique({int padding = 7}) {
String id = _uniqid();

if (padding > 0) {
StringBuffer sb = StringBuffer();
for (var i = 0; i < padding; i++) {
sb.write(Random().nextInt(16).toRadixString(16));
}

static String custom(String id) {
return id;
id += sb.toString();
}
}

return id;
}

static String unique() {
return _unique();
}

static String custom(String id) {
return id;
}
}
Loading

0 comments on commit 896224c

Please sign in to comment.