当 a很小时,如何防止 aNestedScrollView滚动?headerSliverBuilderbody
SliverAppBar在下面的示例中,如果不需要滚动,我想阻止可body滚动,因为它很小,即在这个示例中,视图根本不应该滚动,但它确实滚动了。
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
title: Text('Demo'),
expandedHeight: 300,
)
];
},
body: CustomScrollView(
slivers: <Widget>[
SliverToBoxAdapter(
child: Container(color: Colors.red, height: 100),
),
SliverToBoxAdapter(
child: Container(color: Colors.amber, height: 100),
),
],
),
));
}
}
Run Code Online (Sandbox Code Playgroud)
SliverAppBar这个问题可以通过将移入并完全CustomScrollView不使用 来解决。NestedScrollView但这对我来说不是一个解决方案,因为https://github.com/flutter/flutter/issues/12033基本上要求我使用NestedScrollView …
我有一个外部C库,我从C++链接到.该库定义了一个使用bool的结构,并为C包含了一个typedef.问题是这个typedef使用了一个int,所以(在我的平台上)而不是这个bool的大小为1个字节,它是4个字节大.
当我然后#include标头并在C++中创建结构时,bool(作为C++标准类型)的大小为1字节,因此结构具有完全不同的内存布局,当我通过它时会导致各种堆栈损坏到C库以便在那里修改它.
有没有办法在不修改外部库的情况下解决这种情况?我想用C++编译器而不是C编译器编译外部库会起作用,对吗?这是我解决这个问题的唯一机会吗?
lib.h:
#ifndef __cplusplus
typedef int bool;
#endif
typedef struct {
int numValues;
bool values[20];
} bArray;
int arraySize();
Run Code Online (Sandbox Code Playgroud)
lib.c:
#include "lib.h"
int arraySize() {
return sizeof(bArray);
}
Run Code Online (Sandbox Code Playgroud)
main.cpp中:
#include <iostream>
extern "C" {
#include "lib.h"
}
int main() {
std::cout << "size in c++: " << sizeof(bArray) << std::endl
<< "size in c : " << arraySize() << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
size in c++: 24
size in …Run Code Online (Sandbox Code Playgroud) 我无法正确地将嵌套的Kotlin类反序列化为Gson的正确类型.当我尝试反序列化相同的Java类时,它工作正常.
Java类:
package example;
import java.util.List;
import java.util.Map;
class TestJsonJava {
Map<String, List<Entry>> outer;
static class Entry {
String inner;
}
}
Run Code Online (Sandbox Code Playgroud)
Kotlin类:
package example
class TestJsonKotlin {
var outer: Map<String, List<Entry>>? = null
class Entry {
var inner: String? = null
}
}
Run Code Online (Sandbox Code Playgroud)
Kotlin主要:
package example
import com.google.gson.GsonBuilder
class Main {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val json = """
{
"outer": {
"keyA": [
{
"inner": "hello"
}
]
}
}
"""
val javaObject = …Run Code Online (Sandbox Code Playgroud) 我创建了一个自定义小部件,它监听ChangeNotifier并在通知程序触发时调用提供的回调。这用于在通知程序更改时执行一次性任务,例如导航。
一切似乎都工作正常,但偶然我偶然发现了这样的文档didUpdateWidget:
如果 State 的构建方法依赖于一个本身可以更改状态的对象,例如 ChangeNotifier 或 Stream,或者可以订阅以接收通知的其他对象,那么请确保在 initState、didUpdateWidget 和 dispose 中正确订阅和取消订阅:
- 在initState中,订阅该对象。
- 在 didUpdateWidget 中,如果更新的小部件配置需要替换对象,则取消订阅旧对象并订阅新对象。
- 在处置中,取消订阅该对象。
我处理第一点和最后一点的原因很明显,但是有人可以解释一下为什么我也必须实施吗didUpdateWidget?如果我不这样做,会出现什么问题?
额外问题:我还没有在我的应用程序中使用提供程序。它是否提供了开箱即用的类似功能?我找不到这样的东西。
我的小部件代码:
class ChangeNotifierListener<T extends ChangeNotifier> extends StatefulWidget {
final Widget child;
final T changeNotifier;
final void Function(T changeNotifier) onChanged;
ChangeNotifierListener(
{@required this.child,
@required this.changeNotifier,
@required this.onChanged});
@override
_ChangeNotifierListenerState createState() =>
_ChangeNotifierListenerState<T>();
}
class _ChangeNotifierListenerState<T extends ChangeNotifier>
extends State<ChangeNotifierListener<T>> {
VoidCallback _callback;
@override
Widget build(BuildContext context) => widget.child;
@override
void initState() {
super.initState();
_callback = …Run Code Online (Sandbox Code Playgroud)