使用“Stack”小部件而不是“Paint”,实现了您的设计。
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: 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> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: _buildBody(),
);
}
Widget _buildBody() {
return Container(
height: 400,
width: 400,
child: Stack(
alignment: AlignmentDirectional.center,
children: [
Container(
width: 280,
height: 280,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Color(0xFF4C4D4F),
),
),
Container(
width: 200,
height: 200,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
),
),
Container(
width: 140,
height: 140,
child: Icon(
Icons.access_alarm,
color: Colors.white,
size: 30,
),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Color(0xFF5EA2EB),
),
)
],
),
);
}
}