目前使用typeAhead小部件来查询一些参数,在最近的 flutter 3 更新后我不断收到此错误
\nScrollable.of() was called with a context that does not contain a Scrollable widget.\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: 6.0,\n spreadRadius: 0.5,\n offset: Offset(0.7, 0.7),\n )\n ],\n ),\n child: Padding(\n padding: EdgeInsets.only(\n left: 25.0, top: 30.0, right: 25.0, bottom: 20.0),\n child: Column(\n children: [\n SizedBox(height: 5.0),\n Stack(\n children: [\n GestureDetector(\n onTap: () async {\n FocusScopeNode currentFocus =\n FocusScope.of(context);\n if (!currentFocus.hasPrimaryFocus) {\n currentFocus.unfocus();\n }\n dropOffTextEditingController.text.isNotEmpty\n ? Navigator.pop(context, true)\n : Navigator.pop(context, false);\n },\n child: Icon(Icons.arrow_back)),\n Center(\n child: Text(\n "Choose your drop off ",\n style: TextStyle(\n fontSize: 18.0, fontFamily: "Brand-Bold"),\n ),\n )\n ],\n ),\n SizedBox(height: 16.0),\n Row(\n children: [\n Image.asset("images/images/pickicon.png",\n height: 16.0, width: 16.0),\n SizedBox(width: 18.0),\n Expanded(\n child: Container(\n decoration: BoxDecoration(\n color: Colors.grey[400],\n borderRadius: BorderRadius.circular(5.0),\n ),\n child: Padding(\n padding: EdgeInsets.all(3.0),\n child: TextField(\n controller: pickUpTextEditingController,\n decoration: InputDecoration(\n hintText: "PickUp Location",\n fillColor: Colors.grey[400],\n filled: true,\n border: InputBorder.none,\n isDense: true,\n contentPadding: EdgeInsets.only(\n left: 11.0, top: 8.0, bottom: 8.0),\n ),\n ),\n ),\n ))\n ],\n ),\n SizedBox(height: 10.0),\n Row(\n children: [\n Image.asset("images/images/desticon.png",\n height: 16.0, width: 16.0),\n SizedBox(width: 18.0),\n Expanded(\n child: Container(\n //error points here\n decoration: BoxDecoration(\n color: Colors.grey[400],\n borderRadius: BorderRadius.circular(5.0),\n ),\n child: Padding(\n padding: EdgeInsets.all(3.0),\n child: TypeAheadField(\n textFieldConfiguration: TextFieldConfiguration(\n autofocus: false,\n maxLines: 1,\n controller: dropOffTextEditingController,\n decoration: InputDecoration(\n contentPadding: EdgeInsets.all(3),\n hintText: "Drop off Location",\n labelStyle: TextStyle(color: Colors.black),\n focusedBorder: OutlineInputBorder(\n borderSide: BorderSide(\n width: 1.3, color: Colors.black),\n ),\n border: OutlineInputBorder(\n borderSide: BorderSide(width: 0.8),\n ),\n ),\n ),\n suggestionsCallback: (pattern) async {\n //if (pattern.isNotEmpty)\n return await addressSuggestion(pattern);\n // return Future.value();\n },\n suggestionsBoxController:\n SuggestionsBoxController(),\n itemBuilder: (context, dynamic suggestion) {\n return ListTile(\n leading: Icon(Icons.location_on),\n title: Text((suggestion as SearchInfo)\n .address!\n .name!),\n subtitle:\n Text((suggestion).address!.country!),\n );\n },\n onSuggestionSelected: (dynamic suggestion) {\n print("xxx $suggestion");\n\n dropOffTextEditingController.text =\n (suggestion as SearchInfo).address!.name!;\n Provider.of<AppData>(context, listen: false)\n .updateDropOffLocationAddress(\n dropOffTextEditingController.text);\n //get the coordinates here\n GeoPoint? dropOffPoint = suggestion.point;\n print("Coordinates :$dropOffPoint");\n Provider.of<AppData>(context, listen: false)\n .updateDropOffGeoPoint(dropOffPoint);\n\n // Navigator.pop(\n // context, widget.showMapFunction(false));\n },\n ),\n ),\n ),\n ),\n ],\n ),\n\n SizedBox(height: 25.0),\n //create a button with yellow color\n Padding(\n padding: EdgeInsets.symmetric(horizontal: 16.0),\n child: ElevatedButton(\n onPressed: () {\n if (dropOffTextEditingController.text.isNotEmpty) {\n Navigator.pop(context, true);\n } else {\n Navigator.pop(context, false);\n }\n },\n child: Text(\n "Confirm Drop Off",\n style: TextStyle(fontSize: 18.0),\n ),\n style: ElevatedButton.styleFrom(\n foregroundColor: Colors.black,\n backgroundColor: Colors.yellow,\n shape: RoundedRectangleBorder(\n borderRadius: BorderRadius.circular(24.0),\n ),\n ),\n ),\n ),\n ],\n ),\n ),\n ),\n ],\n ),\n ),\n );\n }\n}\n\nRun Code Online (Sandbox Code Playgroud)\n这是完整的错误堆栈
\n\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90 Exception caught by widgets library \xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nThe following assertion was thrown building Container(bg: BoxDecoration(color: Color(0xffbdbdbd), borderRadius: BorderRadius.circular(5.0))):\nScrollable.of() was called with a context that does not contain a Scrollable widget.\n\nNo Scrollable widget ancestor could be found starting from the context that was passed to Scrollable.of(). This can happen because you are using a widget that looks for a Scrollable ancestor, but no such ancestor exists.\nThe context used was:\n TypeAheadField<SearchInfo>(dirty, state: _TypeAheadFieldState<SearchInfo>#d5046(lifecycle state: initialized))\nThe relevant error-causing widget was\nContainer\nlib/AllScreens/searchScreen.dart:140\nWhen the exception was thrown, this was the stack\n#0 Scrollable.of.<anonymous closure>\npackage:flutter/\xe2\x80\xa6/widgets/scrollable.dart:336\n#1 Scrollable.of\npackage:flutter/\xe2\x80\xa6/widgets/scrollable.dart:348\n#2 _TypeAheadFieldState.didChangeDependencies (package:flutter_typeahead/src/flutter_typeahead.dart:871:51)\nRun Code Online (Sandbox Code Playgroud)\n我该如何解决它?
\n小智 8
在最新的颤振中,我也遇到了这个错误。我将 TypeAhead 包装在 SingleChildScrollView 中,错误消失了。
SingleChildScrollView(
scrollDirection: Axis.vertical,
child: TypeAheadField(
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1732 次 |
| 最近记录: |