- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在关注克隆 flutter uber 应用程序的教程,并不断收到错误消息:
** 错误:在此 MapSample 小部件上方找不到正确的提供程序**,我正在尝试将地理位置添加到我的应用程序中,我已经添加了我的和下面的教程源代码,我对 flutter 有点新,所以请原谅任何明显的问题,请,谢谢
这是我的源代码:
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:awesome/app_state.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle(
statusBarColor: Colors.red,
),
child: MaterialApp(
title: 'Flutter Google Maps Demo',
home: MapSample(),
)
);
}
}
class MapSample extends StatefulWidget {
@override
State < MapSample > createState() => MapSampleState();
}
class MapSampleState extends State < MapSample > {
Completer<GoogleMapController> _controller = Completer();
static final CameraPosition _kGooglePlex = CameraPosition(
target: LatLng(-13.9875107, 33.768144),
zoom: 14.4746,
);
static final CameraPosition _kLake = CameraPosition(
bearing: 192.8334901395799,
target: LatLng(37.43296265331129, -122.08832357078792),
tilt: 59.440717697143555,
zoom: 19.151926040649414);
@override
Widget build(BuildContext context) {
GoogleMapController mapController;
final appState = Provider.of<AppState>(context);
return new Scaffold(
backgroundColor: Colors.transparent,
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0.0,
iconTheme: new IconThemeData(color: Colors.black),
),
extendBodyBehindAppBar: true,
drawer: Drawer(
// Add a ListView to the drawer. This ensures the user can scroll
// through the options in the drawer if there isn't enough vertical
// space to fit everything.
child: ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text('Drawer Header'),
decoration: BoxDecoration(
color: Colors.black,
),
),
ListTile(
title: Text('Trip History'),
onTap: () {
// Update the state of the app
// ...
// Then close the drawer
Navigator.pop(context);
},
),
ListTile(
title: Text('Payment'),
onTap: () {
// Update the state of the app
// ...
// Then close the drawer
Navigator.pop(context);
},
),
ListTile(
title: Text('Settings'),
onTap: () {
// Update the state of the app
// ...
// Then close the drawer
Navigator.pop(context);
},
),
],
),
),
body:
Stack(
children: <Widget>[
GoogleMap(
mapToolbarEnabled: false,
mapType: MapType.normal,
initialCameraPosition: CameraPosition(
target: appState.initialPosition, zoom: 10.0),
zoomControlsEnabled: false,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
mapController = controller;
mapController.setMapStyle('[ { "featureType": "administrative", "elementType": "geometry.fill", "stylers": [ { "color": "#d6e2e6" } ] }, { "featureType": "administrative", "elementType": "geometry.stroke", "stylers": [ { "color": "#cfd4d5" } ] }, { "featureType": "administrative", "elementType": "labels.text.fill", "stylers": [ { "color": "#7492a8" } ] }, { "featureType": "administrative.neighborhood", "elementType": "labels.text.fill", "stylers": [ { "lightness": 25 } ] }, { "featureType": "landscape.man_made", "elementType": "geometry.fill", "stylers": [ { "color": "#dde2e3" } ] }, { "featureType": "landscape.man_made", "elementType": "geometry.stroke", "stylers": [ { "color": "#cfd4d5" } ] }, { "featureType": "landscape.natural", "elementType": "geometry.fill", "stylers": [ { "color": "#dde2e3" } ] }, { "featureType": "landscape.natural", "elementType": "labels.text.fill", "stylers": [ { "color": "#7492a8" } ] }, { "featureType": "landscape.natural.terrain", "stylers": [ { "visibility": "off" } ] }, { "featureType": "poi", "elementType": "geometry.fill", "stylers": [ { "color": "#dde2e3" } ] }, { "featureType": "poi", "elementType": "labels.icon", "stylers": [ { "saturation": -100 } ] }, { "featureType": "poi", "elementType": "labels.text.fill", "stylers": [ { "color": "#588ca4" } ] }, { "featureType": "poi.park", "elementType": "geometry.fill", "stylers": [ { "color": "#a9de83" } ] }, { "featureType": "poi.park", "elementType": "geometry.stroke", "stylers": [ { "color": "#bae6a1" } ] }, { "featureType": "poi.sports_complex", "elementType": "geometry.fill", "stylers": [ { "color": "#c6e8b3" } ] }, { "featureType": "poi.sports_complex", "elementType": "geometry.stroke", "stylers": [ { "color": "#bae6a1" } ] }, { "featureType": "road", "elementType": "labels.icon", "stylers": [ { "saturation": -45 }, { "lightness": 10 }, { "visibility": "on" } ] }, { "featureType": "road", "elementType": "labels.text.fill", "stylers": [ { "color": "#41626b" } ] }, { "featureType": "road.arterial", "elementType": "geometry.fill", "stylers": [ { "color": "#ffffff" } ] }, { "featureType": "road.highway", "elementType": "geometry.fill", "stylers": [ { "color": "#c1d1d6" } ] }, { "featureType": "road.highway", "elementType": "geometry.stroke", "stylers": [ { "color": "#a6b5bb" } ] }, { "featureType": "road.highway", "elementType": "labels.icon", "stylers": [ { "visibility": "on" } ] }, { "featureType": "road.highway.controlled_access", "elementType": "geometry.fill", "stylers": [ { "color": "#9fb6bd" } ] }, { "featureType": "road.local", "elementType": "geometry.fill", "stylers": [ { "color": "#ffffff" } ] }, { "featureType": "transit", "elementType": "labels.icon", "stylers": [ { "saturation": -70 } ] }, { "featureType": "transit.line", "elementType": "geometry.fill", "stylers": [ { "color": "#b4cbd4" } ] }, { "featureType": "transit.line", "elementType": "labels.text.fill", "stylers": [ { "color": "#588ca4" } ] }, { "featureType": "transit.station", "elementType": "labels.text.fill", "stylers": [ { "color": "#008cb5" } ] }, { "featureType": "transit.station.airport", "elementType": "geometry.fill", "stylers": [ { "saturation": -100 }, { "lightness": -5 } ] }, { "featureType": "water", "elementType": "geometry.fill", "stylers": [ { "color": "#a6cbe3" } ] } ]');
//_controller.setMapStyle('');
},
),
Positioned(
top: 105.0,
right: 30.0,
left: 40.0,
child: Container(
height: 55,
width: 70.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3.0),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey,
offset: Offset(1.0, 5.0),
blurRadius: 10,
spreadRadius: 3)
],
),
child: TextField(
cursorColor: Colors.black,
textInputAction: TextInputAction.go,
onSubmitted: (value) {
},
decoration: InputDecoration(
icon: Container(
margin: EdgeInsets.only(left: 20, top: 0,bottom: 6),
width: 10,
height: 10,
child: Icon(
Icons.local_taxi,
color: Colors.black,
),
),
hintText: "Hello, Where to?",
border: InputBorder.none,
contentPadding: EdgeInsets.only(left: 15.0, top: 10.0),
),
),
),
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: _goToTheLake,
child: Icon(Icons.gps_fixed),
foregroundColor: Colors.black,
backgroundColor: Colors.white,
),
);
}
Future < void > _goToTheLake() async {
final GoogleMapController controller = await _controller.future;
controller.animateCamera(CameraUpdate.newCameraPosition(_kLake));
}
}
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 5872): The following ProviderNotFoundException was thrown building MapSample(dirty, state:
I/flutter ( 5872): MapSampleState#6cfd9):
I/flutter ( 5872): Error: Could not find the correct Provider<AppState> above this MapSample Widget
I/flutter ( 5872):
I/flutter ( 5872): This likely happens because you used a `BuildContext` that does not include the provider
I/flutter ( 5872): of your choice. There are a few common scenarios:
I/flutter ( 5872):
I/flutter ( 5872): - The provider you are trying to read is in a different route.
I/flutter ( 5872):
I/flutter ( 5872): Providers are "scoped". So if you insert of provider inside a route, then
I/flutter ( 5872): other routes will not be able to access that provider.
I/flutter ( 5872):
I/flutter ( 5872): - You used a `BuildContext` that is an ancestor of the provider you are trying to read.
I/flutter ( 5872):
I/flutter ( 5872): Make sure that MapSample is under your MultiProvider/Provider<AppState>.
I/flutter ( 5872): This usually happen when you are creating a provider and trying to read it immediatly.
I/flutter ( 5872):
I/flutter ( 5872): For example, instead of:
I/flutter ( 5872):
I/flutter ( 5872): ```
I/flutter ( 5872): Widget build(BuildContext context) {
I/flutter ( 5872): return Provider<Example>(
I/flutter ( 5872): create: (_) => Example(),
I/flutter ( 5872): // Will throw a ProviderNotFoundError, because `context` is associated
I/flutter ( 5872): // to the widget that is the parent of `Provider<Example>`
I/flutter ( 5872): child: Text(context.watch<Example>()),
I/flutter ( 5872): ),
I/flutter ( 5872): }
I/flutter ( 5872): ```
I/flutter ( 5872):
I/flutter ( 5872): consider using `builder` like so:
I/flutter ( 5872):
I/flutter ( 5872): ```
I/flutter ( 5872): Widget build(BuildContext context) {
I/flutter ( 5872): return Provider<Example>(
I/flutter ( 5872): create: (_) => Example(),
I/flutter ( 5872): // we use `builder` to obtain a new `BuildContext` that has access to the provider
I/flutter ( 5872): builer: (context) {
I/flutter ( 5872): // No longer throws
I/flutter ( 5872): return Text(context.watch<Example>()),
I/flutter ( 5872): }
I/flutter ( 5872): ),
I/flutter ( 5872): }
I/flutter ( 5872): ```
( 5872):
I/flutter ( 5872): If none of these solutions work, consider asking for help on StackOverflow:
I/flutter ( 5872): https://stackoverflow.com/questions/tagged/flutter
I/flutter ( 5872):
I/flutter ( 5872): The relevant error-causing widget was:
I/flutter ( 5872): MapSample
package:awesome/main.dart:29
I/flutter ( 5872):
I/flutter ( 5872): When the exception was thrown, this was the stack:
I/flutter ( 5872): #0 Provider._inheritedElementOf
package:provider/src/provider.dart:258
I/flutter ( 5872): #1 Provider.of
package:provider/src/provider.dart:210
I/flutter ( 5872): #2 MapSampleState.build
package:awesome/main.dart:72
I/flutter ( 5872): #3 StatefulElement.build
package:flutter/…/widgets/framework.dart:4619
I/flutter ( 5872): #4 ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4502
I/flutter ( 5872): #5 StatefulElement.performRebuild
package:flutter/…/widgets/framework.dart:4675
I/flutter ( 5872): #6 Element.rebuild
package:flutter/…/widgets/framework.dart:4218
I/flutter ( 5872): #7 ComponentElement._firstBuild
package:flutter/…/widgets/framework.dart:4481
I/flutter ( 5872): #8 StatefulElement._firstBuild
package:flutter/…/widgets/framework.dart:4666
I/flutter ( 5872): #9 ComponentElement.mount
package:flutter/…/widgets/framework.dart:4476
I/flutter ( 5872): ... Normal element mounting (115 frames)
I/flutter ( 5872): #124 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3446
I/flutter ( 5872): #125 MultiChildRenderObjectElement.mount
package:flutter/…/widgets/framework.dart:5947
I/flutter ( 5872): ... Normal element mounting (256 frames)
I/flutter ( 5872): #381 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3446
I/flutter ( 5872): #382 Element.updateChild
package:flutter/…/widgets/framework.dart:3214
I/flutter ( 5872): #383 RenderObjectToWidgetElement._rebuild
package:flutter/…/widgets/binding.dart:1148
I/flutter ( 5872): #384 RenderObjectToWidgetElement.mount
package:flutter/…/widgets/binding.dart:1119
I/flutter ( 5872): #385 RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure>
package:flutter/…/widgets/binding.dart:1061
I/flutter ( 5872): #386 BuildOwner.buildScope
package:flutter/…/widgets/framework.dart:2607
I/flutter ( 5872): #387 RenderObjectToWidgetAdapter.attachToRenderTree
package:flutter/…/widgets/binding.dart:1060
I/flutter ( 5872): #388 WidgetsBinding.attachRootWidget
package:flutter/…/widgets/binding.dart:941
I/flutter ( 5872): #389 WidgetsBinding.scheduleAttachRootWidget.<anonymous closure>
package:flutter/…/widgets/binding.dart:922
I/flutter ( 5872): (elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)
I/flutter ( 5872):
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:provider/provider.dart';
import 'package:uber_clone/states/app_state.dart';
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(body: Map());
}
}
class Map extends StatefulWidget {
@override
_MapState createState() => _MapState();
}
class _MapState extends State<Map> {
@override
Widget build(BuildContext context) {
final appState = Provider.of<AppState>(context);
return SafeArea(
child: appState.initialPosition == null
? Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SpinKitRotatingCircle(
color: Colors.black,
size: 50.0,
)
],
),
SizedBox(height: 10,),
Visibility(
visible: appState.locationServiceActive == false,
child: Text("Please enable location services!", style: TextStyle(color: Colors.grey, fontSize: 18),),
)
],
)
)
: Stack(
children: <Widget>[
GoogleMap(
initialCameraPosition: CameraPosition(
target: appState.initialPosition, zoom: 10.0),
onMapCreated: appState.onCreated,
myLocationEnabled: true,
mapType: MapType.normal,
compassEnabled: true,
markers: appState.markers,
onCameraMove: appState.onCameraMove,
polylines: appState.polyLines,
),
Positioned(
top: 50.0,
right: 15.0,
left: 15.0,
child: Container(
height: 50.0,
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3.0),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey,
offset: Offset(1.0, 5.0),
blurRadius: 10,
spreadRadius: 3)
],
),
child: TextField(
cursorColor: Colors.black,
controller: appState.locationController,
decoration: InputDecoration(
icon: Container(
margin: EdgeInsets.only(left: 20, top: 5),
width: 10,
height: 10,
child: Icon(
Icons.location_on,
color: Colors.black,
),
),
hintText: "pick up",
border: InputBorder.none,
contentPadding: EdgeInsets.only(left: 15.0, top: 16.0),
),
),
),
),
Positioned(
top: 105.0,
right: 15.0,
left: 15.0,
child: Container(
height: 50.0,
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3.0),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey,
offset: Offset(1.0, 5.0),
blurRadius: 10,
spreadRadius: 3)
],
),
child: TextField(
cursorColor: Colors.black,
controller: appState.destinationController,
textInputAction: TextInputAction.go,
onSubmitted: (value) {
appState.sendRequest(value);
},
decoration: InputDecoration(
icon: Container(
margin: EdgeInsets.only(left: 20, top: 5),
width: 10,
height: 10,
child: Icon(
Icons.local_taxi,
color: Colors.black,
),
),
hintText: "destination?",
border: InputBorder.none,
contentPadding: EdgeInsets.only(left: 15.0, top: 16.0),
),
),
),
),
// Positioned(
// top: 40,
// right: 10,
// child: FloatingActionButton(onPressed: _onAddMarkerPressed,
// tooltip: "aadd marker",
// backgroundColor: black,
// child: Icon(Icons.add_location, color: white,),
// ),
// )
],
),
);
}
}
最佳答案
您必须在使用前调用提供商。您可以使用这样的多提供商。
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider<AppState>(
create: (_) => AppState()),
],
child: MaterialApp(
...
),
);
}
关于android - 在此 MapSample 小部件上方找不到正确的 Provider<AppState>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62371625/
我已经为我的 Python App Engine 应用程序启用了 appstats,我可以在/_ah/stats/url 下本地访问它,但是当我部署应用程序并在 UI 中访问我的应用程序下的 apps
观看后Guido's Google IO talk并听到提到它可以扩展(从而提供记录您自己的事件的仪器机制),我仍然不知道如何做到这一点。 这些函数都是用于处理 RPC,而不仅仅是昂贵的函数(或包装器
我遇到性能问题,但我不知道它来自哪里。 createLogoutURL 和第一个数据存储查询之间的差距是巨大的......它在以下代码段落之间: loginInfo.setLogoutUrl(user
我在 gae 上有一个 Flask 应用程序,它工作正常。我正在尝试添加 Appstats 支持,但一旦启用它,我就会陷入僵局。 当我尝试使用登录的用户 ndb 模型设置 werkzeug Local
我正在使用此处记录的 Appstats: http://code.google.com/appengine/docs/python/tools/appstats.html 它工作正常,但现在每个请求都
答案here通过 Widget 显示正在退出的应用程序。 我想知道,如果我可以退出 initPlatformState(){...} 特别针对我的情况,我在 initPlatformState(){.
当我的 Activity 关闭时,我将应用程序状态数据序列化到文件中,以便在应用程序被系统终止时让我有机会重新加载状态。 这种方法(保存和恢复状态)效果很好。但是,有时,当进程被终止时,根据要加载的数
我正在本地分析我的应用程序(使用开发服务器)以获取有关 GAE 工作原理的更多信息。我的测试正在比较常见的完整实体查询和投影查询。在我的测试中,两个查询都执行相同的查询,但投影指定了 2 个属性。测试
取these stats来自post以 App Engine 博客为例: real = 107ms cpu = 141ms api = 388ms overhead = 1ms RPC Tota
我在 react-native 上使用 AppState,所以我可以知道我的应用程序何时处于事件状态或在后台。我可以使用 AppState 获得事件状态,但我无法获得后台状态,因为当我将应用程序加倍以
如何触发 AppState 监听器来检查它是否正常工作? AppState.addEventListener('change', (nextAppState) => { console.log('t
我一直在关注克隆 flutter uber 应用程序的教程,并不断收到错误消息: ** 错误:在此 MapSample 小部件上方找不到正确的提供程序**,我正在尝试将地理位置添加到我的应用程序中,我
我正在使用GWT和Google API引擎的项目中工作。该项目没有依赖项管理器,因此我们正在实现Gradle。 问题是我们在执行过程中遇到一些错误。与Appstats基本相关。 这是错误: FAILE
在分析 Appstats 跟踪 datastore_v3.Get 调用时,了解正在从数据存储区检索哪些实体将非常有帮助。是否有隐藏的配置标志可以启用此功能? 我尝试在 appengine_config
我有一些代码想要在我的应用程序从后台恢复时运行。为此,我使用 AppState.addEventListener() 注册一个事件。 const handleAppStateChange = ()
我在获取 Appstats 时遇到问题才能正常工作。使用/appstats 或/appstats/stats 会陷入无限循环,不断重定向回/appstats/stats。这会导致 404 错误,指出页
我正在使用 Google AppEngine (python),我的应用程序日志使用 UTC。然而,我的 AppStats 正在返回看起来像 PST 的内容。 如何将 AppStats 使用的时区更改
我们的应用程序每秒处理几十个请求,其中一小部分比其他请求花费更多的时间来处理。我们有兴趣“剖析”那些缓慢的请求,但是 appstats 似乎只保留已处理请求的小窗口,因此我们感兴趣的请求很快就会消失。
我的 java appengine 应用程序中有几个 servlet,它们在内存中进行排序并按秒顺序完成。这些完全没有错误。 但是,我最近为 appengine 启用了 appstats 并开始收到以
如果我尝试按照文档的建议将命名空间作为第一个参数传递,我会得到“undefined”作为值(“test”在模块定义中设置) ...mapState('guest', { email: stat
我是一名优秀的程序员,十分优秀!