Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .github/workflows/supabase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,9 @@ jobs:

- name: Run tests
run: dart test --concurrency=1

- name: Build Dart web app
run: |
dart pub global activate webdev
cd example
webdev build
4 changes: 4 additions & 0 deletions packages/supabase/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/

77 changes: 0 additions & 77 deletions packages/supabase/example/main.dart

This file was deleted.

17 changes: 17 additions & 0 deletions packages/supabase/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: supabase_example
description: An absolute bare-bones supabase web app.
version: 1.0.0
publish_to: none

environment:
sdk: '>=3.3.0 <4.0.0'

dependencies:
web: '>=0.5.0 <2.0.0'
supabase: ^2.9.0

dev_dependencies:
build_runner: any
build_web_compilers: any
lints: ^4.0.0

17 changes: 17 additions & 0 deletions packages/supabase/example/web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>

<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="scaffolded-by" content="https://github.com/dart-lang/sdk" />
<title>dart_web_app</title>
<link rel="stylesheet" href="styles.css" />
<script defer src="main.dart.js"></script>
</head>

<body>
<div id="output"></div>
</body>
</html>
98 changes: 98 additions & 0 deletions packages/supabase/example/web/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import 'dart:typed_data';

import 'package:supabase/supabase.dart';
import 'package:web/web.dart' as web;

void main() {
const supabaseUrl = 'YOUR_SUPABASE_URL';
const supabaseKey = 'YOUR_ANON_KEY';
final supabase = SupabaseClient(supabaseUrl, supabaseKey);

final element = web.document.querySelector('#output') as web.HTMLDivElement;
element.textContent = 'Supabase Dart Web Example';

exampleUsage(supabase);
}

void exampleUsage(SupabaseClient supabase) async {
// query data
final data = await supabase
.from('countries')
.select()
.order('name', ascending: true);
print(data);

// insert data
await supabase.from('countries').insert([
{'name': 'Singapore'},
]);

// update data
await supabase.from('countries').update({'name': 'Singapore'}).eq('id', 1);

// delete data
await supabase.from('countries').delete().eq('id', 1);

// realtime
final realtimeChannel = supabase.channel('my_channel');
realtimeChannel
.onPostgresChanges(
event: PostgresChangeEvent.all,
schema: 'public',
table: 'countries',
callback: (payload) {},
)
.subscribe();

// remember to remove channel when no longer needed
supabase.removeChannel(realtimeChannel);

// stream
final streamSubscription = supabase
.from('countries')
.stream(primaryKey: ['id'])
.order('name')
.limit(10)
.listen((snapshot) {
print('snapshot: $snapshot');
});

// remember to remove subscription
streamSubscription.cancel();

// Upload file to bucket "public" with dart:io

// final file = File('example.txt');
// file.writeAsStringSync('File content');
// final storageResponse = await supabase.storage
// .from('public')
// .upload('example.txt', file);

// Upload file to bucket "public" without dart:io
final content = "my file content";
final storageResponse = await supabase.storage
.from('public')
.uploadBinary('example.txt', Uint8List.fromList(content.codeUnits));
print('upload response : $storageResponse');

// Get download url
final urlResponse = await supabase.storage
.from('public')
.createSignedUrl('example.txt', 60);
print('download url : $urlResponse');

// Download text file
final fileResponse = await supabase.storage
.from('public')
.download('example.txt');
print('downloaded file : ${String.fromCharCodes(fileResponse)}');

// Delete file
final deleteFileResponse = await supabase.storage.from('public').remove([
'example.txt',
]);
print('deleted file id : ${deleteFileResponse.first.id}');

// Local file cleanup on dart:io
// if (file.existsSync()) file.deleteSync();
}
12 changes: 12 additions & 0 deletions packages/supabase/example/web/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
html,
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}

#output {
padding: 20px;
text-align: center;
}
13 changes: 3 additions & 10 deletions packages/supabase/lib/src/constants.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import 'package:supabase/src/version.dart';
import 'dart:io' show Platform;

const bool kIsWeb = bool.fromEnvironment('dart.library.js_util');
import 'platform_stub.dart' if (dart.library.io) 'platform_io.dart';

class Constants {
static String? get platform {
return kIsWeb ? null : Platform.operatingSystem;
}

static String? get platformVersion {
return kIsWeb ? null : Platform.operatingSystemVersion;
}
static String? get platform => condPlatform;
static String? get platformVersion => condPlatformVersion;

static final Map<String, String> defaultHeaders = {
'X-Client-Info': 'supabase-dart/$version',
Expand Down
9 changes: 9 additions & 0 deletions packages/supabase/lib/src/platform_io.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'dart:io';

String? get condPlatform {
return Platform.operatingSystem;
}

String? get condPlatformVersion {
return Platform.operatingSystemVersion;
}
7 changes: 7 additions & 0 deletions packages/supabase/lib/src/platform_stub.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
String? get condPlatform {
return null;
}

String? get condPlatformVersion {
return null;
}
2 changes: 2 additions & 0 deletions packages/supabase/test/utilities_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import 'package:supabase/src/counter.dart';
import 'package:supabase/src/supabase_event_types.dart';
import 'package:test/test.dart';

const bool kIsWeb = bool.fromEnvironment('dart.library.js_util');

void main() {
group('Counter', () {
late Counter counter;
Expand Down
1 change: 0 additions & 1 deletion packages/supabase_flutter/example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ migrate_working_dir/
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols
Expand Down
Loading