import 'package:lib1/lib1.dart';
import 'package:lib2/lib2.dart' as lib2;
// Uses Element from lib1.
Element element1 = Element();
// Uses Element from lib2.
lib2.Element element2 = lib2.Element();// Import only foo.
import 'package:lib1/lib1.dart' show foo;
// Import all names EXCEPT foo.
import 'package:lib2/lib2.dart' hide foo;Source code from: https://dart.dev/guides/language/language-tour#libraries-and-visibility
Use the const keyword when you want to create a compile-time constant.
Note that this value will be immutable.
const color = 'Lava Orange';
color = 'Mexico Blue'; // Error: cannot reassign a const
const colors = ['Lava Orange'];
colors.add('Lava Orange'); // Error: unsupported operationDart
const colors = ['840420', '2898b2', '606476'];
const hexCodes = ['#000000', for (var c in colors) '#$c', '#ffffff'];
hexCodes; // ['#000000', '#840420', '#2898b2', '#606476', `#ffffff`]vs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const xs = [1, 2, 3]; | |
| const xsWithZero = [0, ...xs]; | |
| print(xsWithZero); // [0, 1, 2, 3] | |
| const xsWithZeroBack = [...xs, 0] | |
| print(xsWithZeroBack)' // [1, 2, 3, 0] |
Future<void> somethingThatCanFail() async {
try {
// try some stuff likely to fail
} on SocketException catch (_) {
print('Something happend to the internet')
} on IOException catch (_) {
print('Something happened to your disk');
} catch (e) {
print('An unexpected error occured: $e');
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const zeroTo60 = <String, double>{ | |
| 'Porsche 991.2 Carerra T': 3.5, | |
| 'Porsche 991.2 Carerra GTS': 3.4, | |
| 'Porsche 991.2 GT3': 3.0, | |
| 'Porsche 991.2 GT3': 3.6, | |
| 'Porsche 992 Turbo S': 2.2, | |
| 'Porsche 992 GT3': 2.7 | |
| } | |
| const s = Set.from(zeroTo60.keys) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Color { | |
| static const red = '#f00'; | |
| static const green = '#0f0'; | |
| static const blue = '#00f'; | |
| static const black = '#000'; | |
| static const white = '#fff'; | |
| } |