Tag: Dart

Dart is an open-source, scalable programming language developed by Google. It is used for building web and mobile apps as well as server and desktop applications. Dart is an object-oriented and class-based programming language.

  • Dart: Zufallszahl in einem Bereich erstellen

    Dart: Zufallszahl in einem Bereich erstellen

    By

    in

    Analog zum Artikel über Java Zufallszahlen bietet auch Dart Möglichkeiten, um eine Zufallszahl zu erstellen. Hierzu kann beispielsweise die Klasse Random aus dem Paket dart:math verwendet werden. In der Dokumentation heißt es: Generiert eine nicht-negative Zufallszahl gleichmäßig verteilt im Bereich von 0 (einschließlich) bis max (ausschließlich). https://api.dart.dev/stable/3.3.3/dart-math/Random/nextInt.html In nachfolgendem Beispiel wird eine Zufallszahl zwischen einem Minimum und…

    Read more

  • Dart: What is the difference between the “const” and “final” keywords?

    Dart: What is the difference between the “const” and “final” keywords?

    By

    in

    In Dart, both const and final are used to declare variables that can’t be reassigned after they’re initialized. However, there are some differences between them: In general, use const when you have a value that will never change and you want to ensure that only one instance of it exists, and use final when you…

    Read more

  • Flutter: How to Create a Color from a Hexadecimal Color String

    Flutter: How to Create a Color from a Hexadecimal Color String

    By

    in

    In Flutter, you can use included the Color class to create a color from a hexadecimal color string value. The Color class accepts a 32 bit integer value with the first 8 bits denoting the alpha channel (transparency) and the subsequent 24 bits representing the red, green and blue channels. To create a color object…

    Read more

  • Flutter: how to sort a list of objects by one of its properties

    Flutter: how to sort a list of objects by one of its properties

    By

    in

    In Flutter (Dart), there are different posibilities to sort a list of objects by one of its properties. Let’s asume you have a list of Person objects that have a property name on which you want to sort the array. Sort a list using the sort() method Darts List class already provides an abstract sort…

    Read more

  • Dart: code snippets for faster coding

    Dart: code snippets for faster coding

    By

    in

    There are different concepts that improve the data handling in Dart. The following list of snippets is a collection of the most handy once. Warning: this might simplify your code a lot! 😉 The Spread Operator Dart supports the spread operator, which allows to insert a collection (multiple elements) into a collection: Operators Dart supports different…

    Read more

  • Flutter on iOS: themeMode does not change to dark mode if `ThemeMode.system` is used

    Flutter on iOS: themeMode does not change to dark mode if `ThemeMode.system` is used

    By

    in

    In my case, a simple app should automatically use the theme (light or dark) of the system to style the user interface. By default, this should work when using ThemeMode.system (see flutter documentation). But it didn’t. The themes have been defined as follows: In addition, the WidgetsBindingObserver callback didChangePlatformBrightness() was never called. It was defined…

    Read more

  • Flutter: generating *.g.dart files for json serialization

    Flutter: generating *.g.dart files for json serialization

    By

    in

    When working on mobile apps, you might need to communicate with a web server or easily store structured data. In such cases, JSON is a good solution to handle the data. But this also requires the serialization of data – turning a data structure into a string – or the other way round, deserialization –…

    Read more