任何人都知道對此的修復,我不斷收到此錯誤,我在這里使用了 OnPressed,我想我想在這里使用 VoidCallback 但是當我使用它時,我得到了錯誤:
“引數型別 'void Function(dynamic)' 不能分配給引數型別 'void Function()'。”
一直在這個問題上感謝您的幫助。
import 'package:concept1/constant.dart';
import 'package:concept1/screen/login/widget/welcome_back.dart';
import 'package:flutter/material.dart';
class LoginScreen extends StatelessWidget {
const LoginScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: buildAppBar(context),
body: Column(
children: [
const WelcomeBack(),
Container(
padding: EdgeInsets.symmetric(vertical: 20, horizontal: 30),
child: Column(children: <Widget>[
InputTextField(
label: 'Email',
onChange: (value) {},
),
InputTextField(
label: 'Password',
onChange: (value) {},
),
]),
)
],
),
);
}
AppBar buildAppBar(BuildContext context) {
return AppBar(
backgroundColor: mBackgroundColor,
elevation: 0,
centerTitle: true,
title: Text(
'Login Screen',
style: TextStyle(
color: mPrimaryColor,
),
),
leading: IconButton(
icon: const Icon(Icons.arrow_back_ios),
color: mPrimaryColor,
onPressed: () {
Navigator.pop(context);
},
),
);
}
}
class InputTextField extends StatelessWidget {
const InputTextField({
Key? key,
required this.label,
required this.onChange,
}) : super(key: key);
final String label;
final Function? onChange;
@override
Widget build(BuildContext context) {
return TextField(
onChanged: onChange,
cursorColor: Colors.grey,
decoration: InputDecoration(
labelText: label,
labelStyle: const TextStyle(color: Colors.grey),
border: UnderlineInputBorder(
borderSide: BorderSide(
color: mPrimaryColor,
width: 2,
)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: mPrimaryColor,
width: 2,
)),
enabledBorder: const UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.grey,
width: 0.5,
))),
);
}
}
uj5u.com熱心網友回復:
每當您將函式作為引數傳遞時,您應該使用VoidCallBack而不是Function
只是改變 :
final Function? onChange
至
final VoidCallBack? onChange
uj5u.com熱心網友回復:
我想到了!
import 'package:concept1/constant.dart';
import 'package:concept1/screen/login/widget/welcome_back.dart';
import 'package:flutter/material.dart';
class LoginScreen extends StatelessWidget {
const LoginScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: buildAppBar(context),
body: Column(
children: [
const WelcomeBack(),
Container(
padding: EdgeInsets.symmetric(vertical: 20, horizontal: 30),
child: Column(children: <Widget>[
InputTextField(
label: 'Email',
onChange: () {},
),
InputTextField(
label: 'Password',
onChange: (() {}),
)
]),
)
],
),
);
}
AppBar buildAppBar(BuildContext context) {
return AppBar(
backgroundColor: mBackgroundColor,
elevation: 0,
centerTitle: true,
title: Text(
'Login Screen',
style: TextStyle(
color: mPrimaryColor,
),
),
leading: IconButton(
icon: const Icon(Icons.arrow_back_ios),
color: mPrimaryColor,
onPressed: () {
Navigator.pop(context);
},
),
);
}
}
class InputTextField extends StatelessWidget {
const InputTextField({
Key? key,
required this.label,
required this.onChange,
}) : super(key: key);
final String label;
final VoidCallback onChange;
@override
Widget build(BuildContext context) {
return TextField(
onChanged: (value) {},
cursorColor: Colors.grey,
decoration: InputDecoration(
labelText: label,
labelStyle: const TextStyle(color: Colors.grey),
border: UnderlineInputBorder(
borderSide: BorderSide(
color: mPrimaryColor,
width: 2,
)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: mPrimaryColor,
width: 2,
)),
enabledBorder: const UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.grey,
width: 0.5,
))),
);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/523378.html
標籤:扑镖
