如何将字符串数据从一个文件传递到另一个颤振



我想把这个字符串:String pathPDF = "assets/borst-oei.pdf";的数据传递给另一个名为arbor .dart的dart文件

问题是我不知道我怎么能做到这一点:GestureDetector( onTap: () => Navigator.of(context).push(PageTransition( child: PDFScreen(), type: PageTransitionType.fade)),

我不能这样做:GestureDetector( onTap: () => Navigator.of(context).push(PageTransition( child: PDFScreen(pathPDF: ''),type: PageTransitionType.fade)),因为它没有定义,所以

这是字符串:String pathPDF = "assets/borst-oei.pdf";

我该如何解决这个问题?

这是一小段代码:

import 'package:get/get.dart';
import 'package:hetmaantje/utils1/colors.dart';
import 'package:page_transition/page_transition.dart';
import 'arbo.dart';
import 'assets.dart';
class oeiikgroei extends StatefulWidget {
const oeiikgroei({Key? key}) : super(key: key);
@override
State<oeiikgroei> createState() => _oeiikgroeiState();
}

class _oeiikgroeiState extends State<oeiikgroei> {
String pathPDF = "assets/borst-oei.pdf";
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 0,
title: const Text(
"Oei ik groei",
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
),
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(colors: [
hexStringToColor("no"),
hexStringToColor("notshowing"),
hexStringToColor("this is not an mistake"),
hexStringToColor("#sorry")
], begin: Alignment.topCenter, end: Alignment.bottomCenter)),

child: Card(
color: Colors.transparent,
elevation: 0,
shape: RoundedRectangleBorder(

),
child: ListView(
padding: EdgeInsets.all(8),
physics: const BouncingScrollPhysics(),
children: [
Column(

children: [
SizedBox(
width: double.infinity,
child: Image.asset(Assets.imagesIcon17, fit: BoxFit.cover)),
SizedBox(
height: Get.size.height * .02,
),]),
ListTile(
contentPadding: EdgeInsets.only(left: 5, top: 1 , right: 4),
tileColor: Colors.transparent,
onTap: () {
Navigator.of(context).push(PageTransition(
child: PDFScreen(),
type: PageTransitionType.fade));
},
textColor: Colors.white,
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.white, width: 3 ),
borderRadius: BorderRadius.circular(10),
),  

我现在已经扩展了PDFScreen,它可以工作,但我将使用下面的方式代替。

方法之间是否存在任何性能问题?

什么不是" defined then ";? 参数到PDFScreen或字符串pathPDF本身?

只需将参数添加到名为PDFScreen的小部件的构造函数中(如果它是StatefulWidget,则无关紧要)。

class PDFScreen extends StatelessWidget {
const PDFScreen({Key? key, required this.pathPdf}) : super(key: key);
final String pathPdf;
...
}

:

GestureDetector(
onTap: () => Navigator.of(context).push(
PageTransition(
child: PDFScreen(pathPDF: pathPDF),
type: PageTransitionType.fade),
..
)

从这里开始导航

GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: ((context) => PDFScreen(pathPDF: pathPDF)),
),
);
},
);

获取另一个文件中的数据

class PDFScreen extends StatelessWidget {
const PDFScreen({Key? key, required this.pathPdf}) : super(key: key);
final String pathPdf;      
// The rest of your code
}

相关内容

最新更新