Here is my task description:
"Underneath the full prospectus pdf, allow for downloading any number of PDFs, so add to the Asset model an array field called Documents with each document having an id for the file and a name. Display them underneath the Download Prospectus thing with the same design (same icon and font)."
Here is how the app looks right now and the full prospectus pdf is below the image:
I have to put more pdf files under the full prospectus pdf, so I'm putting them in a list so that more pdf files can be added in the future.
Here is the current code for displaying the full prospectus pdf on the simulation.
if (widget.asset.prospectusEng?.isNotEmpty ?? false)
Padding(
padding: const EdgeInsets.only(left: 24, right: 24),
child: Row(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Material(
color: Colors.transparent,
child: InkWell(
borderRadius: BorderRadius.all(Radius.circular(4.0)),
onTap: () {
launchURL(widget.asset.prospectusEng!);
},
child: Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 16.0),
child: SizedBox(
height: 38,
width: 26,
child: Icon(
FontAwesomeIcons.filePdf,
size: 36,
color: AppTheme.getTheme().primaryColor,
),
),
),
Text(
"Full Prospectus",
style: AppTheme.getTheme().textTheme.headline1,
),
],
),
),
),
),
],
),
),
Here is the asset.dart file where the toJson and fromJson methods are located.
class Asset {
String? id;
late String name;
late int assetId;
late String assetDocumentID;
late num currentValue;
late int totalShares;
late String address;
late String shortDescription;
late String assetType;
late List assetImageIDList;
late String nameMn;
late String addressMn;
late String defaultCurrency;
late List<Image> imageList = [];
late List<Document> documents = [];
late num expectedAnnualReturn;
late num expected5YearReturn;
late num yearlyAppreciation;
late num fundedAmount;
late num fundingTargetAmount;
late num availableShares;
late num offeringSharePrice;
late num offeringMinInvestment;
late num expectedHoldingPeriod;
late num expectedCAGR;
late String description1Title;
late String description1Content;
late String description2Title;
late String description2Content;
late String description1TitleMn;
late String description1ContentMn;
late String description2TitleMn;
late String description2ContentMn;
late String assetTypeDetailsID;
late bool openInvestment;
RealEstateAssetDetails? realEstateAssetDetails;
SpiritsAssetDetails? spiritsAssetDetails;
ArtworkAssetDetails? artworkAssetDetails;
DebtInstrumentAssetDetails? debtInstrumentAssetDetails;
StartupAssetDetails? startupAssetDetails;
NftFundAssetDetails? nftFundAssetDetails;
List<String>? secondaryAssetTypes;
WhiskyFundAssetDetails? whiskyFundAssetDetails;
String? prospectusEng;
String? prospectusMn;
bool? openFund = false;
bool? delisted = false;
Asset({
this.id,
required this.assetDocumentID,
required this.name,
required this.nameMn,
required this.defaultCurrency,
required this.addressMn,
required this.assetId,
required this.currentValue,
required this.totalShares,
required this.address,
required this.shortDescription,
required this.assetType,
required this.fundedAmount,
required this.fundingTargetAmount,
required this.assetImageIDList,
required this.yearlyAppreciation,
required this.expectedAnnualReturn,
required this.expected5YearReturn,
required this.openInvestment,
required this.availableShares,
required this.offeringSharePrice,
required this.offeringMinInvestment,
required this.expectedHoldingPeriod,
required this.expectedCAGR,
required this.description1Title,
required this.description1Content,
required this.description2Title,
required this.description2Content,
required this.assetTypeDetailsID,
required this.description1TitleMn,
required this.description1ContentMn,
required this.description2TitleMn,
required this.description2ContentMn,
this.spiritsAssetDetails,
this.realEstateAssetDetails,
this.artworkAssetDetails,
this.startupAssetDetails,
this.nftFundAssetDetails,
this.whiskyFundAssetDetails,
this.prospectusMn,
this.prospectusEng,
this.openFund = false,
this.delisted = false,
this.secondaryAssetTypes,
});
Asset.fromJson(Map<String, dynamic> json) {
id = json["\u0024id"] == null ? '' : json["\u0024id"];
assetDocumentID = json['\$id'] ?? '';
description1TitleMn = json['description1TitleMn'] ?? '';
description1ContentMn = json['description1ContentMn'] ?? '';
description2TitleMn = json['description2TitleMn'] ?? '';
description2ContentMn = json['description2ContentMn'] ?? '';
availableShares = json['availableShares'] ?? '';
offeringSharePrice = json['offeringSharePrice'] ?? '';
offeringMinInvestment = json['offeringMinInvestment'] ?? '';
expectedHoldingPeriod = json['expectedHoldingPeriod'] ?? '';
expectedCAGR = json['expectedCAGR'] ?? '';
description1Title = json['description1Title'] ?? '';
description1Content = json['description1Content'] ?? '';
description2Title = json['description2Title'] ?? '';
description2Content = json['description2Content'] ?? '';
fundedAmount = json['fundedAmount'] ?? '';
fundingTargetAmount = json['fundingTargetAmount'] ?? '';
name = json['name'] ?? '';
yearlyAppreciation = json['yearlyAppreciation'] ?? '';
assetId = json['assetId'] ?? '';
currentValue = json['currentValue'] ?? '';
totalShares = json['totalShares'] ?? '';
address = json['address'] ?? '';
shortDescription = json['shortDescription'] ?? '';
assetType = json['assetType'] ?? '';
assetImageIDList = json['assetImagePathList'] ?? '';
nameMn = json['nameMn'] ?? '';
addressMn = json['addressMn'] ?? '';
defaultCurrency = json['defaultCurrency'] ?? '';
expectedAnnualReturn = json['expectedAnnualReturn'] ?? '';
expected5YearReturn = json['expected5YearReturn'] ?? '';
openInvestment = json['openInvestment'] ?? '';
assetTypeDetailsID = json['assetTypeDetailsID'] ?? '';
prospectusEng = json['prospectusEng'] ?? '';
prospectusMn = json['prospectusMn'] ?? '';
openFund = json['openfund'] ?? false;
delisted = json['delisted'] ?? false;
secondaryAssetTypes = json["secondaryAssetTypes"] == null
? []
: List<String>.from(json["secondaryAssetTypes"].map((x) => x));
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data["\u0024id"] = this.id;
data['\$id'] = this.assetDocumentID;
data['description1TitleMn'] = this.description1TitleMn;
data['description1ContentMn'] = this.description1ContentMn;
data['description2TitleMn'] = this.description2TitleMn;
data['description2ContentMn'] = this.description2ContentMn;
data['availableShares'] = this.availableShares;
data['offeringSharePrice'] = this.offeringSharePrice;
data['offeringMinInvestment'] = this.offeringMinInvestment;
data['expectedHoldingPeriod'] = this.expectedHoldingPeriod;
data['expectedCAGR'] = this.expectedCAGR;
data['description1Title'] = this.description1Title;
data['description1Content'] = this.description1Content;
data['description2Title'] = this.description2Title;
data['description2Content'] = this.description2Content;
data['fundedAmount'] = this.fundedAmount;
data['fundingTargetAmount'] = this.fundingTargetAmount;
data['name'] = this.name;
data['yearlyAppreciation'] = this.yearlyAppreciation;
data['assetId'] = this.assetId;
data['currentValue'] = this.currentValue;
data['totalShares'] = this.totalShares;
data['address'] = this.address;
data['shortDescription'] = this.shortDescription;
data['assetType'] = this.assetType;
data['assetImagePathList'] = this.assetImageIDList;
data['nameMn'] = this.nameMn;
data['addressMn'] = this.addressMn;
data['defaultCurrency'] = this.defaultCurrency;
data['expectedAnnualReturn'] = this.expectedAnnualReturn;
data['expected5YearReturn'] = this.expected5YearReturn;
data['openInvestment'] = this.openInvestment;
data['assetTypeDetailsID'] = this.assetTypeDetailsID;
data['prospectusEng'] = this.prospectusEng;
data['prospectusMn'] = this.prospectusMn;
data['delisted'] = this.delisted;
data['secondaryAssetTypes'] = this.secondaryAssetTypes;
return data;
}
As a first step, I added a document list List documents = [] to the asset.dart file and created a new document class in asset_pdf_list.dart file.
The pdf file is directly from appwrite and I'm trying to put it in a document list and use ListView.builder to show the pdfs on the screen. I turned the above code into a widget like this below:
if (widget.asset.prospectusEng?.isNotEmpty ?? false)
AssetPdfList(widget: widget),
and incorporated the listView.builder into the previous padding() and came up with the following code.
class AssetPdfList extends StatelessWidget {
const AssetPdfList({
Key? key,
required this.widget,
}) : super(key: key);
final InvestAssetDetails widget;
@override
Widget build(BuildContext context) {
widget.asset.documents.add(Document(id: widget.asset.prospectusEng!, name: 'Full Prospectus'));
return ListView.builder(
itemCount: widget.asset.documents.length,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.only(left: 24, right: 24),
child: Row(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Material(
color: Colors.red,
child: InkWell(
borderRadius: BorderRadius.all(Radius.circular(4.0)),
onTap: () {
launchURL(widget.asset.documents[index].id);
},
child: Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 16.0),
child: SizedBox(
height: 38,
width: 26,
child: Icon(
FontAwesomeIcons.filePdf,
size: 36,
color: AppTheme.getTheme().primaryColor,
),
),
),
Text(
widget.asset.documents[index].name,
style: AppTheme.getTheme().textTheme.headline1,
),
],
),
),
),
),
],
),
);
},
);
}
}
I tried to add to the list a pdf using the following code:
widget.asset.documents.add(Document(id: widget.asset.prospectusEng!, name: 'Full Prospectus'));
However, somehow the widget is not showing up on the screen and I don't know why. here is the picture.
anyone can tell me why is this happening? I worked on this for like 4 hours, but still can't do it. Are there any other approaches I should be using?