【发布时间】:2021-08-19 22:06:34
【问题描述】:
我创建了一个卡片组件,其中包含图标、文本和 pressn 作为卡片组件内的参数。 pressn 代表路线。除了表示路线小部件的 pressn 小部件外,所有其他小部件都在工作。
我想给 pressn 分配任何 unClick 或 tab 功能吗?
下面是代码
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:api_example_app/constants.dart';
import 'package:flutter/widgets.dart';
class CardsParent extends StatefulWidget {
const CardsParent({
Key key,
@required this.size,
this.icon,
this.title,
this.subtitle,
this.pressn,
}) : super(key: key);
final Size size;
final IconData icon;
final String title;
final String subtitle;
final GestureTapCallback pressn;
@override
_CardsParentState createState() => _CardsParentState();
}
class _CardsParentState extends State<CardsParent> {
@override
Widget build(BuildContext context) {
return Container(
width: 140,
height: 100,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
color: Colors.white,
elevation: 10,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
leading: Icon(
widget.icon,
size: 50,
color: kOrangeColor,
),
title: Text(widget.title,
style: TextStyle(fontSize: 14.0, color: kOrangeColor)),
subtitle: Text(widget.subtitle,
style: TextStyle(fontSize: 11.0, color: kOrangeColor)),
),
],
),
),
);
}
}
下面是我要使用代码的地方,在这里我通过 pressn 来表示 Navigator。
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
CardsParent(
size: size,
icon: FontAwesomeIcons.temperatureHigh,
title: 'Tem',
subtitle: '33C',
pressn: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TemSensorScreen(),
),
);
},
),
CardsParent(
size: size,
title: 'Hum ',
subtitle: '75%',
icon: FontAwesomeIcons.cloudShowersHeavy,
pressn: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HumSensorScreen(),
),
);
},
),
],
),
我做错了什么?
【问题讨论】:
-
您没有在
CardsParent的任何地方使用pressn -
我用过。请检查:` press: () { Navigator.push( context, CupertinoPageRoute( builder: (context) => SensorScreen(), ), ); },`
-
以下是我如何解构代码 [1]:ibb.co/Jt0cmxn 我在哪里使用它:ibb.co/FHCY9Tx
-
在这些更改之后,您是否仍然面临同样的问题?
标签: flutter routes flutter-routes