#flutter
Let's study #Dart.
final, const & late in 3+ steps.
🧵👇
1/1
What is the difference between final and const?
A constant variable must be initialized at the time of declaration. It's a compile-time constant. A final variable can be initialized later, but only once when the first time it’s used.
1/2
void main() {
final int x;
const int y = 1;
x = 8; // ok
y = 2; // error: Constant variables can't be assigned a value.
x = 9; // error: The final variable 'a' can only be set once.
}
2/1
Const is used to create constant values and to declare constructors by which immutable values are created. This allows any variable to have an immutable value.
2/2
var one = const [];
one = const [1, 2, 3]; // ok
one[0] = 4; //Unsupported operation: Cannot modify an unmodifiable list

final two = const [];
two = const [10, 3, 23]; // error

const three = [];
three = const [10, 3, 23]; // error
3/1
The late was added in Dart 2.12 and has now two uses:
1. To declare a variable that doesn't store a null value, which is initialized after it is declared;
2. For lazy variable initialization.
3/2
What is the difference between final and late?
Modifier final cannot be declared at the top level of the code. At the same time, variables declared with one of these modifiers must be initialized before they are used. Otherwise, an exception will be thrown.
3/3
late String lateName;
// final int finalName; // error

void main() {
final int finalName; // ok
// print(lateName); //error
// LateInitializationError: Field 'lateName' has not been initialized
lateName = '#Flutter';
print(lateName); // ok
}
Did you really read to the end and not fall asleep?
Don't follow me. You can get smart.
twitter.com/intent/follow?…

Retweet the first tweet.
DartPad 👇
dartpad.dev/bb9ee86d4204f6…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Vladimir Romashkin💙

Vladimir Romashkin💙 Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @romashkin_dev

4 Sep
The best books for app development with #Dart and #Flutter.
English, German, Russian, Italian, French
1
Dart Apprentice by Jonathan Sande @Suragch1 & Matt Galloway @mattjgalloway
Published by raywenderlich.com @rwenderlich
Version: First Edition
Language: Dart 2.12.2
Editor: VS Code 1.54
English | 2021 | ISBN: 978-1950325320 | 295 Pages
raywenderlich.com/books/dart-app…
2
Flutter Cookbook by Simone Alessandria (github.com/simoales), Brian Kayfitz @bkayfitz
English | 2021 | ISBN: 9781838823382 | 646 Pages
Publication date: June 2021
Publisher Packt @PacktPub
packtpub.com/product/flutte…
Read 31 tweets
2 Sep
#Flutter #Dart #CSS
CSS vs Flutter.
How to embed CSS examples in the text widget.
My success story.
Of course, you can find 15 awesome examples below.
🧵👇 Image
1 #Flutter #Dart #CSS
When I found an example, I thought, why not?
Shadows in CSS has this syntax:
// text-shadow: [horizontal offset] [vertical offset] [blur radius] [color];
// text-shadow: 0 2px 1px #747474,
// rgbo: 0px -4px 10px rgba(255,255,255,0.3);
2 #Flutter #Dart #CSS
Each shadow in the Text widget has 5 lines of code.
Shadow(
color: Color(0xFFFFFFFF),
offset: Offset(1.0, 1.0),
blurRadius: 1.0,
),
It's all good, but I broke my head when I found the example with 26 shadows.
WTF... 🤯🤯🤯
Read 21 tweets
29 Aug
#Flutter #Dart #CSS
CSS vs Flutter.
Flutter the containers with shadows.
How to create BoxShadow with CSS box-shadow?
21 amazing containers with CSS box-shadow in Flutter for the next app.
🧵👇
1⃣ #CSS vs #Flutter
CSS box-shadow: rgba(149, 157, 165, 0.2) 0px 8px 24px;
2⃣ #CSS vs #Flutter
CSS box-shadow: rgba(100, 100, 111, 0.2) 0px 7px 29px 0px;
Read 23 tweets
20 Aug
Let's study #Flutter.
How to remember new buttons in Flutter?
Old RaisedButton >>> ElevatedButton
Old FlatButton >>> TextButton
Old OutlinedButton >>> OutlinedButton
Three examples below & in DartPad🧵👇
1
ElevatedButton(
onPressed: () {},
child: const Text('ElevatedButton'),
style: ElevatedButton.styleFrom(
primary: Colors.yellow, //background button color
onPrimary: Colors.green, //text color
),
),
2
TextButton(
onPressed: () {},
child: const Text('TextButton'),
style: TextButton.styleFrom(
backgroundColor: Colors.yellow,
primary: Colors.deepOrangeAccent,
padding: const EdgeInsets.all(10),
),
),
Read 5 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(