我希望 Textfield 中的文本背景如下所示:
但是用这段代码:
style: TextStyle(
background: Paint()..color = Colors.blue
..style = PaintingStyle.fill,
color: Colors.white,
),
Run Code Online (Sandbox Code Playgroud)
我有这个结果:
没有填充,没有圆角,两者之间有一条透明线......
我怎样才能做到这一点 ?
编辑 :
@Csaba Mihaly 提供了另一种方法TextStyle,但这是我想避免的解决方法。我正在寻找定制油漆解决方案
编辑 :
根据提供的答案,可以使用 PaintStyle.lines,但它不是 100% 匹配预期结果(第一个屏幕):
无论文本大小如何,为了填充空白,笔画宽度必须更大,正如我所看到的。它将渲染一个大的填充和角半径。就我而言:
我正在尝试实现一个圆形显示动画,其中包括在用户触摸视图时根据用户手指显示视图。
首先,我的视图在一个无限循环的显示循环内,只要用户什么都不做,就可以保持圆形。然后当用户触摸视图并开始滑动时,我计算了一个因子ACTION_MOVE以实时增加半径并在每次通过时调用圆形显示。
public void reveal(final View view,
final float centerX,
final float centerY,
final float startRadius,
final float endRadius,
final int duration) {
anim = ViewAnimationUtils.createCircularReveal(view, (int)centerX, (int)centerY, (int)startRadius, (int)endRadius);
anim.setDuration(duration);
anim.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
if (isRepeating) {
reveal(view,centerX,centerY,startRadius,endRadius,duration);
}
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
anim.start();
}
Run Code Online (Sandbox Code Playgroud)
我再次回忆起它的 Listener 中的循环显示方法来创建循环,最重要的是避免视觉失真。
我注意到,如果我不这样做,会出现一些非常快的失真,因为动画持续时间比每次传递都快,ACTION_MOVE因此动画有时间在下一次传递之前完成。失真是动画完成时视图缺失部分的表示,并像闪光一样快速返回到使用 Touch 设置的当前半径。 …
我正在将图库文件中的新内容推Route送到带有动画的详细信息文件中Hero。一切都很好,但是当我调用pop()详细信息文件内部以返回图库时,出现错误Provider:
flutter: \xe2\x95\x90\xe2\x95\x90\xe2\x95\xa1 EXCEPTION CAUGHT BY WIDGETS LIBRARY \xe2\x95\x9e\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nflutter: The following ProviderNotFoundException was thrown building GalleryThumbnail(dirty, state:\nflutter: _GalleryThumbnailState#9dc96):\nflutter: Error: Could not find the correct Provider<GalleryViewModel> above this GalleryThumbnail Widget\nRun Code Online (Sandbox Code Playgroud)\n这是我的画廊文件:
\n@override\n Widget build(BuildContext context) {\n return MultiProvider(\n providers: [\n ChangeNotifierProvider.value(value: galleryViewModel),\n ChangeNotifierProvider.value(value: galleryProvider)\n ],\n child: Scaffold(\n resizeToAvoidBottomInset: false,\n body: Stack(\n children: [\n Consumer<GalleryViewModel>(\n builder: (context, model, child) =>\n galleryViewModel.assetsList.length != 0 ? gallery() : emptyGallery()),\n\n...\n\n}\n\n\nWidget gallery() {\n return Container(\n …Run Code Online (Sandbox Code Playgroud) 我已经根据设备设置模式在我的应用程序中实现了深色和浅色主题。
我将应用程序置于后台,当我回来时,我在“恢复”上看到一些闪烁/闪烁。
这是我的应用程序中用于观察行为的随机页面:
行为就像在恢复时首先重置浅色主题,然后记住这实际上是深色主题集。然后我认为主应用程序主题可以在状态恢复时重新加载,但我不太确定。
材料应用程序是否在恢复时重新加载?
这是我的MaterialApp:
MaterialApp(
navigatorKey: NavigationService.navigatorKey,
theme: ThemeProvider.instance.getLightTheme(),
darkTheme: ThemeProvider.instance.getDarkTheme(),
themeMode: ThemeProvider.instance.getThemeMode(),
locale: Locale(SharedPreferencesManager.instance.getLocale()),
debugShowCheckedModeBanner: false,
localizationsDelegates: const [
LocalizationDelegate(),
CountryLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: LocaleManager().getSupportedLocale(),
home: WillPopScope(
onWillPop: () async => false,
child: const HomePage(),
));
Run Code Online (Sandbox Code Playgroud)
主题的主题提供者管理器方法:
ThemeMode getThemeMode() {
if (SharedPreferencesManager.instance.getTheme() == "dark") {
onDarkMode = true;
return ThemeMode.dark;
} else if (SharedPreferencesManager.instance.getTheme() == "light") {
onDarkMode = false;
return ThemeMode.light;
} else {
return ThemeMode.system;
}
}
ThemeData getDarkTheme() {
return …Run Code Online (Sandbox Code Playgroud) 在我的用例中,我必须监听我的CustomScrollView滚动,NotificationListener并且我想阻止我PageView在滑动时更新像素指标值。
代码 :
@override
Widget build(BuildContext context) {
return Scaffold(
body: NotificationListener(
onNotification: (ScrollNotification scroll) {
pixelsScrolled = scroll.metrics.pixels.toInt().toString();
setState(() {});
return true;
},
child: CustomScrollView(
slivers: [
SliverPadding(padding: EdgeInsets.all(20)),
SliverToBoxAdapter(
child: pageView(),
),
SliverPadding(padding: EdgeInsets.all(40)),
SliverToBoxAdapter(
child: Center(child: Text("Pixels scrolled : " + pixelsScrolled, style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold))),
),
],
),
),
);
}
Run Code Online (Sandbox Code Playgroud)
我想避免的结果
有没有办法避免NotificationListener观察所需的孩子?
感谢帮助
我知道这个问题以前被问过很多次,但每次我尝试从 ImageView 检索位图时,它都会返回 null 对象
我试过 :
ImageView imageView = findViewById(R.id.image);
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
Run Code Online (Sandbox Code Playgroud)
和
imageView.setDrawingCacheEnabled(true);
imageView.buildDrawingCache();
Bitmap bmap = imageView.getDrawingCache();
Run Code Online (Sandbox Code Playgroud)
而且还有滑行。
我错过了什么还是有其他方法可以实现这一目标?
感谢帮助