【 Flutter 】Flutter を 基礎 から 学習 ( ウィジェット編 ) part98 Interaction model widgets
「 基礎 から 学ぶ Flutter 」という書籍で 学習 したことを ブログでアウトプットしていこうと思います。今回は ウィジェット編 ( part98 )です。
前回
【 Flutter 】Flutter を 基礎 から 学習 ( ウィジェット編 ) part97 Input
新しくInteraction model widgetsについて学びます。
Interaction model widgets
GestureDetectorウィジェット
GestureDetector
ウィジェットはジェスチャーを検出するウィジェットです。
マテリアルデザインを使用する場合はGestureDetector
ウィジェットではなくInkWell
ウィジェットの方を使用するそうです。
InkWell
ウィジェットはGestureDetector
ウィジェットのラッパーのような存在なのでしょうか。
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() {
// runApp(new MaterialApp(home: new MyApp()));
runApp(new MaterialApp(home: new SamplePage()));
}
class SamplePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _SamplePageState();
}
}
class _SamplePageState extends State<SamplePage> {
var _lighits = false;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('テスト中!')),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
GestureDetector(
onTap: () {
setState(
() {
_lighits = !_lighits;
},
);
},
child: Container(
color: _lighits ? Colors.yellow : Colors.greenAccent,
child: Text(
_lighits ? 'タップしてライトオフ!' : 'タップしてライトオン!',
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontWeight: FontWeight.bold),
),
width: 200.0,
height: 200.0,
),
)
],
),
),
);
}
}
他にもたくさんのジェスチャーがあるようです。
最後に
・・・InkWell
ウィジェットの説明は?
今日はここまで!
ディスカッション
コメント一覧
まだ、コメントがありません