- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在下面的代码中使用了 3 个文本字段,我验证了每条消息,当我点击凸起的按钮时它会显示错误消息,但在那之后当我输入值时它仍然会在屏幕有人可以帮助我。
这是我的代码:
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:toast/toast.dart';
class AddPromo extends StatefulWidget {
@override
_AddPromoState createState() => _AddPromoState();
}
class _AddPromoState extends State<AddPromo> {
final databaseReference = Firestore.instance;
var priceReductionController = TextEditingController();
var perReductionController = TextEditingController();
var promocodeController = TextEditingController();
bool _validate = false;
bool _validatePrice = false;
bool _validatePerReduction = false;
bool _validatePromoCode = false;
@override
void dispose() {
priceReductionController.dispose();
perReductionController.dispose();
promocodeController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Add promo"),backgroundColor: Colors.indigo,),
body: Column(
children : <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
keyboardType: TextInputType.number,
controller: priceReductionController,
decoration: InputDecoration(labelText: "Price Reduction",
errorText: _validatePrice ? 'value cant be empty' : null,
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(0.0),
),
borderSide: new BorderSide(
color: Colors.indigo,
width: 1.0,
),
)),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
keyboardType: TextInputType.number,
controller: perReductionController,
decoration: new InputDecoration(labelText: "Percentage Reduction",
errorText: _validatePerReduction ? 'value cant be empty' : null,
border: new OutlineInputBorder(
borderSide: new BorderSide(color: Colors.indigo)
)),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
controller: promocodeController,
decoration: InputDecoration(labelText: "Promo code",
errorText: _validatePromoCode ? 'value cant be empty' : null,
border: OutlineInputBorder(
)),
),
),
Spacer(flex:2),
Container(
width: 350,
child: RaisedButton(
color: Colors.indigo,
onPressed: () async {
//perform the validation first
setState(() {
priceReductionController.text.isEmpty
? _validatePrice = true
: _validatePrice = false;
perReductionController.text.isEmpty
? _validatePerReduction = true
: _validatePerReduction = false;
promocodeController.text.isEmpty
? _validatePromoCode = true
: _validatePromoCode = false;
});
//verify that all are fine
if (_validatePrice || _validatePromoCode || _validatePerReduction) {
return;
}
//store the values into the database
DocumentReference ref = await databaseReference.collection("promo_codes")
.add({
'percentage_reduction': perReductionController.text,
'price_reduction': priceReductionController.text,
'promo_code': promocodeController.text,
});
Scaffold.of(context)
.showSnackBar(SnackBar(content: Text("Promo saved.")))
.closed
.then((reason) {
// snackbar is now closed
});
I/OpenGLRenderer( 6519): Initialized EGL, version 1.4
D/OpenGLRenderer( 6519): Swap behavior 2
W/IInputConnectionWrapper( 6519): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 6519): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 6519): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 6519): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 6519): endBatchEdit on inactive InputConnection
W/BiChannelGoogleApi( 6519): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzak@172de21
W/DynamiteModule( 6519): Local module descriptor class for com.google.firebase.auth not found.
I/FirebaseAuth( 6519): [FirebaseAuth:] Loading module via FirebaseOptions.
I/FirebaseAuth( 6519): [FirebaseAuth:] Preparing to create service connection to gms implementation
D/FirebaseAuth( 6519): Notifying id token listeners about user ( 7pkcfF4j1yVLCnMUn9BE0uvjL2s1 ).
I/flutter ( 6519): AsyncSnapshot<String>(ConnectionState.waiting, null, null)
W/DynamiteModule( 6519): Local module descriptor class for providerinstaller not found.
I/DynamiteModule( 6519): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller( 6519): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
I/dminbookingpag( 6519): The ClassLoaderContext is a special shared library.
I/chatty ( 6519): uid=10296(m20zero.adminbookingpage) AsyncTask #2 identical 1 line
I/dminbookingpag( 6519): The ClassLoaderContext is a special shared library.
V/NativeCrypto( 6519): Registering com/google/android/gms/org/conscrypt/NativeCrypto's 286 native methods...
W/dminbookingpag( 6519): Accessing hidden field Ljava/nio/Buffer;->address:J (light greylist, reflection)
W/dminbookingpag( 6519): Accessing hidden method Ljava/security/spec/ECParameterSpec;->getCurveName()Ljava/lang/String; (light greylist, reflection)
D/NetworkSecurityConfig( 6519): No Network Security Config specified, using platform default
I/ProviderInstaller( 6519): Installed default security provider GmsCore_OpenSSL
W/dminbookingpag( 6519): Accessing hidden field Ljava/net/Socket;->impl:Ljava/net/SocketImpl; (light greylist, reflection)
W/dminbookingpag( 6519): Accessing hidden method Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard; (light greylist, linking)
W/dminbookingpag( 6519): Accessing hidden method Ldalvik/system/CloseGuard;->open(Ljava/lang/String;)V (light greylist, linking)
W/dminbookingpag( 6519): Accessing hidden field Ljava/io/FileDescriptor;->descriptor:I (light greylist, JNI)
W/dminbookingpag( 6519): Accessing hidden method Ljava/security/spec/ECParameterSpec;->setCurveName(Ljava/lang/String;)V (light greylist, reflection)
W/dminbookingpag( 6519): Accessing hidden method Ldalvik/system/BlockGuard;->getThreadPolicy()Ldalvik/system/BlockGuard$Policy; (light greylist, linking)
W/dminbookingpag( 6519): Accessing hidden method Ldalvik/system/BlockGuard$Policy;->onNetwork()V (light greylist, linking)
I/flutter ( 6519): 21
I/flutter ( 6519): AsyncSnapshot<String>(ConnectionState.done, 21, null)
W/IInputConnectionWrapper( 6519): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 6519): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 6519): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 6519): requestCursorAnchorInfo on inactive InputConnection
E/flutter ( 6519): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Scaffold.of() called with a context that does not contain a Scaffold.
E/flutter ( 6519): No Scaffold ancestor could be found starting from the context that was passed to Scaffold.of(). This usually happens when the context provided is from the same StatefulWidget as that whose build function actually creates the Scaffold widget being sought.
E/flutter ( 6519): There are several ways to avoid this problem. The simplest is to use a Builder to get a context that is "under" the Scaffold. For an example of this, please see the documentation for Scaffold.of():
E/flutter ( 6519): https://api.flutter.dev/flutter/material/Scaffold/of.html
E/flutter ( 6519): A more efficient solution is to split your build function into several widgets. This introduces a new context from which you can obtain the Scaffold. In this solution, you would have an outer widget that creates the Scaffold populated by instances of your new inner widgets, and then in these inner widgets you would use Scaffold.of().
E/flutter ( 6519): A less elegant but more expedient solution is assign a GlobalKey to the Scaffold, then use the key.currentState property to obtain the ScaffoldState rather than using the Scaffold.of() function.
E/flutter ( 6519): The context used was:
E/flutter ( 6519): AddPromo
E/flutter ( 6519): #0 Scaffold.of (package:flutter/src/material/scaffold.dart:1316:5)
E/flutter ( 6519): #1 _AddPromoState.build.<anonymous closure> (package:adminbookingpage/screens/addPromo.dart:119:24)
E/flutter ( 6519): <asynchronous suspension>
E/flutter ( 6519): #2 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:706:14)
E/flutter ( 6519): #3 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:789:36)
E/flutter ( 6519): #4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter ( 6519): #5 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:486:11)
E/flutter ( 6519): #6 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:264:5)
E/flutter ( 6519): #7 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:199:7)
E/flutter ( 6519): #8 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:467:9)
E/flutter ( 6519): #9 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76:12)
E/flutter ( 6519): #10 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:117:9)
E/flutter ( 6519): #11 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8)
E/flutter ( 6519): #12 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:115:18)
E/flutter ( 6519): #13 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:7)
E/flutter ( 6519): #14 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter ( 6519): #15 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter ( 6519): #16 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter ( 6519): #17 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter ( 6519): #18 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter ( 6519): #19 _rootRunUnary (dart:async/zone.dart:1138:13)
E/flutter ( 6519): #20 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter ( 6519): #21 _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
E/flutter ( 6519): #22 _invoke1 (dart:ui/hooks.dart:273:10)
E/flutter ( 6519): #23 _dispatchPointerDataPacket (dart:ui/hooks.dart:182:5)
最佳答案
BlockquoteForm(key: _formKey,autovalidateMode: AutovalidateMode.onUserInteraction)
您应该将 Autovalidate Mode.onUserInteraction
属性添加到表单小部件中,这样您就可以在每次用户更改某些值时验证表单。
关于firebase - 即使在插入值后文本字段仍显示错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59316942/
表架构 DROP TABLE bla; CREATE TABLE bla (id INTEGER, city INTEGER, year_ INTEGER, month_ INTEGER, val I
我需要拆分字符串/或从具有以下结构的字符串中获取更容易的子字符串。 字符串将来自 window.location.pathname 或 window.location.href,看起来像 text/n
每当将对象添加到数组中时,我都会尝试更新 TextView ,并在 TextView 中显示该文本,如下所示: "object 1" "object 2" 问题是,每次将新对象添加到数组时,它都会覆盖
我目前正在寻找使用 Java 读取网站可见文本并将其存储为纯文本字符串的方法。 换句话说,我想转换成这样: Hello stupid World进入“ Hello World ” 或者类似的东西 Un
我正在尝试以文本和 HTML 格式发送电子邮件,但无法正确发送正确的 header 。特别是,我想设置 Content-Type header ,但我找不到如何为 html 和文本部分单独设置它。 这
我尝试了上面的代码,但我无法绑定(bind)文本,我怎样才能将资源内部文本 bloc
我刚刚完成了 Space Shooter 教程,由于没有 GUIText 对象,所以我创建了 UI.Text 对象并进行了相应的编码。它在统一播放器中有效,但在构建 Web 应用程序后无效。我花了一段
我有这个代码: - (IBAction)setButtonPressed:(id)sender { NSUserDefaults *sharedDefaults = [[NSUserDefau
抱歉标题含糊不清,但我想不出我想在标题中做什么。无论如何,对于图像上的文本,我使用了 JLabel 文本并将其添加到图标中。 JLabel icon = new JLabel(new Imag
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我在将 Twitter 嵌入到我从 HTML 5 转换的 wordpress 运行网站时遇到问题。 我遇到的问题是推文不是我的自定义字体... 这是我无法使用任何 css 定位的 HTML 代码,我正
我正在尝试找到解决由于使用以下形式的代码而导致的冗余字符串连接问题的最佳方法: logger.debug("Entering loop, arg is: " + arg) // @1 在大多数情况下,
我写了这个测试 @Test public void removeRequestTextFromRouteError() throws Exception { String input = "F
我目前正在创建一个正则表达式来拆分所有匹配以下格式的字符串:&[文本],并且需要获取文本。字符串可能类似于:something &[text] &[text] everything &[text] 等
有没有办法将标题文本从一个词变形为另一个词,同时保留两个词中使用的字母?我看过的许多 css 文本动画大多是视觉的,很少有旋转整个单词的。 我想要做的是从一个词过渡,例如“BEACH”到“CHANGE
总结matplotlib绘图如何设置坐标轴刻度大小和刻度。 上代码: ?
我在容器 (1) 中创建了容器 (2)。你能帮忙如何向容器(1)添加文本吗?下面是我的代码 return Scaffold( body: Padding( padding: c
我似乎找不到任何人或任何人这样做过。我试图限制我们使用的图像数量,并想创建一个带有渐变作为其“颜色”的文本,并在其周围设置渐变轮廓/描边 到目前为止,我还没有看到任何将两者结合在一起的东西。 我可以自
我正在为视频游戏暗黑破坏神 2 使用 discord.py 构建一个不和谐机器人。其中一项功能要求机器人从暗黑破坏神 2 屏幕截图中提取项目的名称和属性。我目前正在为此使用 pytesseract,但
我很难弄清楚如何旋转 strip.text theme 中的属性来自 ggplot2 .我使用的是 R 版本 3.4.2 和 ggplot2 版本 2.2.1。 以下是 MWE 的数据。 > dput
我是一名优秀的程序员,十分优秀!