Columで各ボタンウィジェットを縦に並べてみる。
上から
ElevatedButton
TextButton
OutlinedButton
IconButton
FloatingActionButton
import 'package:flutter/material.dart';
void main() {
// デバッグ用の関数。ボタンがクリックされたときにコンソールにメッセージを表示します。
debugFunction() {
debugPrint('ボタンがクリックされました');
}
// 背景色が緑のElevatedButtonを作成します。
final button1 = ElevatedButton(
onPressed: debugFunction,
child: Text('ElavatedButton'),
style: ElevatedButton.styleFrom(backgroundColor: Colors.green),
);
// TextButtonを作成します。
final button2 =
TextButton(onPressed: debugFunction, child: Text('TextButton'));
// OutlinedButtonを作成します。
final button3 =
OutlinedButton(onPressed: debugFunction, child: Text('OutlinedButton'));
// アイコン付きのIconButtonを作成します。
final button4 = IconButton(
onPressed: debugFunction,
icon: Icon(Icons.control_point),
);
final button5 =
FloatingActionButton(onPressed: debugFunction, child: Text('FAB'));
// MaterialAppウィジェットを使用して、アプリのルートを定義します。
final app = MaterialApp(
home: Scaffold(
// Scaffoldウィジェットを使用して、基本的なマテリアルデザインのレイアウトを提供します。
body: Center(
// Columnウィジェットを使用して、ボタンを垂直に並べます。
child: Column(mainAxisSize: MainAxisSize.min, children: [
button1,
button2,
button3,
button4,
button5,
]),
),
),
);
// アプリケーションを起動します。
runApp(app);
}