#flutter #flutter-layout #flutter-dependencies #flutter-test
Вопрос:
У меня есть ошибка в приведенном ниже коде флаттера, когда я запускаю код, у меня возникает следующая ошибка, из-за чего это происходит? Я заявляю, что переключился на нулевую безопасность flutter 2. ошибка возникает при отображении виджета, с чем это может быть связано? код выполняет отображение карты с серией прокрутки виджетов местоположений на ней в определенной позиции, как можно решить эту проблему?
Ошибка:
Another exception was thrown: Stack Overflow
Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line
4269 pos 14: 'owner!._debugCurrentBuildTarget == this': is not true.
Код Флаттера:
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
class Coffee {
final String shopName;
final String address;
final String description;
final String thumbNail;
final LatLng locationCoords;
Coffee(
{required this.shopName,
required this.address,
required this.description,
required this.thumbNail,
required this.locationCoords});
}
final List<Coffee> coffeeShops = [
Coffee(
shopName: 'Stumptown Coffee Roasters',
address: '18 W 29th St',
description:
'Coffee bar chain offering house-roasted direct-trade coffee, along with brewing gear amp; whole beans',
locationCoords: LatLng(40.745803, -73.988213),
thumbNail:
'https://lh5.googleusercontent.com/p/AF1QipNNzoa4RVMeOisc0vQ5m3Z7aKet5353lu0Aah0a=w90-h90-n-k-no'),
Coffee(
shopName: 'Andrews Coffee Shop',
address: '463 7th Ave',
description:
'All-day American comfort eats in a basic diner-style setting',
locationCoords: LatLng(40.751908, -73.989804),
thumbNail:
'https://lh5.googleusercontent.com/p/AF1QipOfv3DSTkjsgvwCsUe_flDr4DBXneEVR1hWQCvR=w90-h90-n-k-no'),
Coffee(
shopName: 'Third Rail Coffee',
address: '240 Sullivan St',
description:
'Small spot draws serious caffeine lovers with wide selection of brews amp; baked goods.',
locationCoords: LatLng(40.730148, -73.999639),
thumbNail:
'https://lh5.googleusercontent.com/p/AF1QipPGoxAP7eK6C44vSIx4SdhXdp78qiZz2qKp8-o1=w90-h90-n-k-no'),
Coffee(
shopName: 'Hi-Collar',
address: '214 E 10th St',
description:
'Snazzy, compact Japanese cafe showcasing high-end coffee amp; sandwiches, plus sake amp; beer at night.',
locationCoords: LatLng(40.729515, -73.985927),
thumbNail:
'https://lh5.googleusercontent.com/p/AF1QipNhygtMc1wNzN4n6txZLzIhgJ-QZ044R4axyFZX=w90-h90-n-k-no'),
Coffee(
shopName: 'Everyman Espresso',
address: '301 W Broadway',
description:
'Compact coffee amp; espresso bar turning out drinks made from direct-trade beans in a low-key setting.',
locationCoords: LatLng(40.721622, -74.004308),
thumbNail:
'https://lh5.googleusercontent.com/p/AF1QipOMNvnrTlesBJwUcVVFBqVF-KnMVlJMi7_uU6lZ=w90-h90-n-k-no')
];
class MapsScreenPage extends StatefulWidget {
const MapsScreenPage({Key? key}) : super(key: key);
@override
_MapsScreenPageState createState() => _MapsScreenPageState();
}
class _MapsScreenPageState extends State<MapsScreenPage> {
GoogleMapController? _controller;
List<Marker> allMarkers = [];
PageController _pageController = new PageController();
int prevPage = 0;
@override
void initState() {
super.initState();
coffeeShops.forEach((element) {
allMarkers.add(Marker(
markerId: MarkerId(element.shopName),
draggable: false,
infoWindow:
InfoWindow(title: element.shopName, snippet: element.address),
position: element.locationCoords));
});
_pageController = PageController(initialPage: 1, viewportFraction: 0.8)
..addListener(_onScroll);
}
void _onScroll() {
if (_pageController.page!.toInt() != prevPage) {
prevPage = _pageController.page!.toInt();
moveCamera();
}
}
_coffeeShopList(index) {
return AnimatedBuilder(
animation: _pageController,
builder: (BuildContext context, Widget? child) {
double value = 1;
if (_pageController.position.haveDimensions) {
value = _pageController.page!.toDouble() - index.toDouble();
value = (1 - (value.abs() * 0.3) 0.06).clamp(0.0, 1.0);
}
return Center(
child: SizedBox(
height: Curves.easeInOut.transform(value) * 125.0,
width: Curves.easeInOut.transform(value) * 350.0,
child: widget,
),
);
},
child: InkWell(
onTap: () {
// moveCamera();
},
child: Stack(children: [
Center(
child: Container(
margin: EdgeInsets.symmetric(
horizontal: 10.0,
vertical: 20.0,
),
height: 125.0,
width: 275.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
boxShadow: [
BoxShadow(
color: Colors.black54,
offset: Offset(0.0, 4.0),
blurRadius: 10.0,
),
]),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: Colors.white),
child: Row(children: [
Container(
height: 90.0,
width: 90.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10.0),
topLeft: Radius.circular(10.0)),
image: DecorationImage(
image: NetworkImage(
coffeeShops[index].thumbNail),
fit: BoxFit.cover))),
SizedBox(width: 5.0),
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
coffeeShops[index].shopName,
style: TextStyle(
fontSize: 12.5,
fontWeight: FontWeight.bold),
),
Text(
coffeeShops[index].address,
style: TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w600),
),
Container(
width: 170.0,
child: Text(
coffeeShops[index].description,
style: TextStyle(
fontSize: 11.0,
fontWeight: FontWeight.w300),
),
)
])
]))))
])),
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: FittedBox(
fit: BoxFit.scaleDown,
child:Stack(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: GoogleMap(
initialCameraPosition:
CameraPosition(target: LatLng(40.7128, -74.0060), zoom: 12.0),
markers: Set.from(allMarkers),
onMapCreated: mapCreated,
),
),
Positioned(
bottom: 20.0,
child: Container(
height: 200.0,
width: MediaQuery.of(context).size.width,
child: PageView.builder(
controller: _pageController,
itemCount: coffeeShops.length,
itemBuilder: (BuildContext context, int index) {
return _coffeeShopList(index);
},
),
),
)
],
)),
),
);
}
void mapCreated(controller) {
setState(() {
_controller = controller;
});
}
moveCamera() {
_controller?.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(
target: coffeeShops[_pageController.page!.toInt()].locationCoords,
zoom: 14.0,
bearing: 45.0,
tilt: 45.0)));
}
}