我想將這個字串的資料傳遞 String pathPDF = "assets/borst-oei.pdf";給另一個名為 arbo.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 并且它可以作業,但我將改用下面的方式。
這些方法之間有任何性能問題嗎?
uj5u.com熱心網友回復:
什么不是“那么定義”?PDFScreen 的引數還是 String pathPDF 本身?
只需將引數添加到名為 widget 的建構式中即可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),
..
)
uj5u.com熱心網友回復:
使用資料從這里導航
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
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/535416.html
標籤:安卓ios细绳扑镖
上一篇:創建一個移動應用程式,計算用戶輸入的文本中包含字母“A”的單詞數
下一篇:Riverpodref.watch(statenotifierprovider)與ref.watch(statenotifierprovider.notifier)
