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

时间:2019-10-10 13:02:19

标签: android ios flutter dart flutter-layout

我希望我的应用程序通过将应用程序的角弄圆并使背景变黑来模拟大多数现代智能手机具有的圆形显示角。 当前,TikTok应用具有类似的内容。

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

有什么想法可以做到吗?

1 个答案:

答案 0 :(得分:1)

我会在最高级别使用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")));
  }
}

结果如下:

enter image description here

也许您希望将半径从20减小到8,以使结果类似于您提供的图像。

相关问题