0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Flutter 〜簡単にキレイな日付選択ダイアログを作成できるDatePickerDialogを使う〜

Posted at

DatePickerDialogについて

日付入力の際に使用するダイアログが簡単にできるDatePikcerDialogのサンプル。

サンプルコード

// 必要なFlutterのMaterialデザイン関連のパッケージをインポート
import 'package:flutter/material.dart';

// アプリケーションのエントリポイントです。プログラムが実行されるとここから開始。
void main() {
  // MyAppクラスのインスタンスを作成し、それをアプリのルートウィジェットとして設定する。
  runApp(MyApp());  
}

// StatelessWidgetを継承したMyAppクラスを定義
class MyApp extends StatelessWidget {
  // buildメソッドはウィジェットが描画される際に呼ばれるメソッド
  @override
  Widget build(BuildContext context) {
    // MaterialAppはMaterialデザインのアプリケーションを作るためのルートウィジェット
    return MaterialApp(
      home: Scaffold(
        // ScaffoldはMaterialデザインの基本的なレイアウト構造を提供するウィジェットで、アプリケーションの基盤となる。
        body: Column(
          // Columnウィジェットは子ウィジェットを垂直方向に並べる。
          // 子ウィジェットを中央に配置。
          mainAxisAlignment: MainAxisAlignment.center,  
          children: [
            // DatePickerDialogは日付を選択するためのダイアログウィジェット。
            DatePickerDialog(
              // 初期選択日を10年前の今日の日付に設定。
              initialDate: DateTime(DateTime.now().year - 10), 
              // 選択可能な最古の日付を100年前の今日の日付に設定。
              firstDate: DateTime(DateTime.now().year - 100),  
              // 選択可能な最新の日付を今日の日付に設定。
              lastDate: DateTime(DateTime.now().year),              
              ),
          ],
        ),
      ),
    );
  }
}
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?