Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: lint cleanup

dshukertjreaa5aa5a61e1
diff --git a/examples/todo-list/flutter-todo-list/README.md b/examples/todo-list/flutter-todo-list/README.md
index 8f1af2000ca..117838af68f 100644
--- a/examples/todo-list/flutter-todo-list/README.md
+++ b/examples/todo-list/flutter-todo-list/README.md
@@ -1 +1,64 @@
-A Flutter Supabase CRUD App
+# Flutter Todo example using Supabase
+
+## Build from scratch
+
+### 1. Create new project
+
+Sign up to Supabase - [https://app.supabase.com](https://app.supabase.com) and create a new project. Wait for your database to start.
+
+### 2. Run "Todo List" Quickstart
+
+Once your database has started, run the "Todo List" quickstart. Inside of your project, enter the `SQL editor` tab and scroll down until you see `TODO LIST: Build a basic todo list with Row Level Security`.
+
+### 3. Get the URL and Key
+
+Go to the Project Settings (the cog icon), open the API tab, and find your API URL and `anon` key, you'll need these in the next step.
+
+The `anon` key is your client-side API key. It allows "anonymous access" to your database, until the user has logged in. Once they have logged in, the keys will switch to the user's own login token. This enables row level security for your data. Read more about this [below](#postgres-row-level-security).
+
+![image](https://user-images.githubusercontent.com/10214025/88916245-528c2680-d298-11ea-8a71-708f93e1ce4f.png)
+
+**_NOTE_**: The `service_role` key has full access to your data, bypassing any security policies. These keys have to be kept secret and are meant to be used in server environments and never on a client or browser.
+
+## Supabase details
+
+### Postgres Row level security
+
+This project uses very high-level Authorization using Postgres' Role Level Security.
+When you start a Postgres database on Supabase, we populate it with an `auth` schema, and some helper functions.
+When a user logs in, they are issued a JWT with the role `authenticated` and their UUID.
+We can use these details to provide fine-grained control over what each user can and cannot do.
+
+This is a trimmed-down schema, with the policies:
+
+```sql
+create table todos (
+ id bigint generated by default as identity primary key,
+ user_id uuid references auth.users not null,
+ task text check (char_length(task) > 3),
+ is_complete boolean default false,
+ inserted_at timestamp with time zone default timezone('utc'::text, now()) not null
+);
+
+alter table todos enable row level security;
+
+create policy "Individuals can create todos." on todos for
+ insert with check (auth.uid() = user_id);
+
+create policy "Individuals can view their own todos. " on todos for
+ select using (auth.uid() = user_id);
+
+create policy "Individuals can update their own todos." on todos for
+ update using (auth.uid() = user_id);
+
+create policy "Individuals can delete their own todos." on todos for
+ delete using (auth.uid() = user_id);
+```
+
+## Authors
+
+- [Aniket Singh](https://github.com/Anikets08)
+- [Tyler Shukert](https://github.com/dshukertjr)
+- [Supabase](https://supabase.com)
+
+Supabase is open source. We'd love for you to follow along and get involved at https://github.com/supabase/supabase
diff --git a/examples/todo-list/flutter-todo-list/analysis_options.yaml b/examples/todo-list/flutter-todo-list/analysis_options.yaml
index 61b6c4de17c..dd058571417 100644
--- a/examples/todo-list/flutter-todo-list/analysis_options.yaml
+++ b/examples/todo-list/flutter-todo-list/analysis_options.yaml
@@ -1,29 +1,6 @@
-# This file configures the analyzer, which statically analyzes Dart code to
-# check for errors, warnings, and lints.
-#
-# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
-# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
-# invoked from the command line by running `flutter analyze`.
-
-# The following line activates a set of recommended lints for Flutter apps,
-# packages, and plugins designed to encourage good coding practices.
-include: package:flutter_lints/flutter.yaml
+include: package:lints/recommended.yaml
linter:
- # The lint rules applied to this project can be customized in the
- # section below to disable rules from the `package:flutter_lints/flutter.yaml`
- # included above or to enable additional rules. A list of all available lints
- # and their documentation is published at
- # https://dart-lang.github.io/linter/lints/index.html.
- #
- # Instead of disabling a lint rule for the entire project in the
- # section below, it can also be suppressed for a single line of code
- # or a specific dart file by using the `// ignore: name_of_lint` and
- # `// ignore_for_file: name_of_lint` syntax on the line or in the file
- # producing the lint.
rules:
- # avoid_print: false # Uncomment to disable the `avoid_print` rule
- # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
-
-# Additional information about this file can be found at
-# https://dart.dev/guides/language/analysis-options
+ prefer_single_quotes: true
+ require_trailing_commas: true
\ No newline at end of file
diff --git a/examples/todo-list/flutter-todo-list/lib/constant.dart b/examples/todo-list/flutter-todo-list/lib/constant.dart
index 7209c2c3ec9..ef3ef3651cd 100644
--- a/examples/todo-list/flutter-todo-list/lib/constant.dart
+++ b/examples/todo-list/flutter-todo-list/lib/constant.dart
@@ -5,6 +5,10 @@ const largeGap = SizedBox(height: 40);
final appTheme = ThemeData.dark().copyWith(
scaffoldBackgroundColor: Colors.black,
+ appBarTheme: const AppBarTheme(
+ backgroundColor: Colors.transparent,
+ elevation: 0,
+ ),
outlinedButtonTheme: OutlinedButtonThemeData(
style: OutlinedButton.styleFrom(
primary: Colors.white,
@@ -55,56 +59,17 @@ final appTheme = ThemeData.dark().copyWith(
),
);
-Future<void> displayTextInputDialog(
- BuildContext context,
- Function()? onTab,
- TextEditingController taskCtrl,
- TextEditingController dueCtrl,
-) async {
- return showDialog(
- context: context,
- builder: (context) {
- return AlertDialog(
- title: const Text('Add a todo'),
- content: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- TextField(
- controller: taskCtrl,
- decoration:
- const InputDecoration(hintText: "Add title of todo"),
- ),
- TextField(
- controller: dueCtrl,
- keyboardType: TextInputType.datetime,
- decoration:
- const InputDecoration(hintText: "Add Due Date in DD/MM"),
- ),
- smallGap,
- MaterialButton(
- onPressed: onTab,
- child: const Text("Add Task",
- style: TextStyle(
- color: Colors.white,
- fontWeight: FontWeight.bold,
- )),
- color: const Color(0xff33b27b),
- )
- ],
- ),
- );
- });
-}
-
extension ShowSnackBar on BuildContext {
/// Extention method to easily display error snack bar.
void showErrorSnackbar(String text) {
- ScaffoldMessenger.of(this).showSnackBar(SnackBar(
- content: Text(
- text,
- style: const TextStyle(color: Color(0xFFFFFFFF)),
+ ScaffoldMessenger.of(this).showSnackBar(
+ SnackBar(
+ content: Text(
+ text,
+ style: const TextStyle(color: Color(0xFFFFFFFF)),
+ ),
+ backgroundColor: Colors.red,
),
- backgroundColor: Colors.red,
- ));
+ );
}
}
diff --git a/examples/todo-list/flutter-todo-list/lib/functions/crud.dart b/examples/todo-list/flutter-todo-list/lib/functions/crud.dart
index 31ca5b2cee8..27ce0f63cfe 100644
--- a/examples/todo-list/flutter-todo-list/lib/functions/crud.dart
+++ b/examples/todo-list/flutter-todo-list/lib/functions/crud.dart
@@ -7,7 +7,7 @@ class CrudSupabase {
final res = await AuthSupabase.client
.from('Users')
.select()
- .eq("email", email)
+ .eq('email', email)
.execute();
final data = res.data;
final error = res.error;
@@ -19,20 +19,22 @@ class CrudSupabase {
final res = await AuthSupabase.client
.from('Todo')
.select()
- .eq("email", AuthSupabase.client.auth.currentUser!.email.toString())
+ .eq('email', AuthSupabase.client.auth.currentUser!.email.toString())
.execute();
final data = res.data;
final error = res.error;
return data;
}
- static Future<dynamic> addTodo(
- {required String task, required String due}) async {
+ static Future<dynamic> addTodo({
+ required String task,
+ required String due,
+ }) async {
final res = await AuthSupabase.client.from('Todo').insert({
- "email": AuthSupabase.client.auth.currentUser!.email.toString(),
- "task": task,
- "due": due,
- "done": false
+ 'email': AuthSupabase.client.auth.currentUser!.email.toString(),
+ 'task': task,
+ 'due': due,
+ 'done': false
}).execute();
final data = res.data;
final error = res.error;
@@ -42,19 +44,21 @@ class CrudSupabase {
static Future<void> deleteTodo({required String id}) async {
final res =
- await AuthSupabase.client.from('Todo').delete().eq("id", id).execute();
+ await AuthSupabase.client.from('Todo').delete().eq('id', id).execute();
final data = res.data;
final error = res.error;
print(data);
return data;
}
- static Future<void> taskDone(
- {required String id, required bool value}) async {
+ static Future<void> taskDone({
+ required String id,
+ required bool value,
+ }) async {
final res = await AuthSupabase.client
.from('Todo')
- .update({"done": value})
- .eq("id", id)
+ .update({'done': value})
+ .eq('id', id)
.execute();
final data = res.data;
final error = res.error;
@@ -62,12 +66,15 @@ class CrudSupabase {
return data;
}
- static Future<void> editTask(
- {required String id, required String due, required String task}) async {
+ static Future<void> editTask({
+ required String id,
+ required String due,
+ required String task,
+ }) async {
final res = await AuthSupabase.client
.from('Todo')
- .update({"due": due, "task": task})
- .eq("id", id)
+ .update({'due': due, 'task': task})
+ .eq('id', id)
.execute();
final data = res.data;
final error = res.error;
@@ -75,13 +82,15 @@ class CrudSupabase {
return data;
}
- static Future<dynamic> addUser(
- {required String name, required String email}) async {
+ static Future<dynamic> addUser({
+ required String name,
+ required String email,
+ }) async {
final res = await AuthSupabase.client.from('Users').insert({
- "name": name,
- "email": email,
+ 'name': name,
+ 'email': email,
}).execute();
- print("adding number");
+ print('adding number');
final data = res.data;
final error = res.error;
print(data);
diff --git a/examples/todo-list/flutter-todo-list/lib/screens/signin.dart b/examples/todo-list/flutter-todo-list/lib/screens/signin.dart
index 80783e1024b..6490c54f179 100644
--- a/examples/todo-list/flutter-todo-list/lib/screens/signin.dart
+++ b/examples/todo-list/flutter-todo-list/lib/screens/signin.dart
@@ -17,6 +17,7 @@ class _SignInPageState extends State<SignInPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
+ appBar: AppBar(),
body: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 300),
@@ -24,7 +25,7 @@ class _SignInPageState extends State<SignInPage> {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
- SvgPicture.asset("assets/supabase-dark.svg", width: 200),
+ SvgPicture.asset('assets/supabase-dark.svg', width: 200),
largeGap,
TextFormField(
controller: _emailController,
@@ -33,7 +34,7 @@ class _SignInPageState extends State<SignInPage> {
),
smallGap,
TextFormField(
- controller: _emailController,
+ controller: _passwordController,
decoration: const InputDecoration(label: Text('Password')),
obscureText: true,
),
@@ -51,14 +52,15 @@ class _SignInPageState extends State<SignInPage> {
),
)
: ElevatedButton(
- child: const Text("Sign In"),
+ child: const Text('Sign In'),
onPressed: () async {
setState(() {
loading = true;
});
var value = await AuthSupabase.loginUser(
- email: _emailController.text,
- password: _passwordController.text);
+ email: _emailController.text,
+ password: _passwordController.text,
+ );
setState(() {
loading = false;
});
diff --git a/examples/todo-list/flutter-todo-list/lib/screens/signup.dart b/examples/todo-list/flutter-todo-list/lib/screens/signup.dart
index 55e2baf9db1..baca47c60d9 100644
--- a/examples/todo-list/flutter-todo-list/lib/screens/signup.dart
+++ b/examples/todo-list/flutter-todo-list/lib/screens/signup.dart
@@ -18,6 +18,7 @@ class _SignUpPageState extends State<SignUpPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
+ appBar: AppBar(),
body: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 300),
@@ -25,19 +26,19 @@ class _SignUpPageState extends State<SignUpPage> {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
- SvgPicture.asset("assets/supabase-dark.svg", width: 200),
+ SvgPicture.asset('assets/supabase-dark.svg', width: 200),
largeGap,
TextFormField(
controller: _nameController,
decoration: const InputDecoration(
- label: Text('Full Name'),
+ label: Text('Username'),
),
),
smallGap,
TextFormField(
controller: _emailController,
decoration: const InputDecoration(
- label: Text('Full Name'),
+ label: Text('Email'),
),
keyboardType: TextInputType.emailAddress,
),
@@ -51,16 +52,18 @@ class _SignUpPageState extends State<SignUpPage> {
),
smallGap,
ElevatedButton(
- child: const Text("Sign Up"),
+ child: const Text('Sign Up'),
onPressed: () async {
- var value = await AuthSupabase.createAccount(
- email: _emailController.text,
- password: _passwordController.text);
+ final value = await AuthSupabase.createAccount(
+ email: _emailController.text,
+ password: _passwordController.text,
+ );
if (value == true) {
CrudSupabase.addUser(
- name: _nameController.text,
- email: _emailController.text);
- Navigator.pushReplacementNamed(context, "/signin");
+ name: _nameController.text,
+ email: _emailController.text,
+ );
+ Navigator.pushReplacementNamed(context, '/signin');
}
},
)
diff --git a/examples/todo-list/flutter-todo-list/lib/screens/todo.dart b/examples/todo-list/flutter-todo-list/lib/screens/todo.dart
index df06b42f166..23f0c9a8163 100644
--- a/examples/todo-list/flutter-todo-list/lib/screens/todo.dart
+++ b/examples/todo-list/flutter-todo-list/lib/screens/todo.dart
@@ -17,9 +17,10 @@ class _TodoPageState extends State<TodoPage> {
final TextEditingController _taskEditingController = TextEditingController();
final TextEditingController _dueEditingController = TextEditingController();
- void initFunc() async {
+ Future<void> initFunc() async {
var nameVal = await CrudSupabase.getUser(
- email: AuthSupabase.client.auth.currentUser!.email.toString());
+ email: AuthSupabase.client.auth.currentUser!.email.toString(),
+ );
setState(() {
userName = nameVal[0]['name'];
});
@@ -45,6 +46,50 @@ class _TodoPageState extends State<TodoPage> {
_dueEditingController.dispose();
}
+ Future<void> displayTextInputDialog({
+ required BuildContext context,
+ void Function()? onTab,
+ required TextEditingController taskCtrl,
+ required TextEditingController dueCtrl,
+ }) async {
+ return showDialog(
+ context: context,
+ builder: (context) {
+ return AlertDialog(
+ title: const Text('Add a todo'),
+ content: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ TextField(
+ controller: taskCtrl,
+ decoration:
+ const InputDecoration(hintText: 'Add title of todo'),
+ ),
+ TextField(
+ controller: dueCtrl,
+ keyboardType: TextInputType.datetime,
+ decoration:
+ const InputDecoration(hintText: 'Add Due Date in DD/MM'),
+ ),
+ smallGap,
+ MaterialButton(
+ onPressed: onTab,
+ child: const Text(
+ 'Add Task',
+ style: TextStyle(
+ color: Colors.white,
+ fontWeight: FontWeight.bold,
+ ),
+ ),
+ color: const Color(0xff33b27b),
+ )
+ ],
+ ),
+ );
+ },
+ );
+ }
+
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -69,7 +114,7 @@ class _TodoPageState extends State<TodoPage> {
width: double.infinity,
child: todos.isEmpty
? const Center(
- child: Text("No Task, add new task"),
+ child: Text('No Task, add new task'),
)
: ListView.builder(
itemCount: todos.length,
@@ -77,33 +122,39 @@ class _TodoPageState extends State<TodoPage> {
return ListTile(
//Long Press to edit
onLongPress: () {
- displayTextInputDialog(context, () async {
- await CrudSupabase.editTask(
- id: todos[index]["id"].toString(),
+ displayTextInputDialog(
+ context: context,
+ taskCtrl: _taskEditingController,
+ dueCtrl: _dueEditingController,
+ onTab: () async {
+ await CrudSupabase.editTask(
+ id: todos[index]['id'].toString(),
due: _dueEditingController.text,
- task: _taskEditingController.text);
- Navigator.pop(context);
- setState(() {
- loading = true;
- });
- List<dynamic> value =
- await CrudSupabase.getTodo();
- todos.clear();
- setState(() {});
- for (var element in value) {
- todos.add(element);
- }
- setState(() {
- loading = false;
- });
- }, _taskEditingController, _dueEditingController);
+ task: _taskEditingController.text,
+ );
+ Navigator.pop(context);
+ setState(() {
+ loading = true;
+ });
+ List<dynamic> value =
+ await CrudSupabase.getTodo();
+ todos.clear();
+ setState(() {});
+ for (var element in value) {
+ todos.add(element);
+ }
+ setState(() {
+ loading = false;
+ });
+ },
+ );
},
title: Text(
- todos[index]["task"],
+ todos[index]['task'],
style: const TextStyle(color: Colors.white),
),
subtitle: Text(
- todos[index]["due"],
+ todos[index]['due'],
style: const TextStyle(color: Colors.white),
),
leading: GestureDetector(
@@ -112,7 +163,8 @@ class _TodoPageState extends State<TodoPage> {
loading = true;
});
await CrudSupabase.deleteTodo(
- id: todos[index]["id"].toString());
+ id: todos[index]['id'].toString(),
+ );
List<dynamic> value =
await CrudSupabase.getTodo();
todos.clear();
@@ -135,8 +187,9 @@ class _TodoPageState extends State<TodoPage> {
loading = true;
});
await CrudSupabase.taskDone(
- id: todos[index]["id"].toString(),
- value: !todos[index]["done"]);
+ id: todos[index]['id'].toString(),
+ value: !todos[index]['done'],
+ );
List<dynamic> value =
await CrudSupabase.getTodo();
todos.clear();
@@ -156,12 +209,12 @@ class _TodoPageState extends State<TodoPage> {
color: const Color(0xff33b27b),
width: 2,
),
- color: todos[index]["done"]
+ color: todos[index]['done']
? const Color(0xff33b27b)
: Colors.transparent,
borderRadius: BorderRadius.circular(5),
),
- child: todos[index]["done"]
+ child: todos[index]['done']
? const Center(
child: Icon(
Icons.done,
@@ -174,32 +227,38 @@ class _TodoPageState extends State<TodoPage> {
),
);
},
- )),
+ ),
+ ),
floatingActionButton: FloatingActionButton(
backgroundColor: const Color(0xff33b27b),
+ child: const Icon(Icons.add),
onPressed: () {
- displayTextInputDialog(context, () async {
- await CrudSupabase.addTodo(
- task: _taskEditingController.text,
- due: _dueEditingController.text,
- );
- Navigator.pop(context);
- setState(() {
- loading = true;
- });
+ displayTextInputDialog(
+ context: context,
+ taskCtrl: _taskEditingController,
+ dueCtrl: _dueEditingController,
+ onTab: () async {
+ await CrudSupabase.addTodo(
+ task: _taskEditingController.text,
+ due: _dueEditingController.text,
+ );
+ Navigator.pop(context);
+ setState(() {
+ loading = true;
+ });
- List<dynamic> value = await CrudSupabase.getTodo();
- todos.clear();
- setState(() {});
- for (var element in value) {
- todos.add(element);
- }
- setState(() {
- loading = false;
- });
- }, _taskEditingController, _dueEditingController);
+ List<dynamic> value = await CrudSupabase.getTodo();
+ todos.clear();
+ setState(() {});
+ for (var element in value) {
+ todos.add(element);
+ }
+ setState(() {
+ loading = false;
+ });
+ },
+ );
},
- child: const Icon(Icons.add),
),
);
}
diff --git a/examples/todo-list/flutter-todo-list/pubspec.lock b/examples/todo-list/flutter-todo-list/pubspec.lock
index a899da6fff7..4afdab6011f 100644
--- a/examples/todo-list/flutter-todo-list/pubspec.lock
+++ b/examples/todo-list/flutter-todo-list/pubspec.lock
@@ -42,7 +42,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
- version: "1.15.0"
+ version: "1.16.0"
crypto:
dependency: transitive
description:
@@ -56,7 +56,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
- version: "1.2.0"
+ version: "1.3.0"
ffi:
dependency: transitive
description:
@@ -76,13 +76,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
- flutter_lints:
- dependency: "direct dev"
- description:
- name: flutter_lints
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.0.4"
flutter_svg:
dependency: "direct main"
description:
@@ -148,7 +141,7 @@ packages:
name: js
url: "https://pub.dartlang.org"
source: hosted
- version: "0.6.3"
+ version: "0.6.4"
jwt_decode:
dependency: transitive
description:
@@ -157,12 +150,12 @@ packages:
source: hosted
version: "0.3.1"
lints:
- dependency: transitive
+ dependency: "direct dev"
description:
name: lints
url: "https://pub.dartlang.org"
source: hosted
- version: "1.0.1"
+ version: "2.0.0"
matcher:
dependency: transitive
description:
@@ -176,7 +169,7 @@ packages:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
- version: "0.1.3"
+ version: "0.1.4"
meta:
dependency: transitive
description:
@@ -197,7 +190,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
- version: "1.8.0"
+ version: "1.8.1"
path_drawing:
dependency: transitive
description:
@@ -314,7 +307,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
- version: "1.8.1"
+ version: "1.8.2"
stack_trace:
dependency: transitive
description:
@@ -370,7 +363,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
- version: "0.4.8"
+ version: "0.4.9"
typed_data:
dependency: transitive
description:
@@ -468,7 +461,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
- version: "2.1.1"
+ version: "2.1.2"
web_socket_channel:
dependency: transitive
description:
@@ -498,5 +491,5 @@ packages:
source: hosted
version: "5.3.1"
sdks:
- dart: ">=2.16.1 <3.0.0"
+ dart: ">=2.17.0-206.0.dev <3.0.0"
flutter: ">=2.10.0"
diff --git a/examples/todo-list/flutter-todo-list/pubspec.yaml b/examples/todo-list/flutter-todo-list/pubspec.yaml
index 4fbe0d09274..3d4df48cc8d 100644
--- a/examples/todo-list/flutter-todo-list/pubspec.yaml
+++ b/examples/todo-list/flutter-todo-list/pubspec.yaml
@@ -44,7 +44,7 @@ dev_dependencies:
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
- flutter_lints: ^1.0.0
+ lints: ^2.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec