如何在 Flutter 中对整个应用程序进行圆角处理?

Luc*_*ach 1 android ios dart flutter flutter-layout

我希望我的应用程序通过将应用程序的角变圆并使背景变黑来模拟大多数现代智能手机的圆角显示角。目前,TikTok应用程序有这样的功能。

我已经尝试使用Material小部件的 borderRadius 属性并将内容包装到带有圆角的容器中。没有一个为我工作。

任何想法如何做到这一点?

Dur*_*rdu 8

我会在最上层使用ClipRRect

这是一个完整的例子:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: ClipRRect(
        borderRadius: BorderRadius.circular(20.0),
        child: MyHomePage(title: 'Flutter Demo Home Page')),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text("Something")),
        body: Container(alignment: Alignment.center, color: Colors.blue, child: Text("hello")));
  }
}
Run Code Online (Sandbox Code Playgroud)

结果如下:

在此处输入图片说明

也许您希望将半径从 20 减小到 8 之类的值,以获得与您提供的图像类似的结果。