簡體   English   中英

帶有一些文本的半圈顫振

[英]Half circle with some text Flutter

我是flutter的新手,但我想知道是否有可能在flutter中做這樣的事情? 在兩個文本內繪制半個圓圈,我將在登錄表單中使用它。

您可以使用 Stack 小部件進行可自定義的疊加。

home: Scaffold(
  body: LayoutBuilder(
    builder: (context, constraints) {
      final width = constraints.maxWidth;
      return SizedBox(
        width: width,
        height: constraints.maxHeight,
        child: Stack(
          children: [
            // background 1st
            Positioned(
              top: 10,
              left: -width * .4,
              bottom: 10,
              right: 10,
              child: Container(
                decoration: const ShapeDecoration(
                  shape: CircleBorder(),
                  color: Colors.grey,
                ),
              ),
            ),

            Align(
              alignment: Alignment(-.4, .2),
              child: Text("Some Text"),
            ),
            Align(
              alignment: Alignment(-.4, -.2),
              child: Text("Some Text"),
            ),
          ],
        ),
      );
    },
  ),
),

查看有關Stack小部件和/ui/layout的更多信息。

您可以使用灰色創建容器並在盒子裝飾中進行一些更改。 比如邊界半徑。 這是代碼。

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        body: Center(
          child: SizedBox(
            height: 200,
            width: 125,
            child: Container(
              decoration: const BoxDecoration(
                color: Colors.grey,
                borderRadius: BorderRadius.only(
                    bottomRight: Radius.circular(200),
                    topRight: Radius.circular(200),
                    bottomLeft: Radius.circular(0),
                    topLeft: Radius.circular(0)),
              ),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text("SOME TEXT", style: TextStyle(fontSize: 15)),
                  SizedBox(
                    height: 50,
                  ),
                  Text("SOME TEXT", style: TextStyle(fontSize: 15)),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM