4
1

More than 3 years have passed since last update.

東北TECH道場Flutter講座のUI/UX改善例をやってみた

Last updated at Posted at 2020-08-18

2020/8/18/に東北TECH道場Flutter講座に参加しました.
今回はFlutterについて様々な勉強会で登壇されている,神原健一さんのお話をお伺いしました.

そのお話の中でも「UI/UXの改善例」が興味深かったので,実際に手を動かしてみてアウトプットしてみるといった内容です.
何かツッコミなどあれば編集リクエストかコメントかTwitterでいただければ修正いたします

今回学ぶこと

・FlutterでのUI/UXの改善例
①paddingをつける
②外枠をつける
③ラベルをつける

目指す成果物

こちらのように,Textを入力するためのWidgetのUI/UX改善をしてみます.

before after
スクリーンショット 2020-08-18 22 07 03

beforeのコードはこちらです.

main.dart
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: Text(
              'Book',
              style: TextStyle(
                color: Colors.grey,
              ),
            ),
            backgroundColor: Colors.white,
          ),
          body: Center(
            child: Column(
              children: <Widget>[
                TextField(),
                TextField(),
                RaisedButton(
                  onPressed: () {},
                  color: Colors.blue,
                  child: Text(
                    'Tap',
                    style: TextStyle(
                      color: Colors.white,
                    ),
                  ),
                ),
              ],
            ),
          )),
    );
  }
}

ステップ

1. 余白(padding)をつける

やり方は,このようにPadding()でTextFile()をネストしてあげるとpaddingが設定できます.

Padding(
 padding: const EdgeInsets.all(8.0),
 child: TextField(),
),

全体のコードはこちらです.

main.dart
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: Text(
              'Book',
              style: TextStyle(
                color: Colors.grey,
              ),
            ),
            backgroundColor: Colors.white,
          ),
          body: Center(
            child: Column(
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: TextField(),
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: TextField(),
                ),
                RaisedButton(
                  onPressed: () {},
                  color: Colors.blue,
                  child: Text(
                    'Tap',
                    style: TextStyle(
                      color: Colors.white,
                    ),
                  ),
                ),
              ],
            ),
          )),
    );
  }
}

2. 外枠(border)をつける

外枠をつけると,こんなイメージです.
スクリーンショット 2020-08-18 22 06 12

やり方は,このようにTextFiled()内でdecoration: InputDecoration(border: OutlineInputBorder(),を加えると外枠が設定できます.

Padding(
  padding: const EdgeInsets.all(8.0),
  child: TextField(
    decoration: InputDecoration(border: OutlineInputBorder(),
  ),
),

全体のコードはこちらです.

main.dart
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: Text(
              'Book',
              style: TextStyle(
                color: Colors.grey,
              ),
            ),
            backgroundColor: Colors.white,
          ),
          body: Center(
            child: Column(
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: TextField(
                    decoration: InputDecoration(border: OutlineInputBorder()),
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: TextField(
                    decoration: InputDecoration(border: OutlineInputBorder()),
                  ),
                ),
                RaisedButton(
                  onPressed: () {},
                  color: Colors.blue,
                  child: Text(
                    'Tap',
                    style: TextStyle(
                      color: Colors.white,
                    ),
                  ),
                ),
              ],
            ),
          )),
    );
  }
}

3. ラベルをつける

ラベルをつけると,こんなイメージです.
スクリーンショット 2020-08-18 22 05 32

やり方は,このようにTextFiled()内でlabelText: 'title',を加えるとラベルが設定できます.

Padding(
  padding: const EdgeInsets.all(8.0),
  child: TextField(
    decoration: InputDecoration(
    labelText: 'title', border: OutlineInputBorder()),
  ),
),

全体のコードはこちらです.

main.dart
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: Text(
              'Book',
              style: TextStyle(
                color: Colors.grey,
              ),
            ),
            backgroundColor: Colors.white,
          ),
          body: Center(
            child: Column(
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: TextField(
                    decoration: InputDecoration(
                        labelText: 'title', border: OutlineInputBorder()),
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: TextField(
                    decoration: InputDecoration(
                        labelText: 'author', border: OutlineInputBorder()),
                  ),
                ),
                RaisedButton(
                  onPressed: () {},
                  color: Colors.blue,
                  child: Text(
                    'Tap',
                    style: TextStyle(
                      color: Colors.white,
                    ),
                  ),
                ),
              ],
            ),
          )),
    );
  }
}

このようにテキストの入力するときに,ラベルが外枠に重なるように表示されるようになります.

以上でUI/UX改善例は終了です.

ソースコード

Github:
https://github.com/syuheifujita/flutter-tech-dojo-fix-ui

参考資料

登壇された神原健一さんの各種アカウント

神原健一さんのTwitter: https://twitter.com/korodroid

HP: http://www.iplatform.org/blog/profile

東北TECH道場

http://tohokutechdojo.appspot.com/
スクリーンショット 2020-08-18 22 01 36

おわりに:他にもっとわかりやすい方法あれば教えてください

もしかすると,情報が古かったり間違っていたり,他にもっとわかりやすい方法があるのかもしれません.
皆さんの中で上手に使い方をまとめているかたがいればぜひ教えてください!
Twitterやコメントなどでお待ちしています.質問でもお気軽に!

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1