Android アプリケーションフラッターは、Positioned を使用してコントロールを中央下に配置します。

ここに画像の説明を挿入します

記事ディレクトリ

シーンの説明

Positioned を画面の下の中央に配置するには、MediaQuery を使用して画面の高さを取得し、Positioned の Bottom 属性と left または right 属性を設定します。通常は left と right の値を設定します。では、コントロールを下部の中央に配置するにはどうすればよいでしょうか?

サンプルコードは次のとおりです。

import 'package:flutter/material.dart';

void main() {
    
    
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
    
    
  
  Widget build(BuildContext context) {
    
    
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Positioned Example'),
        ),
        body: MyPositionedWidget(),
      ),
    );
  }
}

class MyPositionedWidget extends StatelessWidget {
    
    
  
  Widget build(BuildContext context) {
    
    
    double screenHeight = MediaQuery.of(context).size.height;

    return Stack(
      children: [
        // Your main content goes here
        Center(
          child: Text(
            'Main Content',
            style: TextStyle(fontSize: 20),
          ),
        ),

        // Positioned at the bottom center
        Positioned(
          bottom: 0,
          left: 0,
          right: 0,
          child: Container(
            height: 50,
            color: Colors.blue,
            child: Center(
              child: Text(
                'Positioned at the bottom center',
                style: TextStyle(color: Colors.white),
              ),
            ),
          ),
        ),
      ],
    );
  }
}

説明する

この例では、Positioned には青い背景のコンテナが含まれており、画面の中央下にあります。bottom: 0 は画面の一番下に配置され、left: 0 と right: 0 は画面幅全体を水平に埋めます。必要に応じて、高さ、色、コンテンツを調整できます。


結論
Flutter は、Google が開発したオープンソース UI ツールキットで、これを使用すると、プラットフォーム固有のコードを大量に記述せずに、さまざまなプラットフォーム上で高品質で美しいアプリケーションを作成できます。Flutter のあらゆる側面を学び、掘り下げていきます。基礎知識から高度なテクニック、UIデザインからパフォーマンスの最適化まで、一緒に議論して学び、一緒にFlutterの素晴らしい世界に入りましょう。

Supongo que te gusta

Origin blog.csdn.net/yikezhuixun/article/details/134997242
Recomendado
Clasificación