vandadnp / flutter-tips-and-tricks Goto Github PK
View Code? Open in Web Editor NEWA Collection of Flutter and Dart Tips and Tricks
Home Page: https://linktr.ee/vandadnp
A Collection of Flutter and Dart Tips and Tricks
Home Page: https://linktr.ee/vandadnp
About https://github.com/vandadnp/flutter-tips-and-tricks/tree/main#future-error-handling-in-dart
Maybe a note would be helpful, to use that with caution. The creation of the error-value could be expensive and with your approach, I would create that object all the time, even if I don't need it. That is the reason, as far as I know, to pass a creation function into it. Just my thought to avoid bad designs for newcomers to dart.
Thanks for all your tips, I like it a lot.
Hello Vandad, that's for creating such a useful project. I've been playing around with loading the tips and trick in the terminal for a while now using this method Flutter Tips and Tricks in Terminal but just now the link doesn't show all the images and dart code just the .md files. Is there a new method to get each tip with its image and source code now? I'm creating an open source app using this repo and would really like it to work out.
I also can't get the dart files now, https://raw.githubusercontent.com/vandadnp/flutter-tips-and-tricks/main/tipsandtricks/implementing-zip-and-tuples-in-dart/implementing-zip-and-tuples-in-dart.dart
This like gives me a 404 error. But I can access the .jpg freely.
Using classes as enum has become obsolete since Dart 2.17, this tip could be removed !
Having:
T? operator +(final T? other) {
final shadow = this;
if (shadow != null) {
return shadow + (other ?? 0) as T;
} else {
return null;
}
}
and the test:
test('Test null + operator', () {
int? var1;
var1++;
var1 += 1;
var1 = var1 + 1;
var1 = 2;
var1++;
var1 += 1;
var1 = var1 + 1;
expect(var1, 5);
}
The test runs successfully but with code coverage we can see that the line
return shadow + (other ?? 0) as T;
never gets called which leads me to the speculation that shadow always equals to NULL when the extension is called and the extension is not "attached" if T is not null.
Hi. The extension method to
could be made more optimized or idiomatic (since its return type is declared as Iterable
) by avoiding unnecessary array creation. The code won't be as pretty though ๐
flutter-tips-and-tricks/source/integer-range-extension-in-dart.dart
Lines 15 to 19 in 4c11641
vs
extension To on int {
Iterable<int> to(int other, [bool inclusive = true]) sync* {
if (other > this) {
for (int i = this; i < other; i++) yield i;
} else {
for (int i = this; i > other; i--) yield i;
}
if (inclusive) yield other;
}
}
Typo in "365 - Recoveringg Stream Errors in Flutter"
Likely you planned saying "Recovering" (single G)?
43 - Converting Lists to Maps in Dart
const list = ['this','is','a','long','text'];
final map = {for (final s in list) s:s.length}; /// <= this way!
void main() {
for (final e in map.entries) {
print('"${e.key}" length is ${e.value}');
}
}
is out of date because we now have enumValue.name since Dart 2.15 so I think this tip can be removed ๐
You use the reduce
method to get the sum of list items in dart. Calculating the Sum of List Items in Dart
Actually there is a built-in way for doing that:
import 'package:collection/collection.dart';
void main() {
final list = [1, 2, 3, 4];
final sum = list.sum;
print(sum); // prints 10
final average = list.average;
print(average); // prints 2.5
}
I declared:
extension OrDefault<T> on T {
T get orDefault {
final value = this;
if (value == null) {
return {
int: 0,
String: '',
double: 0.0,
num: 0,
bool: false,
Map: {},
List: [],
Set: {},
}[T] as T;
} else {
return value;
}
}
}
test('Test ObjectExtension.orDefault()', () async {
const int? nullInt = null;
expect(nullInt.orDefault, 0); // fails since T is int? and returns null instead of 0.
});
Great tips thanks, the only problem is I can't load this page entirely. I think it's too heavy to load on a single page causes browser to stuck.
In "Factory Constructors in Dart" there is no definition for "Rect".
Hey! Thanks for a very cool repo โ๏ธ
Would be nice if the release message contained the tip itself or at least a link to the new section. So if I see the release in the feed, I could just read it by entering the release page.
This tip is overly complicated, you can just do enumValue.index
: https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/enum-associated-values-in-dart/enum-associated-values-in-dart.md
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.