Community to check out googles new web language

Subscribe to Community to check out googles new web language feed
This subreddit is a place for all things related to the Dart programming language and its tools.Dart Programming Language
Updated: 11 min 5 sec ago

Dart for Flutter : Mixin in Dart

6 hours 14 min ago

In object-oriented programming languages, a Mixin is a class that contains methods for use by other classes without having to be the parent class of those other classes.

In other words mixins are normal classes from which we can borrow methods(or variables) without extending the class. And in dart we do this using the keyword with. Like if you want to use class B as a mixin for class A then ,

Visit here for full article :

submitted by /u/shubhamhackz
[link] [comments]

Is there anything like MobX in JS land for Dart and Flutter?

Thu, 12/13/2018 - 17:54

Been searching for a while and can't find one. I love the simplicity of managing states with MobX when building a React/React native app, so something like MobX for Dart and Flutter would be great!

submitted by /u/jexplorer_exe
[link] [comments]

Any help on how to use source_gen for library generation?

Thu, 12/13/2018 - 14:09

Are there any good articles on how to setup packages based on source_gen? Particularly about the setup of the build.yaml files.

By following the documentation of build_config and source_gen I was able to get it working for part files generation but now I'm stuck as I'm unable to do library generation.

submitted by /u/Phy96
[link] [comments]

How to make code execute in order?

Thu, 12/13/2018 - 12:51

Hi Everyone!

I am build Flutter app in dart and want know how to make code execute in order.

Because I have conditional and inside this I have async function which must be execute first before moving to conditional nested in this conditional. I need this async function execute before nested conditional because the conditional need value of variable passed from function.

Here my example:

if (snapshot.hasData) {



if(id==uid) {

The function is async because it call other functions which return future. It look like:

_performThisAsyncFunctionBeforeMoveToNestedConditional() async {

await otherAsyncFunction();

await differentAsyncFunction();


Future<Null> otherAsyncFunction() async {


Thanks for help!

submitted by /u/Flutter_Dev
[link] [comments]

Browser-based unit tests still not debuggable?

Mon, 12/10/2018 - 08:49

I don't know if I miss something or if it is still not available?

submitted by /u/MikeMitterer
[link] [comments]

List.contains....but inside is a list of lists

Sun, 12/09/2018 - 18:22
print(toIndex(pawn)); // [3,3] (runtimeType verified as List<int,int>) print(moves); // [[2,2],[3,3],[4,4],[5,5],[6,6],[7,7],[8,8]] // (runtimeType verified as List<List<int,int>> ) print(moves.contains(toIndex(pawn))); // false.....but why?

moves clearly contains an element [3,3] but is returning false

Why is it false if [3,3] is in the List? Is it a by reference vs by value thing?

How would I go about verifying if this sublist is indeed in the larger list?

thank you!

PS.- I am using dart 1.24.2 and cannot add packages other than core ( exercises )

submitted by /u/NFC_TagsForDroid
[link] [comments]

List.contains....but inside is a list of lists

Sun, 12/09/2018 - 09:11
print(toIndex(pawn)); // [3, 3] print(moves); // [[2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8]] print(moves.contains(toIndex(pawn))); // false

Moves clearly contains an element [3,3] but is returning false

I am guessing this has to do with the list [3,3] being a different list (the "by reference" vs "by value") thing.

If I am correct, then, is there an efficient way to code this so I dont have to loop inside a loop and compare each element?

If I am wrong, then, what is going on? why is it false?

thank you!

submitted by /u/NFC_TagsForDroid
[link] [comments]

When to use await vs .then( )

Sat, 12/08/2018 - 13:44

So reading thru the dart docs on Asynchronous and it says:

When Future returning functions need to run in order, use chained then() calls:


.then((aValue) => expensiveB())

.then((bValue) => expensiveC())

.then((cValue) => doSomethingWith(cValue));

But can't you do that same using async/await so that the code listing is more procedural and readable i.e.

var aValue = await expensiveA();

var bValue = await expensiveB(aValue);

var cValue = await expensiveC(bValue);


So when do I use .then() and when do I use async/await? It seems like I should use .then() when the function is not marked as async. Is that the deciding factor i.e. use await when the function is marked async otherwise use .then()?

Also on the same dart docs page in the Futures section it states:

You might still see the Future API used in older code and in code that needs more functionality than async-await offers.

Can someone expound on the last part of the statement..."and in code that needs more functionality than async-await offers"...the author is clearly stating that there are some scenarios where it is preferable to use .then() but never states what those scenarios are. If anyone could explain what those scenarios are I would appreciate it. Thanks!

submitted by /u/zintjr
[link] [comments]

Listening on a stream

Fri, 12/07/2018 - 14:36

Hello! I'm new to Dart, so I'm trying to figure out the difference between stream.listen() and await for .

I tried this small example where I'm listening from the stream and adding it to a global var but I get the sum as 0.

I'm able to print the each individual item but can't seem to add it to the sum variable.

import 'dart:async'; import 'dart:core'; void main() async { Stream<int> stream = new Stream<int>.fromIterable([1,2,3,4]); var sum = 0; stream.listen((item){ sum += item; }); print(sum); }

Is there anything I'm missing here? Thank you.

submitted by /u/iammunukutla
[link] [comments]