News for hackers. Stuff that matters.
Re:Flutter 2 by offtop5 on Wednesday March 03, 2021 @02:56PM (#26333534)
Pretty sure I'm the only person on this thread who loves flutter. We use flutter web and Firebase for our hobbyist project, and the results have been simply amazing.

Dart makes Typescript look like a joke. The build system alone makes flutter better than React Native !

I'm confident in being able to build any CRUD app in dart

Edit, in fact how many of you have actually built a project in flutter .I can't believe anyone would want to go back to react native after trying it

Re:Flutter 2 by plorkyeran on Wednesday March 03, 2021 @03:26PM (#26333924)
All of the complaints about flutter I see here are based on people using apps built with flutter, and not about the development experience. "Have you actually build a project in flutter?" is a total non-sequitor response to complaints about how even the official demo is miserable to use.
Re:Flutter 2 by offtop5 on Wednesday March 03, 2021 @05:13PM (#26335457)
Would you not buy a screwdriver because some people with that screwdriver don't build chairs correctly ?

Like with Unity, the power of cross-platform development leads many to just assume apps work across platforms automatically. This is absolutely not the case, you need to properly QA any code you write and code it to accommodate each platform's quirks.

Re:Flutter 2 by danShumway on Wednesday March 03, 2021 @05:49PM (#26335934)
But these are the official demos.

I would not buy a screwdriver if a salesperson walked up to me, said "look how great this screwdriver is" and then the chair they were holding as an example immediately fell apart in their hands. There's a difference between a dev community building apps that perform badly and the actual platform advocates showing off apps that can't perform.

Re:Flutter 2 by gagege on Wednesday March 03, 2021 @06:16PM (#26336228)
Exactly! I always think of the official demos as "this is as good as it gets". Look at how Unreal Engine advertises. Beautiful! Will your game look like that? Probably not, but it potentially could!

All the Flutter demos I've seen today are saying "Do you want your app to, at best, take a long time or even fail to load, feel like scrolling through molasses, break when you click a button, and spin text around at 25 fps like a 2005 Flash animation? Well, have we got a framework for you!"

Re:Flutter 2 by the_duke on Wednesday March 03, 2021 @03:34PM (#26334032)
Can you share any example of Flutter Web that isn't a extremely basic Todo app, doesn't completely break regular browser UX and works without being slow as molasses?

I haven't seen one.

I like Flutter, but I don't think the Flutter Web design is very viable for production apps. It renders everything in canvas. Dart is already sluggish on native, and cross compiled to JS it's usually unusable.

I think Flutter will be a good choice for mobile and Desktop soon-ish, but for web ... maybe in a few years. Maybe.

Re:Flutter 2 by gman83 on Wednesday March 03, 2021 @03:46PM (#26334231)
https://rive.app/ is built with Flutter. I use it a lot works very well for me. It's a good example imo of the kind of website that Flutter is a good fit for.
Re:Flutter 2 by tomComb on Wednesday March 03, 2021 @04:12PM (#26334620)
I assume their medium term plan is to make the new wasm backend the default rather than continuing to rely on transpiling.
Re:Flutter 2 by the_duke on Wednesday March 03, 2021 @04:21PM (#26334749)
The gallery already downloads a wasm file for me. Not sure if it's used.

ps: for me the Gallery is extremely laggy in Firefox, but works decently well on Chrome. Maybe wasm is enabled on Chrome only.

Re:Flutter 2 by stephenhuey on Wednesday March 03, 2021 @03:29PM (#26333971)
You're not the only person. After using two decades of improvements to JavaScript, Dart comes out swinging and wins without a contest. I don't want to spend all my time playing with build systems and and Flutter just works, plus even though JS is better these days, Dart in IntelliJ (Android Studio version) is so straightforward you can be productive from day one without having ever written Dart before.
Re:Flutter 2 by LocalPCGuy on Wednesday March 03, 2021 @03:30PM (#26333975)
We built our mobile app in Flutter, and it was pretty amazing. I would absolutely never suggest we create a web version of that mobile app and would strongly fight against it if someone else suggested it.

I strongly disagree re: Dart vs. TS, but then, I was a JS dev before I worked with Dart/Flutter, so probably a bit biased. But I think that is a very subjective statement, not objective.

Re:Flutter 2 by wootie512 on Wednesday March 03, 2021 @04:07PM (#26334565)
Yea I have used Flutter for hybrid apps and love the dev experience. The apps have come out great, and are smoother than my native Android work.

I am really hopeful for it and am going to keep using on it for hybrid apps.

I try to just tell devs to try it, then judge it. Because it does seem weird up front, but it is such a nice experience for devs and can make great mobile apps.

Re:Flutter 2 by aliyfarah on Wednesday March 03, 2021 @03:37PM (#26334079)
>Dart makes Typescript look like a joke.

Dart still does not even have union types, probably the best feature of TS. I would hold off on that claim for now..

Re:Flutter 2 by okamiueru on Wednesday March 03, 2021 @03:54PM (#26334364)
What is your main use case for type unions? I don't know typescript, but I haven't felt the dart language was not feature complete for all my uses. Is this something you cannot solve with a combination of abstract classes, and or/extension? https://dart.dev/guides/language/extension-methods
Re:Flutter 2 by kroltan on Wednesday March 03, 2021 @04:31PM (#26334881)
Not who you asked (and I just now realized I'm replying to you twice regarding this OP, I solemnly swear it's not some crude attempt at stalking).

But for me the main use for TS union types is to make discriminated unions, which is very useful wherever you have some form of a state-machine:

    type AppState =
      | { state: "loading", progress: number }
      | { state: "selecting_level", }
      | { state: "playing", level: Level }
      | { state: "success" }
      | { state: "failure", wantsRetry: boolean }
      | { state: "error", reason: string }
(Small excerpt from a game we're developing at $dayjob)

You can switch on that and the compiler will know what variant you're talking about, and it will apply exhaustiveness checks (ensures your code will handle all possible states)

Re:Flutter 2 by okamiueru on Wednesday March 03, 2021 @04:41PM (#26335034)
Haha. That's alright. That looks super neat though, I must admit. The only equivalent that comes to mind would be using an abstract class. I still might fail to fully understand what that code example does, but, would this be somewhat similar?

    abstract class AppState {}
    class AppLoading extends AppState {
      final int progress;
    }
    class AppSelectingLevel extends AppState {}
    class AppPlaying extends AppState {
      final Level level;
    }
    ...
Certainly not as neat, but also, not that far off either. Then where you use this app state, you could switch over its `runtimeType`, and in each clause, the IDE will understand which implementation you are dealing with, and actually give you context sensitive help related to that particular state.

If you instead only cared about one case, you would be able to do:

    if (appState is AppPlaying) {
        doSomething(appState.level);
    }
Would this be somewhat analogous to the functionality you get with unions in typescript?
Re:Flutter 2 by vsmenon on Wednesday March 03, 2021 @05:11PM (#26335431)
[Disclaimer: I work on the Dart team.]

The TS code indeed looks cool. This is an area we're looking at.

One point, though: we try to be very careful to not regress performance or developer iteration time (e.g., type checking time) when we introduce new language features. E.g., structural typing can be more expensive in general to type check since we need to recurse.

Re:Flutter 2 by kroltan on Wednesday March 03, 2021 @05:55PM (#26336000)
Fair enough, that is a meritable goal.

Have you considered not going full-on structural-typing but still providing some sort of union? In fact, you could go for one with even stronger guarantees, like the sum types in Rust or F#. (with Rust going as far as to call them enums too)

I'll admit I have the faintest notion on what causes that kind of complexity on a compiler, so my suggestion might be an even worse idea.

Re:Flutter 2 by munificent on Wednesday March 03, 2021 @09:42PM (#26337974)
> Have you considered not going full-on structural-typing but still providing some sort of union?

I work on Dart. The terminology gets really confusing here. "Discriminated unions" and "union types" are two quite different things, though they get a little blurry in TS.

The short answer is, yes, we're investigating pattern matching with exhaustiveness checking and making the language more graceful at expressing algebraic datatype-style code. The last half of that sentence sounds weasely because any object-oriented language can (except for exhaustiveness checking) model an algebraic datatype using subtyping. The parent comment using an abstract base class is how you do it.

So there isn't anything really fundamental that Dart can't express already. It's mostly a question of giving users syntactic sugar to make code in that style look more terse and familiar. I personally really like pattern matching and ADTs and I also particularly like multi-paradigm languages, so this is a subject close to my heart.

The language team has been pretty busy with null safety, but now that that's out the door (woo!), we can start working on the next batch of features, which with luck includes pattern matching. Here's an in-progress proposal:

https://github.com/dart-lang/language/blob/master/working/05...

Re:Flutter 2 by hajile on Thursday March 04, 2021 @11:29AM (#26344457)
Any idea when dart will get tuples (and maybe immutable structs)?
Re:Flutter 2 by munificent on Thursday March 04, 2021 @01:25PM (#26346124)
No time frame, sorry. We generally don't make promises about future dates because schedules tend to be flexible and picking dates just sets people up for disappointment.
Re:Flutter 2 by kroltan on Wednesday March 03, 2021 @04:56PM (#26335235)
Indeed, that is basically what you get from unions, except the exhaustiveness check.

Unless I'm mistaken, if one were to later implement a new class that extends AppState, all existing code would compile, but possibly fail or misbehave at runtime, unless you meticulously checked every place that tries to determine something based on those derived types.

In TypeScript, adding a new case for an union and not handling it everywhere is a compilation error on every incomplete usage site.

For example, try deleting one of the arms of the switch in this playground: https://www.typescriptlang.org/play?ts=4.2.2#code/C4TwDgpgBA...

I have to say, the default diagnostic isn't brilliant, but some tooling will give a better error and actually point out the missing arms, instead of complaining about the return type.

Re:Flutter 2 by okamiueru on Wednesday March 03, 2021 @05:20PM (#26335570)
I suppose. In practice, I haven't experienced this to be a problem. Since you already check which implementation you are dealing with, any code that relied on any state, should still work without any issue. This is the same as with typescript unions. Any code that somehow needs to handle a new state hm... I suppose getting a compile time error is nice to immediately see all places where it is used... but, I mean, so would a "find all uses" search. It's also not all that different from the linting warning error you'd get from iterating over runtime types without handling all cases.

All in all, sufficiently analogous to not consider unions a missing feature of the dart language? Seems nice to have, but, maybe not very necessary. Especially if the only difference is whether it is considered an error by the syntax, or a warning by the linter.

Re:Flutter 2 by svieira on Wednesday March 03, 2021 @05:10PM (#26335411)
The proper analog to union types in Dart (as in Java) is enums and / or church-encoding [I think that's the term] generalized algebraic data types (GADTs). E. g. something like this: https://gist.github.com/jbgi/208a1733f15cdcf78eb5

Scala 2 also had `sealed` classes that could be used in places where you needed enums parameterized by runtime values and that's been generalized in Scala 3 IIRC.

Re:Flutter 2 by okamiueru on Wednesday March 03, 2021 @05:26PM (#26335653)
I'm certainly confused now whether or not we are talking about the same thing. Without delving to much on the use of the word "union", how would you solve the use case presented in the typescript examples using enums?
Re:Flutter 2 by okamiueru on Wednesday March 03, 2021 @09:57PM (#26338069)
Reading more about it, it could seem that we are talking about the same thing, except that it was so far over my head, that I didn't realise it.
Re:Flutter 2 by oblio on Wednesday March 03, 2021 @04:01PM (#26334479)
Let's say you get a JSON API that sometimes returns a list, sometimes returns an object. How do you model that in Dart?
Re:Flutter 2 by munificent on Wednesday March 03, 2021 @09:45PM (#26337991)
Yes, union types are really nice for data like that.

But, in practice, a language's type system tends to optimize for the data structures that are idiomatic in the language. TypeScript is a heavily structural type system because idiomatic JavaScript often throws together unrelated types in this way (which makes sense when you're coming from dynamic types).

In a language that is built more strongly on objects and static types, it's less common to see APIs that "return one of these, or one of these, or on Sunday one of these things". So there is relatively less use for union types.

In other words, because people express unions at runtime less frequently in Dart (and other languages like Java and C#), there's less value in supporting them statically. Still some, definitely, but I don't think it's as critical of an omission as you might expect coming from TS/JS.

Re:Flutter 2 by c-cube on Thursday March 04, 2021 @01:53AM (#26339441)
People build less unions because these languages fail them. Just add sum types or something similar, it's a disgrace to not have them in 2021. Static typing goes wonderfully well with them, allowing for exhaustiveness checks and all that.

The "people use fewer unions in Java" argument is like saying people used fewer lambdas in Java 1.6. Build it, and they will use it.

Re:Flutter 2 by munificent on Thursday March 04, 2021 @01:24PM (#26346113)
> Just add sum types or something similar

I think you're confusing union types and sum types, which are very distinct features. SML, Haskell, and Rust don't have union types.

OOP languages can model sum types already. It's mostly a question of how much the surface syntax encourages that style.

Re:Flutter 2 by c-cube on Thursday March 04, 2021 @01:39PM (#26346319)
I'm not confusing them :-)

I think _closed_ union types (the syntax `a | b | c`) are almost as good as sum types, since they bring exhaustiveness checking to the mix. They also act as documentation. Crystal is a good example of a language leveraging this feature.

The OO model of just subclassing a common class is quite poor by itself. Scala and Kotlin have a 'sealed' modifier to at least recover the exhaustiveness check. Both also have ways of safely doing the case switch on the object's class and simultaneously downcasting (Java too with its recent `match` construct, afaik). Does Dart have anything like that?

Re:Flutter 2 by munificent on Thursday March 04, 2021 @05:03PM (#26349059)
> The OO model of just subclassing a common class is quite poor by itself. Scala and Kotlin have a 'sealed' modifier to at least recover the exhaustiveness check.

The natural OOP way to model an operation that must exhaustively be supported by a set of types is by making it an abstract method on a shared superclass. For problems where it's natural to keep the operations textually near each type, that works great.

Otherwise, yes, you'd ideally have some notion of a sealed family of types so that you can do case analysis with exhaustiveness checking. That lets you ensure all operations are covered when you program either in OOP or FP style.

Something I find odd is that FP folks often criticize OOP languages for not supporting exhaustiveness checking, but I rarely hear them admit that most FP languages don't have support for the other style that OOP does well, which is abstract methods.

Re:Flutter 2 by c-cube on Thursday March 04, 2021 @05:12PM (#26349177)
As far as typed FP languages go:

- Scala has the whole OOP stuff - F# as well - SML: you probably need to do it by hand, with a record of closures, or something like that. It's ugly but it works. - OCaml has objects (it's in the name), first-class modules, or records-of-functions; all of which can replace abstract methods successfully. - Haskell can rely on typeclasses to do the virtual dispatch, I think. Not an expert on that.

So I'd say it might not be as ergonomic, but the capability is still 100% there.

Re:Flutter 2 by oblio on Thursday March 04, 2021 @02:35AM (#26339725)
What's the de facto web data interchange language these days? Used by every programming language out there, every language has a library to load it?
Re:Flutter 2 by okamiueru on Wednesday March 03, 2021 @04:14PM (#26334639)
You could create an abstract class for the base response, then implement this abstract class for the two cases one where it has a list member, and one where it contains the object. Then, using the return value with something like `if (response is listLike) { }` the IDE already knows that you are scoped to having only the list like properties, and you'd get the full help of the language. Something like that, I suppose.
Re:Flutter 2 by oblio on Wednesday March 03, 2021 @04:49PM (#26335144)
Versus a sort of:

my_type = my_list | my_object

?

You can see why this is better :-)

Re:Flutter 2 by mixmastamyk on Thursday March 04, 2021 @12:31AM (#26339007)
I'd always return a list. Makes the client code simpler.
Re:Flutter 2 by oblio on Thursday March 04, 2021 @01:16AM (#26339234)
You would. But not every input comes from you :-)
Re:Flutter 2 by okamiueru on Wednesday March 03, 2021 @05:22PM (#26335584)
All I can say is that it is certainly neat :)
Re:Flutter 2 by mdfk on Thursday March 04, 2021 @04:16AM (#26340317)
You are not the only one -- I've been developing in Flutter for the past couple of months and overall I'm very satisfied how easy it is to develop in it compared to native Android and iOS. Being native Android dev, I truly believe that there is a future in Flutter. Till now I was rejecting all the other cross-platform frameworks.

Big part of it is thanks to the community which is providing all the handy packages to add some native stuff easier (such as permission, localization etc.)

I agree with other comments that Flutter Web is not ready yet I've tried to build web version for wish list sharing based on Flutter and I was struggling, so in the end I've switched to Tailwind + Vue. Some issues I had was that website didn't behave like website. For example I couldn't select text with my mouse. It felt and behaved more like a mobile app through the browser.

For mobile though it works (almost) perfectly, my example of the mobile iOS and android app build with Flutter: https://wishpy.com/

Although it loads a bit long at the beginning and I still need to figure out how to show images and icons without an uncomfortable glitch at the screen start.