Android 如何将Inkwell添加到Flatter中的容器文本中?
我是个新手。毫无疑问,这里的环境很棒。目前,我正在尝试创建一个多页面的应用程序在颤振与一些行和容器。我有两个这样的容器,它有一个文本Android 如何将Inkwell添加到Flatter中的容器文本中?,android,flutter,dart,Android,Flutter,Dart,我是个新手。毫无疑问,这里的环境很棒。目前,我正在尝试创建一个多页面的应用程序在颤振与一些行和容器。我有两个这样的容器,它有一个文本 Row( children: [ Container( height: 50, width: MediaQuery.of(context).size.width / 1.2, decoration: BoxDecorati
Row(
children: [
Container(
height: 50,
width: MediaQuery.of(context).size.width / 1.2,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: ColorConstants.korangeColor,
),
child: Center(
child: Text(
"Food Poisoning Symptoms",
style: GoogleFonts.spartan(
fontSize: 15,
fontWeight: FontWeight.w600,
color: ColorConstants.kwhiteColor,
),
),
),
),
SizedBox(
width: 10,
),
],
),
我确实用墨水瓶包装了我的容器,并尝试了以下方法:
Row(
children: [
Container(
height: 50,
width: MediaQuery.of(context).size.width / 1.2,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: ColorConstants.korangeColor,
),
child: Center(
child: Text(
"Food Poisoning Symptoms",
style: GoogleFonts.spartan(
fontSize: 15,
fontWeight: FontWeight.w600,
color: ColorConstants.kwhiteColor,
),
),
InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => FoodPoisoning(),
),
);
},
),
),
),
但我的错误日志显示为黑屏,页面显示为黑屏:
断言失败:第1920行位置12:“hasSize”
我特别不明白我的代码发生了什么。有人能告诉我是什么问题以及如何解决吗?用
InkWell
包装您的容器
Row(children: [
InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => FoodPoisoning(),
),
);
},
child: Container(
height: 50,
width: MediaQuery.of(context).size.width / 1.2,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: ColorConstants.korangeColor,
),
child: Center(
child: Text(
"Food Poisoning Symptoms",
style: GoogleFonts.spartan(
fontSize: 15,
fontWeight: FontWeight.w600,
color: ColorConstants.kwhiteColor,
),
),
),
))
]);
用InkWell
包装您的容器
Row(children: [
InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => FoodPoisoning(),
),
);
},
child: Container(
height: 50,
width: MediaQuery.of(context).size.width / 1.2,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: ColorConstants.korangeColor,
),
child: Center(
child: Text(
"Food Poisoning Symptoms",
style: GoogleFonts.spartan(
fontSize: 15,
fontWeight: FontWeight.w600,
color: ColorConstants.kwhiteColor,
),
),
),
))
]);
我通过创建一个无状态小部件来使用这个方法,该小部件与Flutter中的小部件不同
目标:是防止单击文本时阴影出现在容器大小上,如下所示:
class InkWellApp extends StatelessWidget {
final Function onTap;
final Widget child;
final BorderRadius borderRadius;
const InkWellApp(
{Key key, this.onTap, this.child, this.borderRadius = BorderRadius.zero})
: super(key: key);
@override
Widget build(BuildContext context) {
return Stack(
children: [
child,
Positioned.fill(
child: Material(
color: Colors.transparent,
borderRadius: borderRadius,
child: InkWell(
borderRadius: borderRadius,
onTap: onTap,
),
)),
],
);
}
}
它的应用如下所示:
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
.
.
.
.
InkWellApp(child: Text('Anything Text onTap .....'), onTap: (){
/// onTap Function her ...
},)
],
),
);
}
}
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 50,
width: MediaQuery
.of(context)
.size
.width / 1.2,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: ColorConstants.korangeColor,
),
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => FoodPoisoning(),
),
);
},
child: Text(
"Food Poisoning Symptoms",
//Add this line instead of Center() widget
textAlign: TextAlign.center,
style: GoogleFonts.spartan(
fontSize: 15,
fontWeight: FontWeight.w600,
color: ColorConstants.kwhiteColor,
),
),
),
),
],
)
我通过创建一个无状态小部件来使用这个方法,该小部件与Flutter中的小部件不同
目标:是防止单击文本时阴影出现在容器大小上,如下所示:
class InkWellApp extends StatelessWidget {
final Function onTap;
final Widget child;
final BorderRadius borderRadius;
const InkWellApp(
{Key key, this.onTap, this.child, this.borderRadius = BorderRadius.zero})
: super(key: key);
@override
Widget build(BuildContext context) {
return Stack(
children: [
child,
Positioned.fill(
child: Material(
color: Colors.transparent,
borderRadius: borderRadius,
child: InkWell(
borderRadius: borderRadius,
onTap: onTap,
),
)),
],
);
}
}
它的应用如下所示:
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
.
.
.
.
InkWellApp(child: Text('Anything Text onTap .....'), onTap: (){
/// onTap Function her ...
},)
],
),
);
}
}
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 50,
width: MediaQuery
.of(context)
.size
.width / 1.2,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: ColorConstants.korangeColor,
),
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => FoodPoisoning(),
),
);
},
child: Text(
"Food Poisoning Symptoms",
//Add this line instead of Center() widget
textAlign: TextAlign.center,
style: GoogleFonts.spartan(
fontSize: 15,
fontWeight: FontWeight.w600,
color: ColorConstants.kwhiteColor,
),
),
),
),
],
)