我正在使用ipywidgets创建一个简短的表单,显示两个字段,图像的预期宽度和高度。
我想添加一个复选框,以便如果选中该框,则从文件中加载信息。
如果选中该框,应出现一个文本区域(或文件选择器)和一个加载文件的按钮,读取它并填充文本框。
我应该通过观察复选框事件来做到这一点吗?有没有办法隐藏小部件?
我的应用程序是使用 aMaterialApp作为根小部件构建的。对于这个材质应用,我添加了一个主题如下:
MaterialApp(
theme: myTheme,
home: MyHomePage(),
...
)
final ThemeData myTheme = _buildTheme();
ThemeData _buildTheme() {
final ThemeData base = ThemeData.light();
return base.copyWith(
...
textTheme: _buildMyTextTheme(base.textTheme),
primaryTextTheme: _buildMyTextTheme(base.primaryTextTheme),
accentTextTheme: _buildMyTextTheme(base.accentTextTheme),
pageTransitionsTheme: PageTransitionsTheme(builders: {
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
}));
}
TextTheme _buildMyTextTheme(TextTheme base) {
return base
.copyWith(
headline:
base.headline.copyWith(fontSize: 20.0, fontWeight: FontWeight.w500),
title: base.title.copyWith(fontSize: 18.0, fontWeight: FontWeight.w400),
subhead:
base.subhead.copyWith(fontSize: 16.0, fontWeight: FontWeight.w400),
body1: base.body1.copyWith(fontSize: 14.0, fontWeight: FontWeight.w400),
body2: base.body2.copyWith(fontSize: 14.0, fontWeight: FontWeight.w500),
caption: base.caption.copyWith(
fontWeight: FontWeight.w400,
fontSize: 12.0,
),
) …Run Code Online (Sandbox Code Playgroud) 我正在为 Go 和 Fyne 苦苦挣扎,对这两种语言都不熟悉,也太习惯 C++、Python 和其他面向对象的语言。我正在尝试为许多不同类型的 Fyne 小部件注入某些常见行为,但我迷路了。例如,我需要在许多小部件上创建变体,例如 Label 和 Button,以允许我捕捉右键单击 (TapSecondary),以便我可以做一些特别的事情(通常,弹出一个菜单)。是的,我想要按钮和标签之类的弹出菜单;我什至想在输入框上拦截它(即使我必须以这种方式自己实现粘贴。)
我在网上找到了一个示例,该示例提供此示例以允许我拦截对标签的点击:
type TapLabel struct {
*widget.Label //composition
//function pointers to set to get events
OnTapped func() //`json:"-"`
OnTappedSecondary func() //`json:"-"` (what are these for anyway?)
}
func NewTapLabelWithStyle(text string, alignment fyne.TextAlign, style fyne.TextStyle,
tappedLeft func(), tappedRight func()) *TapLabel {
return &TapLabel{
widget.NewLabelWithStyle(text, alignment, style),
tappedLeft, tappedRight,
}
}
//somehow this catches right click. How?
func (mc *TapLabel) TappedSecondary(pe *fyne.PointEvent) {
if mc.OnTappedSecondary != nil {
mc.OnTappedSecondary()
} …Run Code Online (Sandbox Code Playgroud) 我想让我的代码更整洁,但是当我在 1 个文件中分离我经常使用的小部件时遇到问题
这是我的主要小部件
import 'package:a_tiket/Helpers/widget_helper.dart';
class LoginPage extends StatefulWidget {
@override
_LoginPageState createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
bool _isLoading = false;
var _message = '';
var _hasError = false;
@override
Widget build(BuildContext context) {
return
_isLoading ?
_loadingWidget(context)
:
Scaffold(
body: SingleChildScrollView(
child: Container(
),
],
),
)
)
)
;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 widget_helper.dart
Widget _loadingWidget (BuildContext context){
return Scaffold(
body: Center(
child: CircularProgressIndicator(
backgroundColor: ACCENT_COLOR,
valueColor: new AlwaysStoppedAnimation<Color>(PRIMARY_COLOR),
),
),
);
}
Run Code Online (Sandbox Code Playgroud)
问题是我有一些错误。我已经为 …
我有一个列表,当您单击 中的按钮时会出现该列表BottomNavigationBarItem。这是showMenu带有下面代码的列表。
但是我怎样才能得到这个列表中选择的值呢?
showMenu<int>(
context: context,
position: RelativeRect.fromLTRB(1000.0, 600.0, 0.0, 0.0),
items: <PopupMenuItem<int>>[
new PopupMenuItem<int>(child: const Text('Top 1'), value: 1),
new PopupMenuItem<int>(child: const Text('Top 2'), value: 2),
new PopupMenuItem<int>(child: const Text('Top 3'), value: 3),
new PopupMenuItem<int>(child: const Text('Top 4'), value: 4),
],
elevation: 8.0,
);
Run Code Online (Sandbox Code Playgroud) 我创建了一个CupertinoDatePicker小部件,初始值设置为一个变量。
当用户单击屏幕中的另一个小部件时,我想将选择器中的选定值更新为该变量值 - 但它不起作用(尽管CupertinoDatePicker小部件被重建)。
这是一个错误还是我做错了什么?
代码(可以复制粘贴到 dartPad 中):
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
final _time = DateTime.now();
int _min = 5;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatefulWidget {
@override
createState() => MyWidgetSate();
}
class MyWidgetSate extends State<MyWidget> { …Run Code Online (Sandbox Code Playgroud) 我有一个包含大量内容(如图像、文本等)的小部件,这使得它在 Flutter 应用程序中变得很重,但是当应用程序导航到具有复杂小部件的小部件时,该应用程序面临卡顿,因为小部件太大而无法使用瞬间加载,
我想显示简单的 lite 加载小部件,直到加载原始小部件,从而从应用程序中删除卡顿并启用小部件的延迟加载,
如何在颤振中实现这一目标?
编辑:- 明确地说,我没有从 Internet 加载任何数据,这不会导致延迟。为了从 Internet 加载数据,我们有FutureBuilder. 这里我的小部件本身很重,加载需要一些时间。
如何在加载主小部件时显示正在加载的小部件。
当我从主屏幕添加小部件时,我可以看到 Apple 创建的时钟应用程序有两个小WidgetFamily布局。
如何在时钟应用程序中制作两个小部件?
我看到我只能为每个WidgetFamily.
我一直在疑惑这个问题。我希望具有不同文本的 2 个按钮具有相同的宽度。
我通过使 ElevatedButton 成为 SizedBox 的子项来实现这一点,但我担心如果用户将默认字体大小设置为大,则 Button 标题文本将被剪裁。
我可以在 ElevatedButton 的样式属性上放置一个“minimumSize”:
style: ButtonStyle(minimumSize: ),
但我不知道如何设置 minimumSize,它想要这个:
{MaterialStateProperty minimumSize} 类型:MaterialStateProperty 按钮本身的最小尺寸。每个tapTargetSize 按钮所在的矩形的大小可能更大
我不知道如何设置 MaterialStateProperty,Android Studio 抱怨“无法实例化抽象类”。帮助!