generated from xmartlabs/flutter-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add dart toggle edge function (#22)
- Loading branch information
Showing
12 changed files
with
669 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"flutterSdkVersion": "3.7.12", | ||
"flavors": {} | ||
} |
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,3 @@ | ||
.dart_tool | ||
/functions/ | ||
.fvm/flutter_sdk |
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,21 @@ | ||
# Supabase Edge Functions Example | ||
|
||
This template demonstrates how to run a [Supabase Edge Functions](https://supabase.com/docs/guides/functions) application via Dart Edge. | ||
|
||
## Getting Started | ||
|
||
Install the dependencies: | ||
|
||
```bash | ||
dart pub get | ||
``` | ||
|
||
Start the application via Dart Edge CLU & the [`supabase` CLI](https://supabase.com/docs/guides/cli): | ||
|
||
```bash | ||
supabase init | ||
fvm dart run edge build supabase_functions | ||
supabase functions serve dart_edge | ||
``` | ||
|
||
For more information, see the [Dart Edge documentation](https://docs.dartedge.dev). |
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,24 @@ | ||
# This file configures the static analysis results for your project (errors, | ||
# warnings, and lints). | ||
# | ||
# This enables the 'recommended' set of lints from `package:lints`. | ||
# This set helps identify many issues that may lead to problems when running | ||
# or consuming Dart code, and enforces writing Dart using a single, idiomatic | ||
# style and format. | ||
# | ||
# If you want a smaller set of lints you can change this to specify | ||
# 'package:lints/core.yaml'. These are just the most critical lints | ||
# (the recommended set includes the core lints). | ||
# The core lints are also what is used by pub.dev for scoring packages. | ||
|
||
include: package:lints/recommended.yaml | ||
|
||
# analyzer: | ||
# exclude: | ||
# - path/to/excluded/files/** | ||
|
||
# For more information about the core and recommended set of lints, see | ||
# https://dart.dev/go/core-lints | ||
|
||
# For additional information about configuring this file, see | ||
# https://dart.dev/guides/language/analysis-options |
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,3 @@ | ||
supabase: | ||
functions: | ||
toggle_message: 'lib/toggle_message.dart' |
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 'dart:convert'; | ||
|
||
import 'package:edge_http_client/edge_http_client.dart'; | ||
import 'package:supabase/supabase.dart'; | ||
import 'package:supabase_functions/supabase_functions.dart'; | ||
|
||
void main() { | ||
final supabaseClient = SupabaseClient( | ||
Deno.env.get('SUPABASE_URL')!, | ||
Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!, | ||
httpClient: EdgeHttpClient(), | ||
); | ||
|
||
SupabaseFunctions(fetch: (request) async { | ||
final dynamic body = await request.json(); | ||
final messageId = body['id']; | ||
|
||
final List<dynamic> messages = | ||
await supabaseClient.from('messages').select('body').eq('id', messageId); | ||
|
||
var newBody = (messages[0]['body'] as String).toggleCase(); | ||
await supabaseClient | ||
.from('messages') | ||
.update({'body': newBody}).eq('id', messageId); | ||
|
||
return Response(jsonEncode({"message": "ok"}), status: 200); | ||
}); | ||
} | ||
|
||
extension _StringExtensions on String { | ||
String toggleCase() => this == toUpperCase() ? toLowerCase() : toUpperCase(); | ||
} |
Oops, something went wrong.