大家好,我一直試圖從動態文本欄位值中獲取值到下一個螢屏這里是第一個螢屏代碼。
for (int i = 0; i < _nameControllers.length; i ) {
Navigator.pushReplacement(
context,
CupertinoPageRoute(
builder: (context) => TimeSheetPreviewScreen(
name: _nameControllers[i].text, ====> this line is only showing single value not whole value
// Helper
// .dropdownNameListForSelectClientScreen
// .toString()
// .replaceAll("[", "")
// .replaceAll("]", ""),
startTime: "s",
endTime: "getEndTime",
showDate: "aa",
decription: _descriptionControllers[i].text,
totalLength: this.i,
perHourRate: hourlyRateController.text,
suppliesAmount:
suppliesAmountController.text,
),
),
);
}
但是當我開始一個回圈并將文本欄位中的所有值顯示到另一個螢屏時,這里是行
name: _nameControllers[i].text, ====> this line is only showing a single value not the whole value
此文本欄位僅顯示單個值,而不是每個 textController 欄位值。
這是下一個螢屏代碼。
import 'package:easy_localization/easy_localization.dart';
import 'package:extended_masked_text/extended_masked_text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:ole_app/screens/NewFinalScreen/TimeSheetScreen/pdfGenerationForTimeSheet/PdfInvoiceApi.dart';
import 'package:ole_app/screens/NewFinalScreen/TimeSheetScreen/pdfGenerationForTimeSheet/fileHandler.dart';
import 'package:ole_app/screens/NewFinalScreen/TimeSheetScreen/time_sheet_screen.dart';
import '../../../custom_widgets/Container_btn_with_gradient.dart';
import '../../../custom_widgets/appbar.dart';
import '../../../translations/locale_keys.g.dart';
import '../../../utils/controllers.dart';
import '../../../utils/helper.dart';
class TimeSheetPreviewScreen extends StatefulWidget {
var name,
startTime,
endTime,
showDate,
decription,
// showTime,
perHourRate,
suppliesAmount;
final int totalLength;
TimeSheetPreviewScreen({
Key? key,
this.name,
this.startTime,
this.endTime,
this.showDate,
this.decription,
// this.showTime,
this.perHourRate,
this.suppliesAmount,
required this.totalLength,
}) : super(key: key);
@override
_TimeSheetPreviewScreenState createState() => _TimeSheetPreviewScreenState();
}
class _TimeSheetPreviewScreenState extends State<TimeSheetPreviewScreen> {
final hourlyRateController = MaskedTextController(mask: '000');
// final suppliesAmount = MaskedTextController(mask: '000');
final myStyle = TextStyle(
fontWeight: FontWeight.w600,
fontSize: 22.sp,
);
final myTotalStyle = TextStyle(
fontWeight: FontWeight.w700,
fontSize: 30.sp,
);
// var listItems = Helper.selectedItems.toString().replaceAll('[', '');
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () => Helper.onWillPopFunc(
context: context,
className: const TimeSheetScreen(),
),
child: Scaffold(
appBar: CustomAppBar(
title: LocaleKeys.timeSheetPreview_txt.tr(),
fun: () => Navigator.pushReplacement(
context,
CupertinoPageRoute(
builder: (context) => const TimeSheetScreen(),
)),
elevation: 0),
body: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.only(left: 30.w),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
LocaleKeys.details_txt.tr(),
style: myStyle,
),
SizedBox(
height: 60.h,
),
ListView.separated(
physics: const BouncingScrollPhysics(),
shrinkWrap: true,
itemCount: widget.totalLength,
separatorBuilder: (BuildContext context, int index) =>
const Divider(
color: Colors.transparent,
),
itemBuilder: (BuildContext context, int index) {
WidgetsBinding.instance?.addPostFrameCallback((_) {
Helper.index = index;
if (kDebugMode) {
print("index =====> " index.toString());
}
});
return Column(
children: [
Row(
children: [
Text(
"${LocaleKeys.name_txt.tr()}: ",
style: myStyle,
),
Text("${widget.name}"),
],
),
SizedBox(
height: 15.h,
),
Row(
children: [
Text(
"${LocaleKeys.startTime_txt.tr()}: ",
style: myStyle,
),
Text("${widget.name}"),
],
),
SizedBox(
height: 15.h,
),
Row(
children: [
Text(
"${LocaleKeys.endTime_txt.tr()}: ",
style: myStyle,
),
// Text(
// ControllersTextFields
// .instance.invoiceNoController.text,
// ),
// Text("${widget.endTime}"),
],
),
SizedBox(
height: 15.h,
),
Row(
children: [
Text(
"${LocaleKeys.date_txt.tr()}: ",
style: myStyle,
),
Text(
// DateFormat('dd-MM-yyyy').format(widget.showDate),
"${DateTime.now()}",
),
],
),
SizedBox(
height: 15.h,
),
Row(
children: [
Text(
"${LocaleKeys.description_txt.tr()}: ",
style: myStyle,
),
Text(
widget.decription,
),
],
),
SizedBox(
height: 15.h,
),
Helper.customSizedBox,
const Divider(
color: Colors.grey,
),
// Helper.customSizedBox,
],
);
},
),
// ============================
Row(
children: [
Text(
"${LocaleKeys.time_txt.tr()}: ",
style: myStyle,
),
const Text("5.5 Hours"),
],
),
SizedBox(
height: 15.h,
),
Row(
children: [
Text(
"${LocaleKeys.perHourRate_txt.tr()}: ",
style: myStyle,
),
Text("\$${widget.perHourRate}"),
],
),
SizedBox(
height: 15.h,
),
Row(
children: [
Text(
"Supplies Amount: ",
style: myStyle,
),
Text("\$${widget.suppliesAmount}"),
],
),
SizedBox(
height: 40.h,
),
Row(
children: [
Text(
"${LocaleKeys.total_txt.tr()}: ",
style: myTotalStyle,
),
],
),
SizedBox(
height: 15.h,
),
Row(
children: [
Text(
"${LocaleKeys.totalTime_txt.tr()}: ",
style: myStyle,
),
const Text(''),
// "${Helper.calcWorkHours(widget.startTime, widget.endTime)}"),
],
),
SizedBox(
height: 15.h,
),
Row(
children: [
Text(
"${LocaleKeys.totalAmount_txt.tr()}: ",
style: myStyle,
),
const Text(
'224',
),
// "\$${Helper.calculateTotalAmount(double.tryParse(widget.startTime)!, double.tryParse(widget.endTime)!)} ")
],
),
// ============================
SizedBox(
height: 100.h,
),
],
),
),
),
bottomNavigationBar: SizedBox(
height: 180.h,
child: Column(
children: [
Expanded(
child: Column(
children: [
CustomContainerButton(
text: LocaleKeys.downloadInvoice_text.tr(),
onPressed: () async {
Helper.showAllDataForEverything;
setState(() {});
// generate pdf file
final pdfFile = await PdfInvoiceApi.generate(
weekEndingDate: widget.showDate,
name: widget.name,
description: widget.decription,
amountBilled: widget.perHourRate,
invoiceNo: ControllersTextFields
.instance.invoiceNoController.text);
// opening the pdf file
setState(() {
FileHandleApi.openFile(pdfFile);
});
// Helper.calcWorkHours(widget.startTime, widget.endTime);
// final date = DateTime.now();
// final dueDate = date.add(const Duration(days: 7));
// final invoice = Invoice(
// supplier: Supplier(
// name: "AHmed",
// address: "karachi, johar town",
// paymentInfo: "sddddddddd"),
// customer: Customer(
// name: "AHmed",
// address: "karachi, johar town",
// ),
// info: InvoiceInfo(
// date: date,
// dueDate: dueDate,
// description: "sddddddddddd",
// number: "${DateTime.now().year}-9999",
// ),
// items: [
// InvoiceItem(
// description: "Coffe",
// date: DateTime.now(),
// quantity: 3,
// vat: 0.19,
// unitPrice: 5.99,
// ),
// InvoiceItem(
// description: "Water",
// date: DateTime.now(),
// quantity: 3,
// vat: 0.19,
// unitPrice: 5.99,
// ),
// InvoiceItem(
// description: "Orange",
// date: DateTime.now(),
// quantity: 3,
// vat: 0.19,
// unitPrice: 5.99,
// ),
// ],
// );
// final pdfFile = await PdfInvoiceApi.generate(invoice);
// PdfApi.openFile(pdfFile);\
},
),
SizedBox(
height: 40.h,
),
CustomContainerButton(
text: LocaleKeys.cancel_txt.tr(),
onPressed: () {
Navigator.pushReplacement(
context,
CupertinoPageRoute(
builder: (context) => const TimeSheetScreen(),
),
);
},
isActive: false,
),
],
),
),
],
),
),
),
);
}
// Future openFile(File file) async {
// final url = file.path;
//
// await openFile.open(url);
// }
}
請幫我。
uj5u.com熱心網友回復:
您好,我認為問題出在 Navigator.pushReplacement 上。當您使用替換時,導航器堆疊上的所有先前頁面都將被最后一頁替換。如果您有許多 TextController,則只會顯示最后一個。嘗試更改您的視圖,或改用 Navigator.push
uj5u.com熱心網友回復:
當您在 for 回圈中呼叫 Navigator.pushReplacement 時,在索引一處它會中斷回圈并導航到新螢屏,這就是導致此問題的原因。
更新: 試試這個:
String text = '';
_nameControllers.forEach((element) => text = text element.text);
然后像這樣導航:
Navigator.pushReplacement(
context,
CupertinoPageRoute(
builder: (context) => TimeSheetPreviewScreen(
name: text,
startTime: "s",
endTime: "getEndTime",
showDate: "aa",
decription: _descriptionControllers[i].text,
totalLength: this.i,
perHourRate: hourlyRateController.text,
suppliesAmount:
suppliesAmountController.text,
),
),
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/507009.html
上一篇:.NETClean架構-多個專案
