I'm trying to find how could i can load network image in my Pdf. I have a list of details including an image urls. and i want to create the same list in a pdf with multiple pages.
So, i used pdf plugin to create the pages. All the details where loaded except the images. since the images should be downloaded from the server. The pdf pages are created with special widget elements (as like the flutter elements, but call with a prefix) and there is no FutureBuilder to manage the await functions.
Could anybody please help. I really stuck on this.
generatePdf(List<BhaiModel> bhaiList) async {
itemCount = 0;
List<BhaiModel> pageItems = [];
for (int i = 0; i < bhaiList.length; i++) {
if ((i + 1) % 5 == 0) {
pageItems.add(bhaiList[i]);
createPage(pageItems);
pageItems = [];
} else {
pageItems.add(bhaiList[i]);
if (i + 1 == bhaiList.length) {
createPage(pageItems);
}
}
}
final output = await getApplicationDocumentsDirectory();
final file = File("${output.path}/sample.pdf");
await file
.writeAsBytes(await pdf.save())
.then((value) => print("pdf saved"));
OpenFile.open("${output.path}/sample.pdf");
print(output.path);
}
createPage(List<BhaiModel> pageItems) async {
pdf.addPage(pw.Page(
pageFormat: PdfPageFormat.a4,
margin: const pw.EdgeInsets.all(30),
build: (pw.Context context) => pw.Column(
mainAxisAlignment: pageItems.length == 5
? pw.MainAxisAlignment.spaceEvenly
: pw.MainAxisAlignment.start,
children: pageItems.map((e) => customBhaiPdfItem(e)).toList())));
}
pw.Row customBhaiPdfItem(BhaiModel bhai) {
itemCount++;
final netImage = await networkImage(bhai.photo_url);
//THIS MAKE THE FUNCTION ASYNC
return pw.Row(children: [
pw.Container(
width: 530,
padding: const pw.EdgeInsets.all(8),
decoration: pw.BoxDecoration(border: pw.Border.all()),
child: pw.Row(mainAxisSize: pw.MainAxisSize.min, children: [
pw.Container(
color: const PdfColor(0.5, 0.5, 0.5),
width: 120,
height: 120,
child: pw.Image(netImage)),
pw.SizedBox(width: 20),
pw.Flexible(
child: pw.Container(
child: pw.Column(
mainAxisSize: pw.MainAxisSize.min,
crossAxisAlignment: pw.CrossAxisAlignment.stretch,
children: [
CustomRowText("No.", "$itemCount"),
CustomRowText("Name", "${bhai.first_name} ${bhai.last_name}"),
CustomRowText("Adhaar No.", bhai.adhaar_no),
CustomRowText("Mobile No.", bhai.mobile_no),
CustomRowText("Checkout At.",
bhai.last_checkout.replaceFirst('T', ' ').split('.')[0]),
CustomRowText("Address", bhai.address),
CustomRowText("City", bhai.city),
CustomRowText("State", bhai.state),
],
),
),
),
]),
),
]);
}
pw.Row CustomRowText(String label, String data) {
return pw.Row(children: [
pw.Expanded(
flex: 2,
child: pw.Text(label,
style: pw.TextStyle(fontWeight: pw.FontWeight.bold))),
pw.Expanded(flex: 7, child: pw.Text(data))
]);
}
trying to use some packages and for some reason they aren't working/I am getting a red underline on each of them. Any answer on why this could be happening? as well as if there is a solution that could be provided, that would be much appreciated! I am new to this all and still learning!
For this set of code, the ones that are underlined would be
the logger package, dio package, and units package.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:simple_gradient_text/simple_gradient_text.dart';
import '../utils/dreams_utils.dart';
class ResourcesPage extends StatefulWidget{
#override
_ResourcesPageState createState() => _ResourcesPageState();
}
class _ResourcesPageState extends State<ResourcesPage> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: GradientText('Sleep Resources',
style: TextStyle(fontSize: 30.0,),
colors: [colorStyle("gradient1"), colorStyle("gradient2"),
colorStyle("gradient3"), colorStyle("gradient2"),
colorStyle("gradient1")]
),
backgroundColor: colorStyle("appHeader"),
),
backgroundColor: colorStyle("appBackground"),
resizeToAvoidBottomInset: true,
body: Center(
child: ListView(
shrinkWrap: true,
children: <Widget>[
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/SleepF.jpeg",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('Sleep Foundation',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://www.sleepfoundation.org/sleep-hygiene/healthy-sleep-tips')
),
),
Text('We work hard to bring you the most accurate and up-to-date information about different sleep health topics. Rest assured every Sleep Foundation guide is carefully vetted and fact-checked prior to publication.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/IFFA.png",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('International Functional Foods Association',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://iffassociation.org/learn/how-functional-foods-may-improve-sleep-and-immune-health?gclid=Cj0KCQiAys2MBhDOARIsAFf1D1eHFvfuovsyweVETX8I5DOztdqM_QmIN_1DjOtkDNOiKlHIn9RN1bAaAhsLEALw_wcB')
),
),
Text('We exist to ensure everyone, everywhere has an equal chance to take control of their own health and wellness. Functional foods are an important component of healthy, nutritious diets. A diet rich in functional foods promotes a healthy body, as well as a healthy mind.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/Kaiser.png",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('Kaiser Permanente',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://healthengagement.kaiserpermanente.org/wellness-topics/sleep/')
),
),
Text('We help people reach their health goals, by listening, supporting and guiding, so they can live their best lives.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/JHM.jpeg",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('John Hopkins Medical',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://www.hopkinsmedicine.org/health/wellness-and-prevention/sleep')
),
),
Text('At Johns Hopkins Medicine, your health and safety are our very highest priorities. We are ready to care for you and your family in our hospitals, surgery centers, and through in-person clinic and online video visits. Learn how we are keeping you safe and protected so that you can get the care you need.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/BMI.png",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('Beautiful Mind International',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://beauty-mind.org/sleep-guru/?gclid=Cj0KCQiAys2MBhDOARIsAFf1D1czPDb4ROkA_dhket7YAZrPB9H7AK4OqEclcbTaiU_OgDq9odhQ7x8aAhz7EALw_wcB')
),
),
Text('Beautiful Mind International project aims to educate people what is mental health, its issues, and ways to overcome them.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/CDC.png",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('Centers for Disease Control and Prevention',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://www.cdc.gov/sleep/index.html')
),
),
Text('The Centers for Disease Control and Prevention is the national public health agency of the United States.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/sleepnum1.jpeg",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('Sleep Number',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://www.sleepnumber.com/categories/beds-on-sale?acid=psnonbrand&ascid=Google%2BNational-_-google-_-NB_Number_Bed-_-Number_Bed_Exact-_-516451220073-_-b-_-kwd-846217698-_-mediacode-_-Beds-_-1&key=number%20beds&s_kwcid=AL!6200!3!516451220073!b!!g!!number%20beds&k_clickid=go_cmp-193921164_adg-14393203044_ad-516451220073_kwd-846217698_dev-c_ext-_prd-&gclid=Cj0KCQiAys2MBhDOARIsAFf1D1d4C7oDgf9l_gikrEEVbK2Y7EpcHjg8AvPAmFGam3Qgjgc-XknDyYYaAtNfEALw_wcB')
),
),
Text('Sleep Number is an American manufacturer that makes the Sleep Number and Comfortaire beds, as well as foundations and bedding accessories. The company is based in Minneapolis, Minnesota. In addition to its Minnesota headquarters, Sleep Number has manufacturing and distribution facilities in South Carolina and Utah.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/sunset.jpeg",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('UMN Duluth Health Services',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://health-services.d.umn.edu/health-education/sleep-education-initiatives')
),
),
Text('Health Education Staff, Interns, and our previous student health advisory committee developed and administered an informal needs assessment to measure student reported barriers to sleep and methods for sleep support that students would use. We learned a lot and are putting that information into practice with a series of initiatives on campus.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
],
),
),
);
}
}
For this set of code, the ones that are underlined in red would be the
units package, dio package, and logger package.
import 'package:flutter/material.dart';
import 'package:units/dreams/utils/dreams_constant.dart';
import 'dart:math';
import 'package:shared_preferences/shared_preferences.dart';
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:logger/logger.dart';
import 'package:dio/dio.dart';
import "package:units/api.dart";
List<dynamic> calculator(double hour, double minute, double sleepHour, double
sleepMinute,
UnitType uniType, UnitType unitTypeTime) {
List result = new List.filled(3, null, growable: false);
double tempHour = 0.0;
double tempMinute = 0.00;
if(uniType == UnitType.BED) {
tempHour = hour + sleepHour;
tempMinute = minute + sleepMinute;
if (tempMinute >= 60) {
tempMinute -= 60;
tempHour += 1;
}
}
if (uniType == UnitType.WAKE) {
tempHour = hour - sleepHour;
tempMinute = minute - sleepMinute;
if(tempMinute < 0){
tempMinute += 60.00;
tempHour -= 1;
}
}
if(tempHour > 12 || tempHour < 0) {
switch(unitTypeTime) {
case UnitType.AM: { unitTypeTime = UnitType.PM; }
break;
case UnitType.PM: { unitTypeTime = UnitType.AM; }
break;
default: {}
break;
}
tempHour %= 12;
}
if(tempHour ==0){
tempHour = 12;
}
//result = tempHour + (tempMinute/100);
result[0] = (tempHour + (tempMinute/100));
result[1] = unitTypeTime;
result[2] = uniType;
return result;
}
bool isEmptyString(String string){
return string == null || string.length == 0;
}
Future<int> loadValue() async{
SharedPreferences preferences = await SharedPreferences.getInstance();
int? data = preferences.getInt('data');
if( data != null ) {
return data;
} else {
return 0;
}
}
void saveValue(int value) async{
SharedPreferences preferences = await SharedPreferences.getInstance();
preferences.setInt('data', value);
}
void setThemeKey(int color) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setInt('theme', color);
}
Future<int?> getThemeKey() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
final color = prefs.getInt('theme');
return color;
}
void setTheme(int theme){
switch(theme) {
case 1: { defaultTheme(); }
break;
case 2: { monochromeTheme(); }
break;
case 3: { pinkTheme(); }
break;
case 4: { sherbetTheme(); }
break;
case 5: { thunderTheme(); }
break;
case 6: { redTheme(); }
break;
case 7: { transTheme(); }
break;
case 8: { enbyTheme(); }
break;
default: { defaultTheme(); }
break;
}
}
Color mains = Colors.white60;
Color accent = Colors.cyan;
Color widgets = Colors.blueGrey.shade700;
Color gradient1 = Colors.cyan.shade900;
Color gradient2 = Colors.cyan.shade700;
Color gradient3 = Colors.cyan.shade500;
Color appHeader = Colors.blueGrey.shade900;
Color appBackground = Colors.blueGrey.shade800;
Future<int> defaultTheme() async {
mains = Colors.white60;
accent = Colors.cyan;
widgets = Colors.blueGrey.shade700;
gradient1 = Colors.cyan.shade900;
gradient2 = Colors.cyan.shade700;
gradient3 = Colors.cyan.shade500;
appHeader = Colors.blueGrey.shade900;
appBackground = Colors.blueGrey.shade800;
return 1;
}
Future<int> monochromeTheme() async {
mains = Colors.black;
accent = Colors.grey.shade700;
widgets = Colors.grey;
gradient1 = Colors.grey.shade700;
gradient2 = Colors.grey.shade500;
gradient3 = Colors.grey.shade300;
appHeader = Colors.grey.shade900;
appBackground = Colors.grey.shade800;
return 1;
}
Future<int> pinkTheme() async {
mains = Colors.pink.shade500;
accent = Colors.pink;
widgets = Colors.pink.shade200;
gradient1 = Colors.pinkAccent.shade700;
gradient2 = Colors.pinkAccent.shade400;
gradient3 = Colors.pinkAccent;
appHeader = Colors.pink.shade900;
appBackground = Colors.pink.shade800;
return 1;
}
Future<int> sherbetTheme() async {
mains = Colors.deepOrange;
accent = Colors.green.shade300;
widgets = Colors.yellow.shade100;
gradient1 = Colors.purpleAccent.shade400;
gradient2 = Colors.orangeAccent.shade100;
gradient3 = Colors.cyanAccent;
appHeader = Colors.pink.shade300;
appBackground = Colors.pink.shade100;
return 1;
}
Future<int> thunderTheme() async {
mains = Colors.yellow;
accent = Colors.yellowAccent;
widgets = Colors.grey.shade700;
gradient1 = Colors.cyan.shade500;
gradient2 = Colors.yellow.shade700;
gradient3 = Colors.yellow.shade200;
appHeader = Colors.grey.shade900;
appBackground = Colors.grey.shade800;
return 1;
}
Future<int> redTheme() async {
mains = Colors.red.shade900;
accent = Colors.red.shade900;
widgets = Colors.white70;
gradient1 = Colors.red.shade900;
gradient2 = Colors.red.shade700;
gradient3 = Colors.red.shade500;
appHeader = Colors.grey.shade500;
appBackground = Colors.grey.shade200;
return 1;
}
Future<int> transTheme() async {
mains = Colors.blue;
accent = Colors.pink;
widgets = Colors.white70;
gradient1 = Colors.lightBlue.shade200;
gradient2 = Colors.pinkAccent.shade100;
gradient3 = Colors.white;
appHeader = Colors.blue.shade800;
appBackground = Colors.pinkAccent.shade100;
return 1;
}
Future<int> enbyTheme() async {
mains = Colors.black;
accent = Colors.yellow.shade700;
widgets = Colors.white;
gradient1 = Colors.black;
gradient2 = Colors.yellow;
gradient3 = Colors.white;
appHeader = Colors.purple;
appBackground = Colors.purple.shade200;
return 1;
}
Color colorStyle(String color){
switch(color){
case "main":
return mains;
case "accent":
return accent;
case "widgets":
return widgets;
case "gradient1":
return gradient1;
case "gradient2":
return gradient2;
case "gradient3":
return gradient3;
case "appHeader":
return appHeader;
case "appBackground":
return appBackground;
default:
return Colors.purpleAccent;
}
}
This is the error code that I am getting
Invalid depfile: C:\Users\Mahjur - Coding\Desktop\SweetDreams-X.2.dart_tool\flutter_build\e98d11342ddd14555bbca12c2fd83e4a\kernel_snapshot.d
Invalid depfile: C:\Users\Mahjur - Coding\Desktop\SweetDreams-X.2.dart_tool\flutter_build\e98d11342ddd14555bbca12c2fd83e4a\kernel_snapshot.d
Error: Couldn't resolve the package 'logger' in 'package:logger/logger.dart'.
Error: Couldn't resolve the package 'dio' in 'package:dio/dio.dart'.
lib/dreams/utils/dreams_utils.dart:7:8: Error: Not found: 'package:logger/logger.dart'
import 'package:logger/logger.dart';
^
lib/dreams/utils/dreams_utils.dart:8:8: Error: Not found: 'package:dio/dio.dart'
import 'package:dio/dio.dart';
^
lib/dreams/utils/dreams_utils.dart:9:8: Error: Error when reading 'lib/api.dart': The system cannot find the file specified.
import "package:units/api.dart";
^
Here is my pubspec.yaml
name: units
description: A new Flutter project.
# The following line prevents the package from being accidentally
published to
# pub.dev using `pub publish`. This is preferred for private
packages.
publish_to: 'none' # Remove this line if you wish to publish to
pub.dev
# The following defines the version and build number for your
application.
# A version number is three numbers separated by dots, like
1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in
flutter
# build by specifying --build-name and --build-number,
respectively.
# In Android, build-name is used as versionName while build-
number used as versionCode.
# Read more about Android versioning at
https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while
build-number used as CFBundleVersion.
# Read more about iOS versioning at
#
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
shared_preferences: ^2.0.6
# The following adds the Cupertino Icons font to your
application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
firebase_core: ^1.13.1
firebase_auth: ^3.3.11
cloud_firestore: ^3.1.10
modal_progress_hud: ^0.1.3
firebase_messaging: ^11.2.11
firebase_analytics: ^9.1.2
flutter_launcher_icons: ^0.9.2
flutter_local_notifications: ^9.4.0
#flutter_native_timezone: ^1.1.0
rxdart: ^0.27.1
#awesome_notifications: ^0.6.21
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see
the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons
in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section,
like
this:
assets:
- lib/assests/images/
- android/app/src/main/res/drawable/
# -lib/dreams/images/app_icon.png
# An image asset can refer to one or more resolution-specific
"variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package
dependencies,
see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section
here,
# in this "flutter" section. Each entry in this list should
have a
# "family" key with the font family name, and a "fonts" key
with a
# list giving the asset and other descriptors for the font.
For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
run in the command line
flutter clean
then
flutter pub get
if that doesn't help, shut down and restart android studio and the file.
if that doesn't help delete the dependency from the pubspec.yaml run pub get, then re-add the dependency and run pub get, sometimes you have to hit flutter over the head with a hammer.
double check the packages you are having issues with are actually added in the pubspec.yaml and ensure there is not a # infront of them that comments them out
I'm using a listview to display images and text in my flutter app. I've stored the asset path and text in a Json file and I convert it to a list. Getting the image asset path and displaying the correct one seems to work with no issues but thats not the case in playing the audio files from their assets.
I'm using this package import 'package:assets_audio_player/assets_audio_player.dart';
declaration final AssetsAudioPlayer playAudio = AssetsAudioPlayer();
and this is main widget
#override
Widget build(BuildContext context) {
Widget _buildRow(int idx) {
for (var translations in widget.category.translations) {
_wordList = widget.category.translations[idx];
return Container(
height: 88.0,
child: Card(
child: ListTile(
onTap: () {
playAudio.open(
Audio(_wordList.audio),
);
// player.play(_wordList.audio);
log(_wordList.audio, name: 'my.other.category');
},
onLongPress: () {},
leading: SizedBox(
width: 50.0,
height: 88.0,
child: Image(
image: AssetImage(_wordList.emoji),
fit: BoxFit.contain,
),
),
title: Text(
_wordList.akan,
style: TextStyle(fontSize: 18),
),
subtitle: Text(
_wordList.english,
style: TextStyle(fontSize: 18, color: Colors.black),
),
trailing: const Icon(Icons.play_arrow, size: 28),
),
),
);
}
}
Since the image assets in the json file have no issues I don't get why the audio does
I've stored them like this,
{
"english": "mother",
"akan": "ɛna",
"emoji": "assets/icons/family_mother.png",
"audio": "assets/audio/family_mother.mp3"
},
Solved it by generating a new listtile widget through iteration and then putting it into a listview
I was trying to pass a list inside CupertinoPicker using loops but I couldn't figure it
this image contains the function I was trying to build
const List<String> currenciesList = [
'AUD',
'BRL',
'CAD',
'CNY',
'EUR',
'GBP',
'HKD',
'IDR',
'ILS',
'INR',
'JPY',
'MXN',
'NOK',
];
Container(
height: 150.0,
alignment: Alignment.center,
padding: EdgeInsets.only(bottom: 30.0),
color: Colors.lightBlue,
child:CupertinoPicker(
backgroundColor: Colors.lightBlue,
itemExtent: 32.0,
onSelectedItemChanged: (selectedIndex){
print(selectedIndex);
}, children:[
Text('USD',style: whiteColor ),
Text('EUR' , style: whiteColor),
Text('GDP', style:whiteColor),
]
),
),
As of Dart 2.3 you can use Collection For:
CupertinoPicker(
children:[
for (String name in currenciesList) Text( name ,style: whiteColor ),
]
)
You should create a Func to get all value in your list.
List<Widget> getPickerItems() {
List<Text> itemsCurrency = [];
for (var currency in currenciesList) {
itemsCurrency.add(Text(currency));
}
return itemsCurrency;
}
and add it in to children of CupertinoPicker:
CupertinoPicker(
children: getPickerItems(),
)
I want to make a dynamic table with list contents. I am not able to map the array list with the List type of table data. I am not getting table in PDF and instead it's showing me an error.
This is my PDF code:
goTocreatePdf(context,AllTranList) async {
final Document pdf = Document();
pdf.addPage(MultiPage(
pageFormat:
PdfPageFormat.letter.copyWith(marginBottom: 1.5 * PdfPageFormat.cm),
crossAxisAlignment: CrossAxisAlignment.start,
header: (Context context) {
if (context.pageNumber == 1) {
return null;
}
return Container(
alignment: Alignment.centerRight,
margin: const EdgeInsets.only(bottom: 3.0 * PdfPageFormat.mm),
padding: const EdgeInsets.only(bottom: 3.0 * PdfPageFormat.mm),
decoration: const BoxDecoration(
border:
BoxBorder(bottom: true, width: 0.5, color: PdfColors.grey)),
child: Text('Report',
style: Theme.of(context)
.defaultTextStyle
.copyWith(color: PdfColors.grey)));
},
footer: (Context context) {
return Container(
alignment: Alignment.centerRight,
margin: const EdgeInsets.only(top: 1.0 * PdfPageFormat.cm),
child: Text('Page ${context.pageNumber} of ${context.pagesCount}',
style: Theme.of(context)
.defaultTextStyle
.copyWith(color: PdfColors.grey)));
},
build: (Context context) => <Widget>[
Header(
level: 0,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('TRANSACTION LIST', textScaleFactor: 2),
PdfLogo()
])),
Header(level: 1, text: 'What is Lorem Ipsum?'),
Table.fromTextArray(context: context, data: <List<String>>[
<String>[ 'TRANSACTION_AMOUNT No', 'CUSTREF_ID',
'REMARKS','PAYEE_VIR_ID','PAYER_VIR_ID'],
...AllTranList.map(
(item) => [item.TRANSACTION_AMOUNT,
item.CUSTREF_ID,item.REMARKS,item.PAYEE_VIR_ID,item.PAYER_VIR_ID])
]),
//save PDF
final String dir = (await getApplicationDocumentsDirectory()).path;
final String path = '$dir/report.pdf';
Dio dio = new Dio();
final File file = File(path);
await file.writeAsBytes(pdf.save());
material.Navigator.of(context).push(
material.MaterialPageRoute(
builder: (_) => PdfViewerPage(path: path),
),
);
}
Also I am not able to save PDF in the external storage.
This is the AllTransitList that I am mapping:
[{TRANSACTION_AMOUNT: 1.00,
CUSTREF_ID: 001819655570,
CREATED_ON: 2020-01-18T19:55:40.412Z,
REMARKS: SUCCESS,
RESPONSE: SUCCESS,
PAYEE_VIR_ID: navyabj#fbl,
PAYER_VIR_ID: abinthomas0073#oksbi},
{TRANSACTION_AMOUNT: 1.00,
CUSTREF_ID: 002218989414,
CREATED_ON: 2020-01-22T18:12:13.500Z,
REMARKS: SUCCESS,
RESPONSE: SUCCESS,
PAYEE_VIR_ID: navyabj#fbl,
PAYER_VIR_ID: abinthomas0073#oksbi},
{TRANSACTION_AMOUNT: 30.00,
CUSTREF_ID: 002218162602,
CREATED_ON: 2020-01-22T18:13:12.835Z,
REMARKS: SUCCESS,
RESPONSE: SUCCESS,
PAYEE_VIR_ID: navyabj#fbl,
PAYER_VIR_ID: aju#federal},
{TRANSACTION_AMOUNT: 36.00,
CUSTREF_ID: 002219179966,
CREATED_ON: 2020-01-22T19:23:21.377Z,
REMARKS: SUCCESS,
RESPONSE: SUCCESS,
PAYEE_VIR_ID: navyabj#fbl,
PAYER_VIR_ID: aju#federal}]
see this library.
you can create pdf with this library :
https://pub.dev/packages/pdf
i hope it's useful