我需要一个加载小部件,将移动的正弦和余弦函数绘制到画布中。我使用 CustomPaint 小部件和 CustomPainter 对其进行编码,没有任何问题,但是当我分析它时,我发现它的运行速度约为 49 fps,而不是 60 fps。UI 线程运行良好,每帧大约需要 6 毫秒,但光栅线程需要更长的时间。我尝试在画布上绘制更少的点(在 for 循环中使用 i=i+5 而不是 i++),但结果完全相同。
\n\xc2\xbf有人可以建议我如何提高性能吗?下面是小部件代码,以及 Raster 线程在每一帧中执行的操作的 DevTools 屏幕截图,以防它有用。
\nimport \'dart:math\';\n\nimport \'package:flutter/material.dart\';\n\nclass LoadingChart extends StatefulWidget{\n final Color color1;\n final Color color2;\n final double lineWidth;\n final bool line;\n final Size size;\n\n const LoadingChart({\n @required this.color1,\n @required this.color2,\n @required this.size,\n @required this.lineWidth,\n this.line = true,\n Key key\n }): super(key: key);\n\n @override\n State<StatefulWidget> createState() => _LoadingChartState();\n\n}\n\nclass _LoadingChartState extends State<LoadingChart>\n with SingleTickerProviderStateMixin{\n AnimationController _controller;\n\n\n double randomHeight(Random random, double max){\n …Run Code Online (Sandbox Code Playgroud) 我正在开发一个使用不同进度条的应用程序,我希望它们看起来像Google合适的,带有圆角。
我为每个带有不同颜色的条都有一个自定义可绘制对象,并且它使外部拐角而不是内部拐角变圆,如您在此处看到的:
我的自定义可绘制对象是:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="@dimen/progress_bar_rounded" />
<solid android:color="@color/progressbarBackground" />
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="@dimen/progress_bar_rounded" />
<solid android:color="@color/progressbarGreen" />
</shape>
</clip>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
进度条代码为:
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="@dimen/progress_bar_high"
android:id="@+id/GreenProgressBar"
android:indeterminate="false"
android:layout_marginLeft="15dp"
android:layout_gravity="center_vertical"
android:progressDrawable="@drawable/custom_green_progressbar" />
Run Code Online (Sandbox Code Playgroud)
我可以将某些库用作https://github.com/akexorcist/Android-RoundCornerProgressBar,但是由于这很简单,我认为这是不值得的。我也一直在寻找不同的线程,但是没有任何工作适合我。有什么想法,如果可能的话,不必使用.9.png图像?
非常感谢!
我正在处理一个 Flutter 项目,我试图实现一个类似于MaterialDesign Guidelines 上指定的选项对话框的 AlertDialog ,但底部有一个 TextInput。
我设法得到了与我想要的类似的东西,但我有一个无法解决的问题:当用户点击 TextInput 并出现键盘时,我希望 TextInput 位于键盘顶部,列表视图得到在 y 轴上更小(这就是为什么我只在 ConstrainedBox 上设置 maxHeight),以便用户可以看到他的文本,但我得到的正好相反,列表视图保持相同的大小,而 InputText 不可见.

我曾尝试使用嵌套在 SingleChildScrollView 上的列更改列表视图,或将整个原始列包装在 SingleChildScrollView 上,但它们似乎都不起作用。这是我当前的代码:
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text(widget.title),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20))
),
actions: <Widget>[
FlatButton(
child: const Text('CANCEL'),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
textColor: Theme.of(context).accentColor,
onPressed: () {
widget.onCancel();
},
),
FlatButton(
child: const Text('OK'),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
textColor: Theme.of(context).accentColor,
onPressed: () {
widget.onOk();
},
),
],
content: Container(
width: double.maxFinite,
child: Column( …Run Code Online (Sandbox Code Playgroud)