.NET 開発基盤部会 Wiki」は、「Open棟梁Project」,「OSSコンソーシアム .NET開発基盤部会」によって運営されています。

目次

概要

Flutter の step by step(其の一)。

手順1:インストールから実行まで。

コチラを参考にして実施

インストール

ダウンロード

https://flutter.dev/docs/get-started/install/windows

解凍&パス指定

flutter_windows_x.x.x-stable.zip

チェック(1)

以下のCommandを実行し、TODOを確認する。

>flutter doctor

Android Studioのインストール

※ 前述のPowerShell?だと、%USERPROFILE%が展開されねぇんだけど...。

プラグインのインストール

「File」メニュー -> 「Settings..」 -> 「Plugins」

チェック(2)

以下のCommandを実行し、問題が無いことを確認する。

>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.0.3, on Microsoft Windows [Version 
10.0.19041.867], locale ja-JP)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] VS Code, 64-bit edition (version 1.47.2)
[√] Connected device (2 available)

• No issues found!

>

余談:SDKのパス変更

SDKのパスを変更する場合、以下の手順に従って変更する。

サンプルの生成と実行

新規作成プロジェクト

Android Studioで、新規作成プロジェクトする。

プロジェクトタイプ概要
Flutter Applicationアプリケーション用
Flutter Plugin AndroidネイティブAPI用ライブラリ用
Flutter Package画面部品用
Flutter ModuleDartライブラリ用

デバッグ実行

プロジェクトの開発

以降の手順で説明する。

デバッグ実行

Android Studioで1GB、エミュレータで6GB程、メモリを消費するので、
開発機のメモリが16GB程度では少々、スペック不足、故に実機でのデバッグを行うことになる。

エミュレータを登録して実行

実機でデバッグ実行する場合

Flutter Devtoolsを利用する。

FlutterInspector

その他のツールを利用する。

を併用すると、RAD風に開発できる。

手順2:イベントを実装する。

ボタンのWidget

RaisedButton?

RaisedButton(
  child: const Text('Button'),
  color: Colors.orange,
  textColor: Colors.white,
  onPressed: () {},
),

ElevatedButton?

onPressedに、任意のメソッドを書く。

ElevatedButton(
  child: const Text('Button'),
  style: ElevatedButton.styleFrom(
    primary: Colors.orange,
    onPrimary: Colors.white,
  ),
  onPressed: () {},
),

FlatButton?

FlatButton(
  child: const Text('Button'),
  textColor: Colors.black,
  onPressed: () {},
),

TextButton?

onPressedに、任意のメソッドを書く。

TextButton(
  child: const Text('Button'),
  style: TextButton.styleFrom(
    primary: Colors.black,
  ),
  onPressed: () {},
),

OutlineButton?

OutlineButton(
  child: const Text('Button'),
  onPressed: () {},
),

OutlinedButton?

onPressedに、任意のメソッドを書く。

OutlinedButton(
  child: const Text('Button'),
  style: OutlinedButton.styleFrom(
    primary: Colors.black,
  ),
  onPressed: () {},
),

IconButton?

ButtonBar?

FloatingActionButton?

PopupMenuButton?

DropdownButton?

任意のWidget

ボタンでない、任意のWidgetに、イベントを実装できる。

InkWell?

簡単に、Ripple エフェクトを付ける事が出来る。

Material(                  // 親にMaterialが必須
 color: Colors.blue,       // Material自体は青を指定
 child: Center(            //
   child: Ink(             // ここをContainerにするとsplashが効かないので、Inkに変える
     color: Colors.yellow, // 背景色はここで指定
     width: 200.0,
     height: 100.0,
     child: InkWell(
         onTap: () {},
         child: Center(child: Text('YELLOW'))
     ),
   ),
 ),
)

GestureDetector?

InkWellのRipple エフェクトは無いが、
他のイベント(ジェスチャー)にも反応する。

GestureDetector(
  // タッチ検出対象のWidget
  child: Text(
    'How to use GestureDetector',
    textAlign: TextAlign.center,
    overflow: TextOverflow.ellipsis,
    style: TextStyle(fontWeight: FontWeight.bold),
  ),
  // ダブルタップ
  onDoubleTap: _incrementCounter
)

参考

Qiita

手順3:画面遷移処理を実装する。

API

push

Navigator.of(context).pop();
Navigator.of(context).push(
  MaterialPageRoute(
    builder: (context) {
      return MyHomePage(title: 'Flutter Demo Home PageA');
    },
  ),
);

pushNamed

メニュー

AppBar?

にNavigatorによる画面遷移を書く。

Drawer

TabBar?

BottomNavigationBar?

参考

Qiita

手順4:レイアウトを行う。

body, children or childと、レイアウトを行う。

Layout系

Container

のサイズになる。

body: Container(
  ...
  child: Column or Row

Center

body: Center(
  ...
  child: Column or Row

その他

Multi Layout系

Colmn

body: Column(
  ...
  children: <Widget>[
    Row(

Row

body: Row(
  ...
  children: <Widget>[
    Column(

その他

AxisAlignment?

内部コンテンツの位置

MainAxisAlignment?

前述の、...の部分に、

mainAxisAlignment: MainAxisAlignment.XXXXX,

...と書き、主軸方向の配置位置を調整する。

CrossAxisAlignment?

前述の、...の部分に、

crossAxisAlignment: CrossAxisAlignment.XXXXX,

...と書き、交差軸方向の配置位置を調整する。

参考

手順5:パッケージの追加と利用

english_wordsパッケージの例

パッケージの追加

english_wordsパッケージを追加・利用する。

パッケージの利用

ブラウザ起動(url_launcher)

パッケージ追加

url_launcherパッケージを追加する必要がある。

パッケージの利用

import 'package:url_launcher/url_launcher.dart';
_launchURL() async {
  const url = "http://https://www.google.co.jp/";
  if (await canLaunch(url)) {
    await launch(url);
  } else {
    throw 'Could not Launch $url';
  }
}

参考

WebAPIを呼び出す。

パッケージ追加

HTTPパッケージを追加する必要がある。

GET

POST

その他

参考

参考

Flutterのセカンド・ステップ

参考


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS