flutter - Flutter 容器覆盖小部件
问题描述
我想用 Flutter 获得如下图所示的图像。我应该如何提供这个?我可以为它提供容器边框,但我想放一个 wigdet 而不是边框。例如,我想用 Circleprogress 栏包装一个圆形小部件。进度应该随着小部件的增长而增长
Stack(
children: [
Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: context.themeCopyExtensions.backgroundColor,
shape: BoxShape.circle,
border: Border.all(width: 5),
boxShadow: [
BoxShadow(
color: context.themeCopyExtensions.backgroundColor,
blurRadius: 10)
]),
child: ImagesHelper.imagesHelper.getAssetImage(imageName: "logo"),
),
],
);
解决方案
我使用“Stack”小部件和“CircularProgressIndicator”实现。(需要调整每个小部件的大小)
/// Flutter code sample for CircularProgressIndicator
// This example shows a [CircularProgressIndicator] with a changing value.
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// This is the main application widget.
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyStatefulWidget(),
);
}
}
/// This is the stateful widget that the main application instantiates.
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({Key key}) : super(key: key);
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}
/// This is the private State class that goes with MyStatefulWidget.
/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin.
class _MyStatefulWidgetState extends State<MyStatefulWidget>
with TickerProviderStateMixin {
AnimationController controller;
@override
void initState() {
controller = AnimationController(
vsync: this,
duration: const Duration(seconds: 5),
)..addListener(() {
setState(() {});
});
controller.repeat(reverse: true);
super.initState();
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
width: 300,
child: Stack(
alignment: Alignment.center,
children: <Widget>[
CircularProgressIndicator(
value: controller.value,
strokeWidth: 5,
semanticsLabel: 'Linear progress indicator',
),
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Color(0xFF431CEE),
),
child: Icon(
Icons.audiotrack,
color: Colors.white,
size: 35,
),
),
],
),
),
],
),
),
);
}
}
推荐阅读
- javascript - laravel form bootstrap-select 无法正常工作
- c# - 防伪令牌无法解密?[无法摆脱这个奇怪的错误]
- python - 使用python登录booking.com
- php - 如何在 PHP 中获取关联数组的索引?
- ios - 如何将旧项目移动到 PersistentContainer
- c++ - 这个 OpenCV 矩阵表达式是什么意思?
- javascript - 在Javascript中单击标题时按升序和降序对表格进行排序
- java - 我在 apache karaf 中遇到类加载错误,同时加载了一些 java 资源,这对应于什么?
- reactjs - 有没有办法将 prop 传递给 JSX.Component?
- google-apis-explorer - 使用 youtube data api 上传视频时出现两个错误,Unknownpart 和权限不足