A little dart library for wrapping big "if - if else" blocks in a Switch..Case structure. This is mainly for learning purposes of me. I know, it's somehow stupid, but maybe someone has a use-case for this. At least with some additions :)


I think this has a really obvious usage. Create a new Switch object and set Case callbacks with the dart 'do-with-object' operator (..). The Case method gets a condition as lambda returning a boolean or a boolean as first parameter and a callback to execute as the second. If you want to run anything in case no Case block is executed, assign a Default callback. You can only assign one Default callback.


var i = 5;

  Condition cond = () => i < 15;
  Function doe = () => print("i smaller than 15");

  new Switch()
    ..Case(cond, doe)
    ..Case(() => i < 10, () => print("i smaller than 10"))
    ..Case(i > 15, () => print("This callback won't run"))
        () => print("This callback will run when no case block was executed"));


i kleiner 15
i kleiner 10



The dart_switch library