我在 StatelessWidget 中有一个 ListView。它有项目,每个项目都包含一个复选框。当有人检查项目时,我希望 ListView 将其作为参数发送到另一个页面。但是当我这样做时,它给了我这个错误:
I/flutter ( 7067): The following UnsupportedError was thrown while handling a gesture:
I/flutter ( 7067): Unsupported operation: Cannot add to an unmodifiable list
I/flutter ( 7067): When the exception was thrown, this was the stack:
Run Code Online (Sandbox Code Playgroud)
这是我的代码
class StudentsList extends StatelessWidget {
final List<Child> mList;
StudentsList({this.mList});
@override
Widget build(BuildContext context) {
List<Child> selectedList = [];
return Container(
margin: EdgeInsets.only(top: 50, bottom: 20),
child: ListView.builder(
shrinkWrap: true,
physics: ClampingScrollPhysics(),
itemCount: mList == null ? 0 : …Run Code Online (Sandbox Code Playgroud) 我正在尝试从本机 Android 打开颤动屏幕
所以我尝试使用 MethodChannel 将数据返回到 dart,然后调用将我导航到当前屏幕的方法
但我的代码不起作用
这是我的代码
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
super.configureFlutterEngine(flutterEngine);
String channelName = "app_channel";
MethodChannel methodChannel = new MethodChannel(flutterEngine.getDartExecutor(), channelName);
methodChannel.invokeMethod("openCaller", false, new MethodChannel.Result() {
@Override
public void success(@Nullable Object result) {
Log.i("fromInvoke","success" + result.toString());
}
@Override
public void error(String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails) {
Log.i("fromInvoke","failed" + errorMessage);
}
@Override
public void notImplemented() {
Log.i("fromInvoke","not implemented");
}
});
}
Run Code Online (Sandbox Code Playgroud)
}
static const platform =
const MethodChannel('app_channel');
@override
void initState() { …Run Code Online (Sandbox Code Playgroud) 当应用程序处于前台或后台时,flutter_local_notifications 工作正常
但是当应用程序终止时
onSelectNotification 没有按预期工作,而是打开应用程序
static void initializeLocalNotification() async {
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('ic_launcher');
final IOSInitializationSettings initializationSettingsIOS =
IOSInitializationSettings(
requestSoundPermission: false,
requestBadgePermission: false,
requestAlertPermission: false,
);
final InitializationSettings initializationSettings =
InitializationSettings(
android: initializationSettingsAndroid,
iOS: initializationSettingsIOS,
);
await flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: (String payload) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
var res = await prefs.setString(kNotificationPayLoad, payload);
// navigatorKey.currentState
// .push(MaterialPageRoute(builder: (_) => LoginScreen()));
// navigatorKey.currentState.pop();
});
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
IOSFlutterLocalNotificationsPlugin>()
?.requestPermissions(
alert: true,
badge: true,
sound: true, …Run Code Online (Sandbox Code Playgroud)