Switch Case in Dart Last Updated : 26 Mar, 2025 Suggest changes Share 17 Likes Like Report In Dart, switch-case statements are a great tool for managing multiple conditions in a clean and organized way. They serve as a more efficient alternative to lengthy if-else chains, making your code easier to read and maintain.Syntax:switch (expression) { case value1: // Body of value1 break; case value2: // Body of value2 break; // Add more cases as needed default: // Body of default case break; }The default case is the case whose body is executed if none of the above cases matches the condition.Rules to follow in switch case:There can be any number of cases. But values should not be repeated.The case statements can include only constants. It should not be a variable or an expression.There should be a flow control i.e. break within cases. If it is omitted then it will show an error.The default case is optional.The nested switch is also there thus you can have a switch inside the switch. Normal switch-case statementExample: Dart void main() { int gfg = 1; switch (gfg) { case 1: { print("GeeksforGeeks number 1"); } break; case 2: { print("GeeksforGeeks number 2"); } break; case 3: { print("GeeksforGeeks number 3"); } break; default: { print("This is default case"); } break; } } Output:GeeksforGeeks number 1Nested switch-case statementExample: Java void main() { int gfg1 = 1; String gfg2 = "Geek"; switch (gfg1) { case 1: { switch (gfg2) { case 'Geek': { print("Welcome to GeeksforGeeks"); } } } break; case 2: { print("GeeksforGeeks number 2"); } break; default: { print("This is default case"); } break; } } Output:Welcome to GeeksforGeeksConclusionSwitch-case statements in Dart offer a handy way to manage multiple constant conditions, making them a great alternative to lengthy if-else chains. One key difference is that switch statements focus solely on compile-time constants. While it's not always necessary to include a break statement, skipping it can lead to some unexpected behavior, as it allows the program to "fall through" to the next case. You can also add a default case to catch any conditions that don't match the others. Interestingly, Dart supports nested switch-case statements too, although they're not used as often. A aditya_taparia Follow 17 Article Tags : Dart Dart-basics Explore Dart Tutorial 7 min read BasicsIntroduction to Dart Programming Language 4 min read Dart SDK Installation 4 min read Dart - Comments 2 min read Dart - Variables 5 min read Operators in Dart 11 min read Dart - Standard Input Output 3 min read Data TypesDart - Data Types 8 min read Basics of Numbers in Dart 6 min read Strings in Dart 6 min read Dart - Sets 6 min read Dart Programming - Map 7 min read Queues in Dart 3 min read Data Enumeration in Dart 3 min read Control FlowSwitch Case in Dart 2 min read Dart - Loops 4 min read Dart - Loop Control Statements (Break and Continue) 4 min read Labels in Dart 2 min read Key FunctionsDart - Anonymous Functions 2 min read Dart - main() Function 2 min read Dart - Common Collection Methods 2 min read How to Exit a Dart Application Unconditionally? 2 min read Dart - Getters and Setters 3 min read Dart - Classes And Objects 4 min read Object-Oriented ProgrammingDart - this keyword 2 min read Dart - Static Keyword 3 min read Dart - Super and This keyword 4 min read Dart - Concept of Inheritance 5 min read Instance and class methods in Dart 3 min read Method Overriding in Dart 3 min read Getter and Setter Methods in Dart 2 min read Abstract Classes in Dart 4 min read Dart - Builder Class 4 min read Concept of Callable Classes in Dart 4 min read Interface in Dart 3 min read Dart - extends Vs with Vs implements 4 min read Dart - Date and Time 3 min read Using await async in Dart 4 min read Dart UtilitiesHow to Combine Lists in Dart? 3 min read Dart - Finding Minimum and Maximum Value in a List 5 min read Dart - Splitting of String 1 min read Dart ProgramsDart - Sort a List 2 min read Dart - String toUpperCase() Function with Examples 1 min read Dart - Convert All Characters of a String in Lowercase 1 min read How to Replace a Substring of a String in Dart? 2 min read How to Check String is Empty or Not in Dart (Null Safety)? 1 min read Exception Handling in Dart 3 min read Assert Statements in Dart 3 min read Fallthrough Condition in Dart 3 min read Concept of Isolates in Dart 2 min read Advance ConceptsDart - Collections 7 min read Dart - Basics of Packages 2 min read Dart - String codeUnits Property 1 min read HTML Document Object Model and Dart Programming 3 min read My Profile ${profileImgHtml} My Profile Edit Profile My Courses Join Community Transactions Logout Like