我flutter_lints在我的项目中安装了插件,安装后它显示一条警告消息“不要在 createState 中放置任何逻辑”。如何解决这个问题?
class OverviewPage extends StatefulWidget {
final int id;
const OverviewPage({Key? key, required this.id}) : super(key: key);
@override
_OverviewPageState createState() => _OverviewPageState(id); // Warning on this line
}
class _OverviewPageState extends State<OverviewPage>{
late final int id;
_OverviewPageState(this.id);
}
Run Code Online (Sandbox Code Playgroud) Flutter中如何限制“0”不应该放在第一个字符text field?下面是 dart 代码示例。
TextField(
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.allow(
RegExp("[0-9\u0660-\u0669]")),
],
keyboardType: TextInputType.number,
focusNode: _nodeText1,
controller: mobileNumber,
decoration: InputDecoration.collapsed(
fillColor: TuxedoColor.whiteColor,
hintText: "5xxxxxxxx"),
),
Run Code Online (Sandbox Code Playgroud) 我在我的 flutter 项目中添加了支付网关 sdk,但是当我尝试在 android 上本地运行该项目时,应用程序崩溃并显示消息“java.lang.IllegalStateException:您需要在此活动中使用 Theme.AppCompat 主题(或后代) ”。如何解决这个问题?
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app">
<application
android:label="App"
android:icon="@mipmap/main_launcher"
android:usesCleartextTraffic="true">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value=""/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<activity
android:name="com.mastercard.gateway.android.sdk.Gateway3DSecureActivity"
android:label="@string/gateway_3d_secure_authentication" />
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
风格
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud) 我正在使用此库在谷歌地图上显示我当前的位置:package:location/location.dart。酒吧开发链接
问题是每当我在发布模式下打开应用程序时,它就会崩溃并显示:
LateInitializationError:字段“currentLatLng”尚未初始化
它不会在 Android 设备上的调试模式下崩溃。然而,它确实会在 iOS 上崩溃(发布和调试模式)。
我不确定我做错了什么。这是我的小部件和尝试:
class TestGoogle extends StatefulWidget {
const TestGoogle({Key? key}) : super(key: key);
@override
_TestGoogleState createState() => _TestGoogleState();
}
class _TestGoogleState extends State<TestGoogle> {
late LatLng currentLatLng;
late GoogleMapController mapController;
Location location = new Location();
var latitude;
var longitude;
late LocationData _locationData;
get() async {
_locationData = await location.getLocation();
latitude = _locationData.latitude;
longitude = _locationData.longitude;
setState(() {
currentLatLng = new LatLng(latitude, longitude);
});
} …Run Code Online (Sandbox Code Playgroud)