小编Pan*_*nam的帖子

Flutter 中的 GlobalKeys 和 key 到底是什么?

我已经尝试学习这个概念一个多月了,但我似乎无法用更简单的术语弄清楚 GlobalKeys 和各种类型的密钥到底是什么,它只是用于表单验证器还是有更多用途,有youtube 上也没有清晰的基本示例,或者可能在某处有一本书?

在基本的 flutter 应用程序中


void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0; …
Run Code Online (Sandbox Code Playgroud)

dart flutter

12
推荐指数
2
解决办法
1万
查看次数

使用不包含 Scrollable 小部件的上下文调用 Scrollable.of()

目前使用typeAhead小部件来查询一些参数,在最近的 flutter 3 更新后我不断收到此错误

\n

Scrollable.of() was called with a context that does not contain a Scrollable widget.\n这是错误所指向的小部件

\n
@override\n  @mustCallSuper\n  Widget build(BuildContext context) {\n    String placeAddress =\n        Provider.of<AppData>(context).pickUpLocation!.placeName ?? "";\n    pickUpTextEditingController.text = placeAddress;\n\n    return WillPopScope(\n      onWillPop: () {\n        if (dropOffTextEditingController.text.isNotEmpty) {\n          Navigator.pop(context, true);\n          return Future.value(true);\n        } else {\n          Navigator.pop(context, false);\n          return Future.value(false);\n        }\n    \n      },\n      child: Scaffold(\n        resizeToAvoidBottomInset: false,\n        body: Stack(\n          children: [\n            Container(\n              height: 280.0,\n              decoration: BoxDecoration(\n                color: Colors.white,\n                boxShadow: [\n                  BoxShadow(\n                    color: Colors.black,\n                    blurRadius: …
Run Code Online (Sandbox Code Playgroud)

dart flutter

3
推荐指数
1
解决办法
1732
查看次数

flutter中的operator ==方法是什么?

根据文档https://api.flutter.dev/flutter/painting/BoxShadow/operator_equals.html其实现如下

@override
bool operator ==(Object other) {
  if (identical(this, other))
    return true;
  if (other.runtimeType != runtimeType)
    return false;
  return other is BoxShadow
      && other.color == color
      && other.offset == offset
      && other.blurRadius == blurRadius
      && other.spreadRadius == spreadRadius;
}
Run Code Online (Sandbox Code Playgroud)

hashcode属性如下

@override
int get hashCode => hashValues(color, offset, blurRadius, spreadRadius);
Run Code Online (Sandbox Code Playgroud)

这实际上有什么作用?它有什么用处?代码中opeartorruntimeType、等的用途是什么?hasCode如果您也能以更简单的方式提供一些示例,那就太好了。

dart flutter

2
推荐指数
1
解决办法
4647
查看次数

标签 统计

dart ×3

flutter ×3