Flutter 卡/容器/边框问题

问题描述 投票:0回答:1

我想制作一张这样形状的卡片:

enter image description here

我目前面临的问题是这样的情况:

enter image description here

如果仔细观察,您会发现容器没有像边框那样呈圆形。 在对边框本身进行注释后,卡片本身似乎是圆形的,但上面的容器不是圆形的,它比卡片本身更大?

enter image description here

您知道如何解决这个问题吗?

我的代码:

@override
Widget build(BuildContext context) {
return Card(
  elevation: 6,
  // shape: RoundedRectangleBorder(
  //   borderRadius: BorderRadius.circular(15.0),
  // side: const BorderSide(
  //   color: Color.fromRGBO(255, 128, 0, 1),
  //   width: 2.0,
  // ),
  // ),
  child: GestureDetector(
    onTap: () => Navigator.of(context).push(
      MaterialPageRoute(builder: (context) => XxxView()),
    ),
    child: Container(
      width: 130,
      padding: const EdgeInsets.all(15.0),
      color: const Color.fromRGBO(86, 89, 94, 1),
      child: Column(children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              numberExample.toString(),
              style: Theme.of(context).textTheme.bodyLarge,
              //maxLines: 1,
              //overflow: TextOverflow.ellipsis,
            ),
            Icon(
              icon,
              color: Colors.white,
            ),
          ],
        ),
        Text(
          text,
          style: const TextStyle(
            fontSize: 20,
            color: Colors.white,
          ),
        ),
      ]),
    ),
  ),
);

} }

flutter containers border card
1个回答
0
投票

您需要通过使用

Container
属性在
BoxDecoration
内指定边框半径来向
borderRadius
小部件添加边框半径。这是示例代码:

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: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        colorSchemeSeed: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  final String title;

  const MyHomePage({
    super.key,
    required this.title,
  });

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Card(
        elevation: 6,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(15.0),
          side: const BorderSide(
            color: Color.fromRGBO(255, 128, 0, 1),
            width: 2.0,
          ),
        ),
        child: GestureDetector(
          onTap: () {},
          child: Container(
            width: 130,
            height: 100,
            decoration: BoxDecoration(
              color: const Color.fromRGBO(86, 89, 94, 1),
              borderRadius: BorderRadius.circular(15.0)
            ),
            padding: const EdgeInsets.all(15.0),
            child: Column(children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    "2",
                    style: Theme.of(context).textTheme.bodyLarge,
                  ),
                  Icon(
                    Icons.abc,
                    color: Colors.white,
                  ),
                ],
              ),
              Text(
                "test",
                style: const TextStyle(
                  fontSize: 20,
                  color: Colors.white,
                ),
              ),
            ]),
          ),
        ),
      )
    );
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.