Plurals: Different languages have different rules for grammatical agreement with quantity. In English, for example, the quantity 1 is a special case. We write "1 book", but for any other quantity we'd write "n books". This distinction between singular and plural is very common, but other languages make finer distinctions.
You can use Plurals in your Dart string by using Intl
package. The full set supported by Intl
package is zero, one, two, few, many, and other.
- Add dependency:
dependencies:
intl: version
- How to use:
import 'package:intl/intl.dart';
...
notificationCount(int howMany) => Intl.plural(
howMany,
zero: 'You don\'t have any notification.',
one: 'You have $howMany notification.',
other: 'You have $howMany notifications.',
name: "notification",
args: [howMany],
examples: const {'howMany': 42},
desc: "How many notifications are there.",
);
print(notificationCount(0));
print(notificationCount(1));
print(notificationCount(2));
- Output:
You don't have any notification.
You have 1 notification.
There are 2 notifications.
Use an Ink widget! The Ink widget draws on the same widget that InkWell does, so the splash appears. #FlutterFriday tweet by Flutter.dev.
Learn more here.
You can use the print()
function to view it in the system console.
If your output is too much, then Android sometimes discards some log lines.
To avoid this, you can use debugPrint()
.
You can also log your print calls to disk if your doing long-term or background work.
Check out this Gist by Simon Lightfoot
Cascades Notation (..)
allows to chain a sequence of operations on same object. In addition, fields (data-memebers) can be accessed using the same.
Just wrap the widget with the Theme
Widget and pass the ThemeData()
.
This article contains the Tips from February month that shared over here.
Use below.
Instead of this.
What about using Timer.periodic
It will create a repeating timer, It will take a two argument one is duration
and second is callback
that must take a one Timer parameter.
You can cancle the timer using the timer.cancel()
.
Check out below article for detail information about this tip.
Apply style as a Theme in a Text
widget
This article contains the Tips from January month that shared over here.
Adding = null
is redundant and unneeded.
Want to add the separator in your Flutter ListView?
Go for the
ListView.separated();
Best part about seprated is it can be any widget.😃
Check out the below image for the sample code.
While checking the null in the Dart, Use null-aware operators
help you reduce the amount of code required to work with references that are potentially null.