我在Stack.
当键盘出现时,使用小部件Stack明确定位在底部的Positioned(bottom: 0)小部件将移至键盘顶部。
我怎样才能防止这种情况,并使一些小部件保持它们的位置,无论键盘是否在视图中?
例如,我希望“离线模式”标签位于键盘下方,而不是上方。
以下是此页面小部件外观的粗略草图:
Scaffold(
body: Stack(
children: [
LoginImage(),
LoginForm(),
ConnectedToInternet(),
],
),
)
Run Code Online (Sandbox Code Playgroud)
这是ConnectedToInternet小部件的样子 -
Positioned(
bottom: 0,
child: Container(
width: MediaQuery.of(context).size.width,
color: Colors.grey[900],
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Center(
child: Text(
"Offline mode",
style: TextStyle(color: Colors.white, fontSize: 12),
),
),
),
),
);
Run Code Online (Sandbox Code Playgroud) 在以下代码示例中,来自flutter docs:
class RandomWords extends StatefulWidget {
@override
createState() => RandomWordsState();
}
class RandomWordsState extends State<RandomWords> {
@override
Widget build(BuildContext context) {
final wordPair = WordPair.random();
return Text(wordPair.asPascalCase);
}
}
Run Code Online (Sandbox Code Playgroud)
State<RandomWords>语法究竟是什么意思?
我知道您可以使用以下语法为集合中包含的对象(例如列表)指定类型 - List <String>
但我无法理解背后的动机State<RandomWords>。
此外,如何RandomWordsState在RandomWords声明中引用并RandomWords在RandomWordsState声明中引用?这不应该导致循环引用错误或什么的吗?
我来自像 python 这样的动态类型语言,这对我来说看起来有点奇怪,有人可以指点我正确的地方吗?
当我尝试使用 pyenv 安装 python 版本时,出现以下错误:
$ pyenv install 3.5.7
Downloading Python-3.5.7.tar.xz...
-> https://www.python.org/ftp/python/3.5.7/Python-3.5.7.tar.xz
Installing Python-3.5.7...
BUILD FAILED (CentOS release 6.10 (Final) using python-build 1.2.13)
Inspect or clean up the working tree at /tmp/python-build.20190726132219.7116
Results logged to /tmp/python-build.20190726132219.7116.log
Last 10 log lines:
File "/tmp/python-build.20190726132219.7116/Python-3.5.7/Lib/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
File "/tmp/python-build.20190726132219.7116/Python-3.5.7/Lib/ensurepip/__init__.py", line 5, in <module>
import tempfile
File "/tmp/python-build.20190726132219.7116/Python-3.5.7/Lib/tempfile.py", line 45, in <module>
from random import Random as _Random
File "/tmp/python-build.20190726132219.7116/Python-3.5.7/Lib/random.py", line 41, in <module>
from math import log as _log, …Run Code Online (Sandbox Code Playgroud) 我有一个Parent小部件,其中包含一些状态,在这种情况下为计数器。
此状态通过Child其构造函数传递给窗口小部件。
现在,据我所知,Child每次都应该重新构建Parent,因为它处于的build()功能之内Parent,并且build()每次状态改变时都会被调用。
这个概念使我相信,INIT STATE!每次计数器更改时都会打印该消息。但是事实并非如此!
我本质上希望每当Child的构造函数参数(message)更改时,该钩子仅触发一次。
有人可以解释为什么会这样吗,以及使用上述“挂钩”的正确方法是什么?
class Child extends StatefulWidget {
final String message;
const Child(this.message, {Key key}) : super(key: key);
@override
_ChildState createState() => _ChildState();
}
class _ChildState extends State<Child> {
@override
void initState() {
print("INIT STATE!");
super.initState();
}
@override
Widget build(BuildContext context) {
return Center(
child: Text(widget.message),
);
}
}
class Parent extends StatefulWidget {
@override
_ParentState …Run Code Online (Sandbox Code Playgroud) 我想在同一个线程中运行 starlette 和 django 应用程序。
(将它们放在同一线程中可以实现它们之间的快速线程本地通信)。
考虑到 asgi 应用程序只是协程,我认为这在理论上应该是可能的asyncio.gather()。
我想出了一个小窍门来完成这项工作,但它有一些局限性。
from uvicorn import Server, Config
configs = [Config(app1, uds='app1.sock'), Config(app2, uds='app2.sock')]
coros = [Server(c).serve() for c in configs]
await asyncio.gather(*coros)
Run Code Online (Sandbox Code Playgroud)
reload和workers选项。INFO: Started server process [86066]
INFO: Waiting for application startup.
INFO: Started server process [86066]
INFO: Waiting for application startup.
INFO: ASGI 'lifespan' protocol appears unsupported.
INFO: Application startup complete.
INFO: Uvicorn running on unix socket app1.sock (Press CTRL+C to quit) …Run Code Online (Sandbox Code Playgroud) 在颤动中,rootBundle.load()给了我一个ByteData对象。
到底什么是ByteData?可以用来异步读取文件吗?
我真的不明白这背后的动机。
为什么不给我一个好的ol'File,或者更好的是资产的完整路径?
就我而言,我想从资产文件中异步读取字节,逐字节并写入新文件。(构建一个不会挂起 UI 的 XOR 解密东西)
这是我能做的最好的事情,但它却严重挂起了用户界面。
loadEncryptedPdf(fileName, secretKey, cacheDir) async {
final lenSecretKey = secretKey.length;
final encryptedByteData = await rootBundle.load('assets/$fileName');
final outputFilePath = cacheDir + '/' + fileName;
final outputFile = File(outputFilePath);
if (!await outputFile.exists()) {
Stream decrypter() async* {
// read bits from encryptedByteData, and stream the xor inverted bits
for (var index = 0; index < encryptedByteData.lengthInBytes; index++)
yield encryptedByteData.getUint8(index) ^
secretKey.codeUnitAt(index % lenSecretKey);
print('done!');
} …Run Code Online (Sandbox Code Playgroud) 我想创建一个 django 自定义用户模型,这样我就可以让我的用户使用电话或电子邮件登录。
这是我提出的解决方案
class ExtendedUser(AbstractBaseUser, PermissionsMixin):
phonenumber = PhoneNumberField(unique=True, null=True ..)
email = EmailField(unique=True, null=True ..)
...
USERNAME_FIELD = 'pk'
Run Code Online (Sandbox Code Playgroud)
所以现在登录时,我可以做这样的事情
if cleaned_data['phonenumber']:
u = User.objects.get(phonenumber=cleaned_data['phonenumber'])
authenticate(username=u.pk, password=cleaned_data['password'])
...
elif cleaned_data['email']:
...
Run Code Online (Sandbox Code Playgroud)
我不确定是否可以把USERNAME_FIELDas pk。如果不可能,我们可以轻松地放置 UUIDField。
建议的解决方案好吗?
Dart 的List结构似乎不支持负索引。这背后的原因是什么?我曾经使用过的所有其他语言都支持这一点。为什么 dart 决定排除这样一个基本结构?
以下代码 -
void main() {
List<String> x = ["foo", "bar"];
print(x[-1]);
}
Run Code Online (Sandbox Code Playgroud)
产生——
Uncaught exception:
RangeError (index): Index out of range: index must not be negative: -1
Run Code Online (Sandbox Code Playgroud)