Flutter 圈出数字
我想在一张图片的顶部画一个圆圈。因此,圆的内部是透明的,圆的边界是白色的。唉,双圈星的把戏,有一个圈星的边界不工作的透明背景。这里可以找到一个例子Flutter 圈出数字,flutter,dart,Flutter,Dart,我想在一张图片的顶部画一个圆圈。因此,圆的内部是透明的,圆的边界是白色的。唉,双圈星的把戏,有一个圈星的边界不工作的透明背景。这里可以找到一个例子 堆栈( 儿童:[ 图像网络( this.widget.rando.etapes[index].couvertureUrl, 宽度:90.0, 身高:90.0, 安装:BoxFit.盖), 容器( 宽度:90.0, 对齐:对齐.center, 子:容器( 孩子:圆环星( 背景颜色:颜色。透明, 半径:30, 子项:文本((索引+1).toString(
堆栈(
儿童:[
图像网络(
this.widget.rando.etapes[index].couvertureUrl,
宽度:90.0,
身高:90.0,
安装:BoxFit.盖),
容器(
宽度:90.0,
对齐:对齐.center,
子:容器(
孩子:圆环星(
背景颜色:颜色。透明,
半径:30,
子项:文本((索引+1).toString(),
样式:TextStyle(颜色:Colors.white,
字体大小:25.0,
fontWeight:fontWeight.w600),
),
),
)
]
),
您可以使用“Container”和装饰参数而不是“CircleAvatar”来完成此操作。这是我的测试代码。
导入“包装:颤振/材料.省道”;
void main(){
runApp(MyApp());
}
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
主题:主题数据(
主样本:颜色。蓝色,
视觉密度:视觉密度。自适应平台密度,
),
主页:MyHomePage(标题:“颤振演示主页”),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState扩展状态{
@凌驾
void initState(){
super.initState();
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(widget.title),
),
正文:_buildBody(),
浮动操作按钮:浮动操作按钮(
按下:(){},
工具提示:“增量”,
子:图标(Icons.add),
),
);
}
小部件_buildBody(){
返回容器(
身高:190,
宽度:190,
子:堆栈(
儿童:[
图像网络(
'https://images.unsplash.com/photo-1441974231531-c6227db76b6e?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=格式与配合=裁剪&w=1351&q=80',
宽度:190.0,
身高:190.0,
安装:BoxFit.盖),
居中(
子:容器(
宽度:90.0,
身高:90.0,
装饰:盒子装饰(
颜色:颜色。透明,
形状:BoxShape.circle,
边界:边界(
颜色:颜色,白色,
宽度:5.0,
样式:BorderStyle.solid,
),
),
儿童:中心(
子:文本(
'1',
样式:TextStyle(
颜色:颜色,白色,
字体大小:25.0,
fontWeight:fontWeight.w600,
),
),
),
),
),
],
),
);
}
}
工作正常!非常感谢您抽出时间。
Stack(
children: <Widget>[
Image.network(
this.widget.rando.etapes[index].couvertureUrl,
width: 90.0,
height: 90.0,
fit:BoxFit.cover),
Container(
width: 90.0,
alignment: Alignment.center,
child: Container(
child:CircleAvatar(
backgroundColor: Colors.transparent,
radius: 30,
child: Text((index+1).toString(),
style:TextStyle(color: Colors.white,
fontSize: 25.0,
fontWeight: FontWeight.w600)),
),
),
)
]
),
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(),
floatingActionButton: FloatingActionButton(
onPressed: () {},
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
Widget _buildBody() {
return Container(
height: 190,
width: 190,
child: Stack(
children: <Widget>[
Image.network(
'https://images.unsplash.com/photo-1441974231531-c6227db76b6e?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1351&q=80',
width: 190.0,
height: 190.0,
fit: BoxFit.cover),
Center(
child: Container(
width: 90.0,
height: 90.0,
decoration: BoxDecoration(
color: Colors.transparent,
shape: BoxShape.circle,
border: Border.all(
color: Colors.white,
width: 5.0,
style: BorderStyle.solid,
),
),
child: Center(
child: Text(
'1',
style: TextStyle(
color: Colors.white,
fontSize: 25.0,
fontWeight: FontWeight.w600,
),
),
),
),
),
],
),
);
}
}