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

    Written 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?

    Written 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

    Written by

    in

    In Flutter, you can create a color from a hexadecimal color string value using the Color class. The Color class takes a 32-bit integer value as an argument, where the first 8 bits represent the alpha channel (transparency) and the remaining 24 bits represent 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

    Written 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 You can use the sort method of List…

    Read more

  • Dart: code snippets for faster coding

    Dart: code snippets for faster coding

    Written 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

    Written 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

    Written by

    in

    The full documentation for this is available on flutter.dev When creating json_serializable classes the first time, you’ll get errors similar to what is shown in the image below. These errors are entirely normal and are simply because the generated code for the model class does not exist yet. To resolve this, run the code generator that generates…

    Read more