我SelectableText在我的网站中使用小部件。当我用鼠标选择文本时,取消选择的唯一方法是单击SelectableText。
单击屏幕上的任意位置时如何取消选择文本?这是网站的经典行为。
class MainPageWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const Scaffold(
body: SelectableText("This is a selectable text"),
);
}
}
Run Code Online (Sandbox Code Playgroud)
但如果我删除它Scaffold以保留SelectableText唯一的,它就有效。但是如果没有 .txt 文件,文本将以一种奇怪的方式显示Scaffold。
我在 Ubuntu 20.04 上使用 Google Chrome。
我只是想知道是否可以重写toStringdart 中的方法,这就是我所拥有的:
enum Style{italic, bold, underline}
Style.italic.toString()
// print Style.italic, but I want it to be just italic
Run Code Online (Sandbox Code Playgroud) flutter run --release\nLaunching lib/main.dart on motorola one vision in release mode...\nRunning Gradle task 'assembleRelease'... 3.6s\n\xe2\x9c\x93 Built build/app/outputs/flutter-apk/app-release.apk (6.6MB).\n\nFlutter run key commands.\nh List all available interactive commands.\nc Clear the screen\nq Quit (terminate the application on the device).\nD/FlutterBluePlugin(20889): onAttachedToEngine\nD/FlutterBluePlugin(20889): setup\nD/FlutterBluePlugin(20889): onAttachedToActivity\nE/flutter (20889): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(startScan, Field androidScanMode_ for j.e0 not found. Known fields are [private int j.e0.h, private k.b0$i j.e0.i, private boolean j.e0.j, private static final j.e0 j.e0.k, private static volatile k.a1 j.e0.l], java.lang.RuntimeException: Field androidScanMode_ for j.e0 not found. Known …Run Code Online (Sandbox Code Playgroud) 我是一个新的 Flutter 学习者。我正在尝试使用相同的代码库编写移动和网络应用程序。我想知道我应该在哪里使用MediaQuery.of(context).size以及在哪里LayouBuilder( BoxConstraints constraints)?
还想知道在一个大型应用程序中仅使用其中一个是否有效,或者它们是相互补充的?
编辑:我也喜欢更多地了解这些方法的行为
用户放大/缩小屏幕
用户更改移动应用程序上的屏幕方向或桌面计算机上的网络浏览器大小
这两种情况哪种方法更适合呢?
mpmediaquery responsive-design flutter flutter-layoutbuilder
我有 showModalBottomSheet 来获取 OTP 代码,如果用户输入错误的代码,我想显示 SnackBar。所以,我用了这个方法,
showModalBottomSheet(
isScrollControlled: true,
isDismissible: false,
context: context,
builder: (context) {
return SafeArea(
child: Stack(
alignment: Alignment.topCenter,
clipBehavior: Clip.none,
children: [
Column(
children: [
Container(
padding: const EdgeInsets.symmetric(
horizontal: 30, vertical: 0),
child: Column(children: [
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 50),
child: TextField(
controller: codeController,
keyboardType: TextInputType.number,
),
),
const SizedBox(
height: 5,
),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 50),
child: CustomButton(
onTap: () async {
if (codeController.text.length == 6) {
try {
PhoneAuthCredential credential =
PhoneAuthProvider.credential( …Run Code Online (Sandbox Code Playgroud) 我正在尝试删除 的默认边距persistentFooterButtons,但我找不到它,因为它收到了一个小部件列表。
我正在使用extendBody: true中Scaffold。
持久页脚按钮边距
\n
persistentFooterButtons: [\n Container(\n color: const Color.fromRGBO(240, 240, 240, 0.9),\n width: double.infinity,\n child: Padding(\n padding: const EdgeInsets.symmetric(horizontal: 2, vertical: 2),\n child: Row(\n children: [\n Expanded(\n child: GestureDetector(\n child: Column(\n children: [\n const Image(\n image: AssetImage(\'assets/images/home.png\'),\n height: 35,\n ),\n Text(\n "In\xc3\xadcio",\n style: TextStyle(\n fontSize: 10,\n color: Theme.of(context).primaryColor,\n ),\n ),\n ],\n ),\n ),\n ),\n ],\n ),\n ),\n )\n ],\nRun Code Online (Sandbox Code Playgroud)\n 我有一个带有图标的提升按钮,该图标使用 放置在文本左侧ElevatedButton.icon。我真正想要的是将图标放置在文本的右侧。我该如何做我的代码:
ElevatedButton.icon(
onPressed: onPressed,
icon:Icon(icon,
color: color != null ? color : null,
size: getIconSize(),
),
label: Text(label),
style: buttonStyle);
Run Code Online (Sandbox Code Playgroud)
外观如何:
我想要的是 :
下一页->
我是新来的扑腾。我正在创建一个登录页面。但现在,当我将“记住我”和“忘记密码”按钮添加到行小部件中以显示在一行中时,我的代码中出现以下错误。如何解决这个问题。我附上了完整的代码和用户界面供您参考。login_screen 完整 dart 代码, login_screen UI 图像
RenderBox 未布局:_RenderListTile#c9c23 relayoutBoundary=up24 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE 'package:flutter/src/rendering/box.dart':断言失败:第 1982 行 pos 12:'hasSize'
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Form(
key: _formKey,
autovalidateMode: AutovalidateMode.disabled,
child: Container(
margin: const EdgeInsets.all(20.0),
child: Column(
children: [
SizedBox(
height: 40,
),
TextFormField(
controller: emailEditingController,
enabled: true,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30.0),
),
hintText: "Email/ Username",
hintStyle: TextStyle(
color: textGrey, fontFamily: "Dubai", fontSize: 14),
),
validator: (String? UserName) {
if (UserName != null && UserName.isEmpty) { …Run Code Online (Sandbox Code Playgroud) 我想创建一个可调整大小的容器,用户可以使用水平拖动来调整其大小。
这个 Gif 可以解释这个要求:
我尝试了 GestureDetector.horizontal 拖动,但结果相差甚远:
Container(
color: primary,
width: size.width,
height: 40,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
onHorizontalDragUpdate: (details) {
final double newWidth;
if (details.delta.dx > 0) {
// movement in positive direction
final newWidth = size.width + 1;
print(newWidth);
final updatedSize = Size(newWidth, size.height);
setState(() {
size = updatedSize;
});
} else {
// movement in negative direction
final newWidth = math.max(size.width - 1, 5).toDouble();
print(newWidth);
final updatedSize = Size(newWidth, size.height);
setState(() {
size = …Run Code Online (Sandbox Code Playgroud) 在我的 flutter 应用程序中,我需要一个布局,如果所有小部件对于屏幕来说都太长,我可以滚动,所以我添加了一个 SingleChildScrollView。但是,如果小部件较小并留有大量空间,我希望将最后一行固定到屏幕底部,并在最后两项之间留出空白。所以我添加了一个垫片来帮助解决这个问题。
然而,这会导致错误,因为 SingleChildScrollView 不喜欢 Spacer。我已经尝试了我所知道的一切,但我找不到满足这两个条件且没有错误的布局。有人可以建议一个解决方案吗?
下面的代码 - 您可能需要更改容器的大小(或数量)才能在您的设备上演示该问题。
class _TestMain extends State<TestMain> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
child: SingleChildScrollView(
child: Column(
children: [
Container(
color: Colors.blue,
height: 100,
),
Container(
color: Colors.yellow,
height: 100,
),
Container(
color: Colors.green,
height: 100,
),
Container(
color: Colors.pink,
height: 100,
),
// comment out these four containers to demonstrate issue
Container(
color: Colors.blue,
height: 100,
),
Container(
color: Colors.yellow,
height: 100,
),
Container(
color: …Run Code Online (Sandbox Code Playgroud)