Search
 
SCRIPT & CODE EXAMPLE
 

DART

enum flutter

enum Status { 
   none, 
   running, 
   stopped, 
   paused 
}

void main() { 
   print(Status.values); 
   Status.values.forEach((v) => print('value: $v, index: ${v.index}'));
   print('running: ${Status.running}, ${Status.running.index}'); 
   print('running index: ${Status.values[1]}'); 
}
Comment

enum flutter 3

/// Adding members
/// With enhanced enums, you can add any member to your enum as long as the constructor is const.

/// This also means that you can add getters or methods to existing enums, for example:

enum Cake {
  cherry,
  apple,
  strawberry;

  String get description => '$name cake';
}
/// Generics
/// Enhanced enum classes also enable you to use generics for you enums. If you combine this with members, you can do the following:

enum Bar<T extends Object> {
  number<int>(42),
  name<String>('creativecreatorormaybenot'),
  baz(true); // Note that type inference also works.

  const Bar(this.value);
  final T value;
}
/// Mixins and interfaces
/// In addition to declaring members, you can also mixin mixins and implement interfaces with enhanced enums and override any missing implementations.

mixin Foo {
  int get n;
}

abstract class Bar {
  void printNumber();
}

enum Baz with Foo implements Bar {
  one(1),
  two(2);
  
  const Baz(this.n);

  @override
  final int n;

  @override
  void printNumber() => print(n);
}
/// Multiple arguments
/// Finally note that even if I did not make use of it in any of the examples above, it is possible to have an arbitrary number of arguments (and an initializer list):

enum Foo {
  bar(42, description: 'The answer to life, the universe, and everything.'),
  baz(0, enabled: false, description: 'noop');

  const Foo(
    int number, {
    this.enabled = true,
    required this.description,
  }) : n = number;
  final int n;
  final bool enabled;
  final String description;
}
Comment

PREVIOUS NEXT
Code Example
Dart :: how to make my app scrollable in flutter 
Dart :: listview space between items flutter 
Dart :: flutter table row height 
Dart :: flutter appbar default padding 
Dart :: get initials from name flutter on text 
Dart :: round container boundary in flutter 
Dart :: textfield align top text 
Dart :: flutter get available width 
Dart :: get length of map flutter 
Dart :: dart object to map 
Dart :: flutter column 
Dart :: flutter compute 
Dart :: Named parameters dart 
Dart :: array 2d dart 
Dart :: convert double to string flutter 
Dart :: dart epoch to datetime 
Dart :: flutter otp input scrren 
Dart :: runapp in flutter 
Dart :: camera focus permission in android 
Dart :: flutter crop captured image 
Dart :: dart fold 
Dart :: flutter set default language 
Dart :: flutter text padding 
Dart :: how to define format snippet of class name as file name in dart : flutter 
Dart :: flutter sliver persistent header example 
Dart :: how to center widgets in using scrollview flutter 
Dart :: showing ads every x seconds flutter 
Dart :: dart add list to list 
Swift :: swift ttext align center 
Swift :: add border to button swiftui 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =