Flutter对我来说还不是很自然,希望你们能帮助我。我正在创建一个带有bottomNavigationBar的地图应用程序,并且正在使用一个名为Circular_bottom_navigation 1.0.1的程序包来做到这一点,您可以在下面的链接中找到它。
https://pub.dev/packages/circular_bottom_navigation#-readme-tab-
我设法显示了该栏,但是我遇到了一些让我感到沮丧的问题。
我在回叫中添加了以下行
CircularBottomNavigationController _navigationController =
new CircularBottomNavigationController(selectedPos);
但我不确定如何使用下一个
// Write a new value
_navigationController.value = 0;
// Read the latest value
int latest = _navigationController.value;
您将知道该栏尚未激活。
此外,如果您查看屏幕截图,您会注意到地图停在图标顶部,并且对于条形图不可见。我希望地图到达栏的顶部,因此图标被覆盖。
答案 0 :(得分:0)
import 'dart:async';
import 'package:circular_bottom_navigation/circular_bottom_navigation.dart';
import 'package:circular_bottom_navigation/tab_item.dart';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return 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(37.42796133580664, -122.085749655962),
zoom: 14.4746,
);
List<TabItem> tabItems = List.of([
new TabItem(Icons.home, "Home", Colors.blue, labelStyle: TextStyle(fontWeight: FontWeight.normal)),
new TabItem(Icons.search, "Search", Colors.orange, labelStyle: TextStyle(color: Colors.red, fontWeight: FontWeight.bold)),
new TabItem(Icons.layers, "Reports", Colors.red),
new TabItem(Icons.notifications, "Notifications", Colors.cyan),
]);
static final CameraPosition _kLake = CameraPosition(
bearing: 192.8334901395799,
target: LatLng(37.43296265331129, -122.08832357078792),
tilt: 59.440717697143555,
zoom: 19.151926040649414);
CircularBottomNavigationController _navigationController = new CircularBottomNavigationController(0);
@override
Widget build(BuildContext context) {
return new Scaffold(
body: GoogleMap(
mapType: MapType.hybrid,
initialCameraPosition: _kGooglePlex,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
),
floatingActionButton: FloatingActionButton.extended(
onPressed: _goToTheLake,
label: Text('To the lake!'),
icon: Icon(Icons.directions_boat),
),
extendBody: true,
bottomNavigationBar: CircularBottomNavigation(
tabItems,
controller: _navigationController,
selectedCallback: (int selected) {
_navigationController.value = selected;
},
),
);
}
Future<void> _goToTheLake() async {
final GoogleMapController controller = await _controller.future;
controller.animateCamera(CameraUpdate.newCameraPosition(_kLake));
}
}
您必须传递extendBody:true到Scaffold