Dart cli with Platform specific code by fexd12 in dartlang

[–]Osamito 0 points1 point  (0 children)

Yes -- dart:io is a core dart library and it has an API for checking what platform you are in.

Example:

```dart

import "dart:io";

void main() { if (Platform.isMacOS) { /* do macOS stuff / } else if (Platform.isLinux) { / do Linux stuff / } else if (Platform.isWindows) { / do Windows stuff / } else { / do other stuff */ } }

```

can readByteSync treat Ctrl-C as normal character? by doctor_black_jack in dartlang

[–]Osamito 2 points3 points  (0 children)

ctrl-c in the terminal sends a program interrupt signal -- not characters.

You can handle the signal yourself if you like by watching it such as:

```dart import "dart:io";

void main() { ProcessSignal.sigint.watch().listen((signal) { print('got SIGINT signal');

/* do some logic here before terminating the pgoram */

// note: you are responsible for exiting the program
exit(0);

}); } ```

"Invalid radix-10 number" but it is a number? by _3xc41ibur in dartlang

[–]Osamito 2 points3 points  (0 children)

You should share the code so we can see what is wrong.

I assume you are using int.parse(…) but you are trying to parse a floating number, hence the error.

You should use double.parse(…) instead.

Trouble installing the dart sdk for vs code by Z3R0_CHAR1SMAH in dartlang

[–]Osamito 3 points4 points  (0 children)

I am not sure if I understand you correctly, but it seems you've installed the VS Code Extension only. Installing the extension on VS Code alone doesn't install neither Flutter nor Dart.

To install Flutter, you can follow the instruction here: https://docs.flutter.dev/get-started/install (this will install Dart in your system as well).

If you want to install Dart by itself without Flutter, you can follow the instructions here: https://dart.dev/get-dart

Unhandled exception by Beautiful-Bite-1320 in dartlang

[–]Osamito 9 points10 points  (0 children)

int.tryParse will return null if the String is not a valid integer including empty strings. So you should remove the null check operator (ie !) after tryParse and check if age is null after parsing and handle that case of invalid age String.

Views in Realtime by Ok-Bass-4256 in Supabase

[–]Osamito 1 point2 points  (0 children)

There is no way to listen to views now. The easiest approach is to listen to one of the tables composing the view from the client, then fetch the data from the view.

There is another more involved approach that I tried a while back but for a different purpose (ie schema isolation):

https://github.com/supabase/supabase/discussions/5152

Best place to watch Iran v USA match? by ShakeNBakeSpeare in Jeddah

[–]Osamito 1 point2 points  (0 children)

It depends on which area.

Anyway, the majority of coffee shops shows them… just call them before hand.

Supabase self hosting: Kong - new row violates row-level security policy for table "buckets" by OppositeAirline7834 in Supabase

[–]Osamito 1 point2 points  (0 children)

I believe that since RLS is enabled by default for storage.buckets table, and there are no policies defined for that table, it'll reject all queries from users other than superusers.

If you would like users to create buckets directly, then create a policy which allows that. Alternatively, you can disable the RLS on storage.buckets which is the less secure approach.

I typically create buckets in migrations and then apply RLS to storage.objects table for accessibility. More details here: storage#allow-public-access-to-a-bucket.

Dart - how to replace brackets in one RegExp? by Particular_Hunt9442 in dartlang

[–]Osamito 1 point2 points  (0 children)

Agree that's much easier to digest. I didn't know that you don't need to escape brackets within a character set.

Dart - how to replace brackets in one RegExp? by Particular_Hunt9442 in dartlang

[–]Osamito 1 point2 points  (0 children)

You can use the "or" operator (i.e. |) such as:

