FlutterのためのDart基礎
Flutterに不可欠な変数、データ型、制御フロー、関数、オブジェクト指向の概念など、Dartプログラミングの基礎を学びます。
「FlutterのためのDart基礎」はCoddyKit上の無料Flutter Mobile Developmentレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはFlutter Mobile Development学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Flutter Mobile Developmentコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Welcome to Dart!
Before building apps, let’s learn Dart — Flutter’s language. It’s client-optimized and quick to pick up if you know Java or JavaScript.
Storing Data: Variables & Types
Variables store data. Declare them with var for inferred types, or be explicit: int, double, String, bool.
Variables in Action
Here’s declaring different variable types. Note Dart’s null safety: a variable can’t be null unless you opt in with ?.
void main() {
var name = "Alice"; // Type inferred as String
int age = 30;
double height = 1.75;
bool isStudent = true;
String? middleName; // Can be null
print("Name: $name");
print("Age: $age");
print("Student: $isStudent");
}Grouping Data: Lists
A Dart List is an ordered, zero-indexed collection — like an array. Declare a typed one like List<String> and grab items by position.
void main() {
List<String> fruits = ['Apple', 'Banana'];
print('Initial fruits: $fruits');
fruits.add('Orange'); // Add an item
print('After adding: $fruits');
print('First fruit: ${fruits[0]}');
}Making Decisions: If/Else
Control flow lets your code decide. if runs when a condition is true; chain else if and else for the rest.
void main() {
int temperature = 25;
if (temperature > 30) {
print('It\'s very hot!');
} else if (temperature > 20) {
print('It\'s warm.');
} else {
print('It\'s cool.');
}
}Repeating Actions: Loops
Loops repeat a block. A for loop is perfect for iterating a list or running a task a fixed number of times.
void main() {
List<String> colors = ['Red', 'Green', 'Blue'];
for (String color in colors) {
print('Color: $color');
}
for (int i = 0; i < 3; i++) {
print('Count: $i');
}
}Functions: Reusable Code
Functions are reusable blocks that do one task. They take parameters as input and can return a value as output.
Defining & Calling Functions
This shows two functions: greet takes a name, add returns an int. void means a function returns nothing.
void greet(String name) {
print('Hello, $name!');
}
int add(int a, int b) {
return a + b;
}
void main() {
greet('Coddy');
int sum = add(10, 5);
print('Sum: $sum');
}Basic Classes & Objects
Dart is object-oriented: a class is a blueprint for objects. Objects bundle properties (data) and methods (behavior) to keep code organized.
class Car {
String brand; // Property
int year; // Property
Car(this.brand, this.year); // Constructor
void displayInfo() { // Method
print('$brand from $year');
}
}
void main() {
var myCar = Car('Toyota', 2020); // Create an object
myCar.displayInfo(); // Call a method
var otherCar = Car('Honda', 2022);
otherCar.displayInfo();
}Dart Fundamentals Check
Which of the following Dart code snippets are valid variable declarations or initializations?
Recap: Dart Essentials
Nice work! You’ve got Dart’s core building blocks — variables, lists, control flow, loops, functions, and classes. This is the foundation for every Flutter app.
よくある質問
「FlutterのためのDart基礎」レッスンは無料ですか?
はい。「FlutterのためのDart基礎」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Flutter Mobile Developmentコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Flutter Mobile Developmentコースには全4レッスンが含まれています。
「FlutterのためのDart基礎」で何を学びますか?
Flutterに不可欠な変数、データ型、制御フロー、関数、オブジェクト指向の概念など、Dartプログラミングの基礎を学びます。 ブラウザで直接実行するハンズオンコードでFlutter Mobile Developmentを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Flutter Mobile Developmentを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのFlutter Mobile Developmentは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「FlutterのためのDart基礎」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このFlutter Mobile Developmentレッスンでコードを書いて実行できますか?
はい。すべてのFlutter Mobile Developmentレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。