| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

差分

ナビゲーションに移動 検索に移動
4,146 バイト追加 、 2022年2月16日 (水) 09:20
==[[Dart]]==
|[[Flutter]] | [https://www.typea.info/blog/index.php/category/flutter/ ブログカテゴリ(Flutter)] | [[Android Studio]] | [[Flutter macos]] | [[FlutterFire]] | [[Flutter 手順]] |
{{amazon|B00JB3CWZI}}
*https://dart.dev/
===言語仕様===
----
*[https://dart.dev/guides/language/spec 言語仕様]
*[https://dart.dev/guides/language/specifications/DartLangSpec-v2.10.pdf 言語仕様2.1]
*[https://www.cresc.co.jp/tech/java/Google_Dart2/introduction/main_page.html Dart2解説]
 
==[https://dart.dev/guides/language/effective-dart/design#prefer-type-annotating-public-fields-and-top-level-variables-if-the-type-isnt-obvious Effective Dart]==
*[https://dart.dev/guides/language/effective-dart/design#prefer-type-annotating-public-fields-and-top-level-variables-if-the-type-isnt-obvious Effective Dart]
 
==基本==
===Install===
*map
*reduce
=====連結=====
<pre>
void main() {
var l = [1,2,3];
print(l);
[...l, 4, 5, 6];
print(l);
l = [...l, 4, 5, 6];
print(l);
}
</pre>
*結果
<pre>
[1, 2, 3]
[1, 2, 3]
[1, 2, 3, 4, 5, 6]
</pre>
 
====Map====
----
----
*[[Dart]]の構文での演算子や識別子
====[https://www.cresc.co.jp/tech/java/Google_Dart2/language/functions/functions.html Functions]====
----
*[https://www.cresc.co.jp/tech/java/Google_Dart2/language/functions/functions.html 関数] *関数は実行可能なアクションの抽象化*関数もオブジェクトでその型はFunction*関数は第1級関数(first-class function)であり、ある関数を別の関数にパラメターとして渡すことも可能 
====Enum====
----
====コメント ====
----
=====単一行=====
*//
 
=====複数行=====
*/*...*/
 =====ドキュメンテーション=====*/**または///で始まる* 角括弧を使ってクラス、メソッド、フィールド、トップ・レベル変数、及びパラメタを参照可能* 角括弧内の名前はそのドキュメント化されたプログラム要素の構文スコープ内で解決*[https://dart.dev/guides/language/effective-dart/documentation ドキュメンテーション]*[https://github.com/dart-lang/ ドキュメンテーションコメントdartdoc#dartdoc ドキュメンテーションツール]
===変数===
*第1級オブジェクト
*宣言
&lt;blockquote&gt;常&lt;/blockquote&gt;*関数もオブジェクトでその型はFunction*Dartの関数は第1級関数(first-class function)である。*関数を別の関数にパラメタとして渡すことも可能である.
int someFunc2(int a, int b) {
return a + b;
}
====1行矢印構文(arrow syntax)====
----
* => exprという構文は{ return expr; }の短縮形
<blockquote>式のみが矢印(=>)とセミコロン(;)の間に置かれる。例えば、if文はおけないが、条件式は使える。</blockquote>
bool isHoge(String str) =&gt; str == "hoge";
 
====引数の指定====
----
====無名関数(ラムダ、[[クロージャ]])====
----
[[Category:ラムダ]]
 
list.forEach((item) =&gt; print(item));
 
====ブロック====
----
----
*?.
===アクセッサ===
----
*http://dart-ing.blogspot.com/2012/03/dartgetset.html
*クラスのメンバーにgetとset(いわゆるゲッターとセッター)を定義することができます。ゲッターとセッターで定義されたメンバーは、あたかもメンバー変数と同じようにアクセスできますが、変数への代入だけではなく、ほかの処理を追加することもできます。
<pre>
class Line {
Line(this.start, this.end);
int start, end;
int get length() => end - start;
void set length(int len) {
end = start + len;
}
}
</pre>
===構文===
----
// sはスタックトレース
} finally{}
 
==null安全==
*https://medium.com/flutterworld/flutter-null-safety-5d20012c2441
*https://gaprot.jp/2021/04/27/flutter-sound-null-safety/
*[https://dart.dev/codelabs/null-safety#map-types null安全コードラボ]
 
*ver2.1.2 から型レベルでnull安全を導入
<pre>
final String country = null; // nullを代入できない
final String? country = null; // nullを代入できる
</pre>
 
===Non Nullable Type===
----
*変数に ! を付けることで、その変数が NULL ではないことをコンパイラに伝え、安全に使用できる
<pre>
void main() {
String? country = "USA";
String myCountry = country!; // myCountry は null不許可 country が null の場合はエラーとなる
}
</pre>
===lateの使用===
----
*lateキーワード は後で初期化される変数を示すために使用できる。
*宣言時ではなく、アクセス時に初期化される。
*初期化される前の値にアクセスすると、ランタイムエラーが発生
<pre>
void main() {
late String country; // null不許可
// ここで、print(value) した場合、ランタイムエラー
country = "USA";
}
</pre>
==ジェネリクス==
----
void hoge(List&lt;T&gt; list){}
*asyncパッケージをインポート
import 'dart:async';
==拡張メソッド(Extension method)==
*[https://qiita.com/akiakishitai/items/e2fc2e5ae8b7f6abcde4 拡張メソッド]
==[[言語]]サンプル==
*https://dart.dev/samples
----
*https://api.dart.dev/stable/2.5.0/dart-io/File-class.html
 
==Tips==
===実行時の型を調べる===
print(json.encode(yourMapVariable));
</pre>
 
[[category:プログラミング言語]]

案内メニュー