#4 Flutter + Dart Tips

Bhavik Makwana
Flutter Community
Published in
2 min readJul 23, 2019

Here is the #4 article in this Flutter + Dart Tips series. If you have missed previous articles then you can check them out here.

11. Using Plurals in your Dart String.

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.

12. Implement assert() messages in Dart.

Do you know that you can throw your own message when your assert fails? assert() takes an optional message in which you can pass your message.

assert(title != null, "Title string cannot be null.");

The example shown here are may not be perfect but it is to showcase how you can utilize this in your Flutter development.

That’s all for #4 edition of this series. If you have any Tips to share with #Flutterverse then assemble and Start sharing it.

Make a PR in below repository with your Tip.

You can also write the article for this series by your own if I missed it and publish it at flutter-community.

If you found this article helpful click and hold 👏 button and show some love to this article and help others to find this article.

Feeling more generous, You can buy me a cup of tea.

Have a great and Fluttericious day.

--

--

Bhavik Makwana
Flutter Community

Flutter Enthusiast | Google Certified Associate Android Developer | Speaker for flutter | Android Dev | Flutter Dev