onGenerateRouteFlutter中和路由的好处或用例是什么。
在我的应用程序的第一页里面,MaterialApp我们可以为我们的应用程序定义路由,我们可以用onGenerateRoute.
两者都用于 NamedRoute。
我有一个疑问,在哪种情况下我需要使用路由以及在哪种情况下我需要使用onGenerateRoute?
我在我的颤振应用程序中使用了firebase_messaging。为了在 pub 中使用 firebase 消息处理后台消息,他们建议创建新的 Application.java 文件并替换 AndroidManifest 文件中的 java 文件名。
在我的应用程序中,我正在使用 kotlin,并且我已经在 MainActivity.kt 中实现了一些本机代码
那么如何在 kotlin 中编写这段代码。
package io.flutter.plugins.firebasemessagingexample;
import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;
public class Application extends FlutterApplication implements PluginRegistrantCallback {
@Override
public void onCreate() {
super.onCreate();
FlutterFirebaseMessagingService.setPluginRegistrant(this);
}
@Override
public void registerWith(PluginRegistry registry) {
GeneratedPluginRegistrant.registerWith(registry);
}
}
Run Code Online (Sandbox Code Playgroud)
AndroidManifest 文件中必须将 MainActivity 替换为 Application 吗?
在 Flutter 中,我有一张地图,可以在location 的帮助下获取设备 位置。然后我使用这个位置在谷歌地图 Flutter插件的帮助下在谷歌地图中显示标记。
代码类似于
child: GoogleMap(
mapType: MapType.hybrid,
initialCameraPosition: CameraPosition(
target: LatLng(lat, lng),
zoom: 5,
),
markers: Set<Marker>.of(
<Marker>[
Marker(
draggable: true,
markerId: MarkerId("1"),
position: LatLng(lat, lng),
icon: BitmapDescriptor.defaultMarker,
infoWindow: const InfoWindow(
title: 'Usted está aquí',
),
)
],
),
onMapCreated: (GoogleMapController controller) {
mapController = controller;
},
))
Run Code Online (Sandbox Code Playgroud)
如果位置插件失败或获取错误数据,我需要选择重新定位此标记。我使用draggable: true拖动标记,但我需要采用新的纬度和经度将其保存在数据库中。
所以问题是:使用可拖动我怎样才能获得新的纬度和经度?
我希望用户在移动到我的 Flutter 应用程序中的第二页之前选择单选按钮中给出的选项。我在 Alertdialog 中显示单选按钮小部件,但选择后单选按钮未更改。
一切状态类
floatingActionButton: FloatingActionButton(
child: Icon(Icons.create),
onPressed: () {
return showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text("Select Grade System and No of Subjects"),
actions: <Widget>[
Radio(value: 0, groupValue: groupValue, onChanged: selectRadio),
Radio(value: 1, groupValue: groupValue, onChanged: selectRadio),
],
));
},
),
Run Code Online (Sandbox Code Playgroud)
选择收音机功能
void selectRadio(int value)
{
setState(() {
groupValue=value;
});
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 Google 地图,添加大量标记后,我想将相机移动到 newLatLngBounds 以显示用户可见的所有标记。但我面临这个错误。
使用 newLatLngBounds(LatLngBounds, int) 时出错:地图大小不能为 0。最有可能的是,地图视图尚未进行布局。要么等到布局发生,要么使用 newLatLngBounds(LatLngBounds, int, int, int) ,它允许您指定地图的尺寸。, null)
Future<void> getCenterMap() async {
double minlatitude = loadInformationMap[0]['latlng'].latitude,
maxlatitude = loadInformationMap[0]['latlng'].latitude,
minlongitude = loadInformationMap[0]['latlng'].longitude,
maxlongitude = loadInformationMap[0]['latlng'].longitude;
for (int i = 0; i < loadInformationMap.length; i++) {
if (minlatitude >= loadInformationMap[i]['latlng'].latitude) {
minlatitude = loadInformationMap[i]['latlng'].latitude;
}
if (minlongitude >= loadInformationMap[i]['latlng'].longitude) {
minlongitude = loadInformationMap[i]['latlng'].longitude;
}
if (maxlatitude <= loadInformationMap[i]['latlng'].latitude) {
maxlatitude = loadInformationMap[i]['latlng'].latitude;
}
if (maxlongitude <= loadInformationMap[i]['latlng'].longitude) {
maxlongitude = loadInformationMap[i]['latlng'].longitude;
} …Run Code Online (Sandbox Code Playgroud) google-maps latitude-longitude google-maps-markers dart flutter
在 flutter 中创建 Google 地图中的自定义图标显示错误。
我的 pubspec.yaml 文件
assets:
- assets/truck.png
Run Code Online (Sandbox Code Playgroud)
我的代码是:
void getCustomIcon() async {
customIcon = await BitmapDescriptor.fromAssetImage(
ImageConfiguration(
devicePixelRatio: 2.5,
),
'assets/truck.png');
}
Run Code Online (Sandbox Code Playgroud)
错误是:
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, Failed to decode image. The provided image must be a Bitmap., null)
E/flutter (15757): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter (15757): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33)
Run Code Online (Sandbox Code Playgroud) 在 iOS 中调用 subscribeToTopic 方法时,会出现此 APNS 令牌异常。我已遵循文档。我使用了 Flutterfire configure 命令来配置 Flutter 项目。
但这个错误就来了。有谁知道为什么会出现此错误以及如何解决它?
我没有在代码中调用 getAPNSToken() 方法。
调用 subscribeToTopic 方法之前是否需要启动该方法?
注意:我们不使用令牌向特定用户发送通知。我们正在使用该主题来发送通知。所以我没有调用 getToken 和 getAPNSToken 方法。
1970-01-02 04:49:38.216263+0300 Runner[675:161670] flutter: [firebase_messaging/apns-token-not-set] APNS token has not been set yet. Please ensure the APNS token is available by calling `getAPNSToken()`.
1970-01-02 04:49:38.216725+0300 Runner[675:161670] flutter: #0 MethodChannelFirebaseMessaging._APNSTokenCheck (package:firebase_messaging_platform_interface/src/method_channel/method_channel_messaging.dart:138:9)
<asynchronous suspension>
#1 MethodChannelFirebaseMessaging.subscribeToTopic (package:firebase_messaging_platform_interface/src/method_channel/method_channel_messaging.dart:390:5)
<asynchronous suspension>
#2 PushNotificationService.subscribeUserToFirebase (package:team/src/common/notification/firebase/push_notification.dart:70:7)
<asynchronous suspension>
#3 userAPI (package:team/src/features/master_data/application/master_data_providers.dart:116:5)
<asynchronous suspension>
#4 FutureHandlerProviderElementMixin.handleFuture.<anonymous closure>.<anonymous closure> (package:riverpod/src/async_notifier/base.dart:337:9)
<asynchronous suspension>
Run Code Online (Sandbox Code Playgroud) apple-push-notifications ios firebase flutter firebase-cloud-messaging
我在Flutter 中有一个带有 textformfield 和 dropdownbuttonformfield的表单。运行时我的应用提示对我不起作用。提示未显示在下拉按钮表单字段中。它将kkk显示为初始值,而不显示Select City。
我在这里使用 StatefulWidget。
帮我解决这个问题。提前致谢。
class _AddTripState extends State<AddTrip> {
var formKey = GlobalKey<FormState>();
TextEditingController nameController = TextEditingController();
TextEditingController numberController = TextEditingController();
TextEditingController datecontroller = TextEditingController();
final format = DateFormat("yyyy-MM-dd");
DateTime _dateTime;
List<String> name = ['kkk', 'rrr'];
String _dropdownvalue = 'kkk';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Add Trip"),
),
body: Form(
key: formKey,
child: ListView(
children: <Widget>[
Text(
'Name',
textAlign: TextAlign.left,
),
TextFormField( …Run Code Online (Sandbox Code Playgroud) 我在有状态小部件中有一个表单,在我的有状态小部件中,我使用提交方法验证我的表单。
在我的应用程序中,我在另一个 dart 文件的另一个页面中显示该表单。
我的表单在新页面和 appbar 操作中可见,我正在调用提交方法,但我不知道如何在新的 dart 文件中调用该提交方法。
我想在这个容器中使用 Inkwell splash。没有 Inkwell 小部件。
Expanded(
child: Container(
padding: EdgeInsets.all(12.0),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black26,
offset: Offset(0, 1),
blurRadius: 2.0)
],
borderRadius: BorderRadius.circular(12.0),
color: _size.white,
),
child: Column(
children: <Widget>[
Icon(
Icons.book,
color: _size.green,
),
SizedBox(
height: 4.0,
),
Text('Instant'),
],
),
),
),
Run Code Online (Sandbox Code Playgroud)
但是当我添加墨水池和材料小部件时,它看起来像
Expanded(
child: Material(
color: _size.white,
child: InkWell(
borderRadius: BorderRadius.circular(12.0),
onTap: () {},
splashColor: Colors.red,
splashFactory: InkSplash.splashFactory,
child: Container(
padding: EdgeInsets.all(12.0),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black26,
offset: Offset(0, 1),
blurRadius: 2.0)
], …Run Code Online (Sandbox Code Playgroud) 我在列底部有带芯片的列表视图。
在从列表视图开始的第一个图像中,它是圆形的,但最后它显示为矩形。
滚动列表视图芯片 1 天时溢出。(第二张图片)。
我想两边底都需要圆形,怎么实现?提前致谢。
我的代码
Container(
padding: EdgeInsets.only(
top: 16.0,
),
width: MediaQuery.of(context).size.width,
height: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
color: Colors.white),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(""),
Container(
height: 35,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(12.0),
bottomRight: Radius.circular(12.0)),
color:
Theme.of(context).chipTheme.backgroundColor),
child: ListView(
scrollDirection: Axis.horizontal,
children: getChoiceChips(),
),
)
],
),
)
Run Code Online (Sandbox Code Playgroud)
芯片功能
getChoiceChips() {
List<Widget> choiceChipList = [];
List<String> choiceString = [
'1 Day',
'1 Week',
'1 Month',
'3 Months',
'1 Year'
];
for (String …Run Code Online (Sandbox Code Playgroud)