如何将文本发送到其他页面?'package:flutter/src/material/tab_controller.dart':失败的断言:第 181 行 pos 12:"值 >= 0



帮帮我,我想把文本从第一页发送到第二页。

上班地点页面

Padding(
padding: const EdgeInsets.only(top: 16.0),
child: RaisedGradientButton(
child: Text(
'Dapatkan Pengukuran',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
fontFamily: 'Nunito',
fontWeight: FontWeight.bold),
),
gradient: LinearGradient(
colors: const <Color>[Colors.purple, Colors.blue],
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ShowMeasurementsPage(                            
name: name.text,
nohap: nohap.text,

),
),
);
}),
)

第二页*

和我想显示文本的第二页,但错误。

import 'package:flutter/material.dart';
class ShowMeasurementsPage extends StatefulWidget {
static String tag = 'show-measurements-page';
const ShowMeasurementsPage({Key? key}) : super(key: key);
@override
_ShowMeasurementsPageState createState() => _ShowMeasurementsPageState();
}
class _ShowMeasurementsPageState extends State<ShowMeasurementsPage> {
final String? name, nohap;
_ShowMeasurementsPageState({this.name, this.nohap});
有人能帮我吗?

您需要将参数传递给StatefulWidget,然后您可以通过使用widget.namewidget.nohapbuild方法中访问它们。

例如:

class ShowMeasurementsPage extends StatefulWidget {
static String tag = 'show-measurements-page';
final String? name;
final String? nohap;
const ShowMeasurementsPage({
Key? key,
this.name,
this.nohap,
}): super(key: key);
@override
State<ShowMeasurementsPage> createState() => 
_ShowMeasurementsPageState();
}
class _ShowMeasurementsPageState extends State<ShowMeasurementsPage> {
@override
Widget build(BuildContext context) {
return Column(
children: [
if (widget.name != null)
Text(widget.name!),
if (widget.nohap != null)
Text(widget.nohap!),
],
);
}
}

相关内容

  • 没有找到相关文章

最新更新