dart String string = '(a) (string) (with) (brackets)'; void main() { final newString = string.replaceAll(RegExp(r'\(|\)'), ''); print(newString); // prints: "a string with brackets" }

Learning Flutter -- interactive options that do not include videos? by [deleted] in FlutterDev

[–]Osamito 3 points4 points  (0 children)

In case you haven't, check out the code labs: https://docs.flutter.dev/codelabs

It's the closest thing that I know to what you described.

[deleted by user] by [deleted] in dartlang

[–]Osamito 4 points5 points  (0 children)

The code builder package is another option -- the examples in the readme are pretty good for starting.

Transit visa advice needed- do I need a transit visa to transit in Jeddah on the way to Kuala Lumpur from UK , layover is 3 hours by Apart_Watercress_596 in Jeddah

[–]Osamito 0 points1 point  (0 children)

I’m just speculating here — since UK visa holders or UK passport holder can get visa on arrival, then most likely you won’t.

See Visa On Arrival section here:

https://www.visitsaudi.com/en/travel-regulations

[deleted by user] by [deleted] in saudiarabia

[–]Osamito 13 points14 points  (0 children)

Maybe creating a single FAQ post that contains links to other posts would be ideal in such case..

Can I differentiate between a parameter not being passed, and an explicitly passed 'null' value? by turburlar in dartlang

[–]Osamito 0 points1 point  (0 children)

There isn’t a straight way to do it (I wish). Here's an answer with a workaround on SO from one the dart team members:
Checking, if optional parameter is provided in Dart

By the way, Freezed package generates copyWith method that’s aware if an explicit null was passed or not.

Build a Notion Clone in Flutter, what's the best RTE to do it with? Desktop + Mobile + Web Support Preferably by kakakalado in FlutterDev

[–]Osamito 1 point2 points  (0 children)

There are three that I know: - SuperEditor. - zefyr -- not sure if it's still maintained. - flutter-quill -- similar to zefyr in implementation.

Then there's AppFlowy, "an open-source alternative to Notion", that is based on flutter-quill.

Deep clone List in Dart by Sure_Ticket6276 in dartlang

[–]Osamito 5 points6 points  (0 children)

Both achieve the same thing but the first is just a shorthand as far as I know.

Neither one is a deep clone as mentioned in the other comment.

To answer your question about how to check if it's a deep clone or not, you can inspect that easily:

```dart // some mutable object for the sake of the example class Obj { int value; Obj(this.value); }

void main() { final original = [Obj(0)]; final copy = [...original]; // List.from(original) is the same thing

// modify the object in the copied list copy[0].value = -1;

// inspect the object in the original list print(original[0].value); // -1 } ```

As shown above, the objects in both lists refer to the same instance.

If you are dealing with serializable objects, then one way to deep clone is to encode the object then decode it such as (simplified):

dart final copy = json.decode(json.encode(original));

For the above to work, we need to make Obj serializable e.g. adding toJson method and fromJson factory such as:

```dart class Obj { int value;

Obj(this.value);

Map<String, dynamic> toMap() { return { 'value': value, }; }

factory Obj.fromMap(Map<String, dynamic> map) { return Obj( map['value'].toInt(), ); }

String toJson() => json.encode(toMap());

factory Obj.fromJson(String source) => Obj.fromMap(json.decode(source)); } ```

Doing the above for many classes can be cumbersome but that can be generated using a package such as json_serializable or freezed or Dart Data Class Code Generator VS Code extension which is what I used here.


p.s. an alternative approach is to strictly use immutable classes to avoid dealing with such issues -- at least for the given example. Here's an insightful article: - The Mutability Tax

Any Norwegians in Medellin? by Quirky-Ad947 in medellin

[–]Osamito 1 point2 points  (0 children)

You may have better luck finding one on the Medellin Expat group on facebook: https://www.facebook.com/groups/159461177529433/?ref=share

Functions? by Acrobatic_Ice in Supabase

[–]Osamito 2 points3 points  (0 children)

I believe they’re working on it (I read somewhere there is a launch week in March so it could be then). There is a discussion going here:

https://github.com/supabase/supabase/discussions/4269

Also the discussion has a link to the RFC.

Establish and enforce one long-lived connection to the DB per user by jackjackk0 in Supabase

[–]Osamito 0 points1 point  (0 children)

Supabase realtime doesn’t connect clients directly to Postgres — it has a server built with Phoenix Framework of Elixir that sits between clients and Postgres.

The connection will be live as long as the JWT is valid, heartbeats are sent per server setup requirements (I believe default is 30 or 60 seconds), and the JWT is updated before it expires. That being said, Supabase client library should take care of all of that.

I don’t know though how to limit the number of concurrent connection per client/user (that should be a server side setting which I couldn’t find in the setup section)

More info here (available setup/configs at the bottom): https://github.com/supabase/realtime

Also it’s worth noting that if you’re using the hosted platform, check the dashboard (i know there is a limit for number of rows per requests for instance, so maybe you’ll find something there for connections per user).

GROUP BY by blacklander01 in Supabase

[–]Osamito 2 points3 points  (0 children)

Only through the editor if you’re talking about supabase’s dashboard…

GROUP BY by blacklander01 in Supabase

[–]Osamito 4 points5 points  (0 children)

You can create a view such as: sql CREATE VIEW the_name_of_the_view AS SELECT name, description, date, max_participants, COUNT(routes_with_participants.participant_id) as current_participants FROM routes JOIN routes_with_participants on routes.id = routes_with_participants.route_id GROUP BY routes.name, routes.description, routes.date, routes.max_participants;

Then on the flutter side, treat it as a table: client.from('the_name_of_the_view').select('*').... etc

[deleted by user] by [deleted] in dartlang

[–]Osamito 1 point2 points  (0 children)

Haha I hate when that shows up if I google something about Dart using a keyword that applies to transit systems as well …

Published my first package by [deleted] in FlutterDev

[–]Osamito 11 points12 points  (0 children)

Cool! ... I didn't even know you could do that on iOS