[英]How to round corners of an entire app in Flutter?
I want my app to simulate the rounded display corners most modern day smartphones have by rounding the corners of the app and making the background black.我希望我的应用程序通过将应用程序的角弄圆并使背景变黑来模拟大多数现代智能手机所具有的圆角显示角。 Currently, the TikTok app has something like this.
目前, TikTok应用程序有这样的东西。
I already tried using the borderRadius property of the Material widget and wrapping the contents into a container with rounded corners.我已经尝试使用Material小部件的borderRadius 属性并将内容包装到一个带有圆角的容器中。 Neither one worked for me.
没有一个对我有用。
Any ideas how this could be done?任何想法如何做到这一点?
I would use ClipRRect at the up most level:我会在最高级别使用ClipRRect :
Here is a full example:这是一个完整的例子:
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")));
}
}
And here is the result:结果如下:
Maybe you will want to reduce the radius from 20 to something like 8 to have the result similar to the image you provided.也许您希望将半径从 20 减小到 8 左右,以得到与您提供的图像相似的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.