I would like to show an image from firebase with syncfusion_flutter_pdf but I couldn't do it. I used exact same code block from official documentation but it didn't help me too.
The documentation gives the code below but there are no spesific way for Network image or something
Can anyone have an idea
Easiest way to use flutter printing package flutter printing
const imageProvider = const NetworkImage('https/image.png');
final image = await flutterImageProvider(imageProvider);
doc.addPage(pw.Page(
build: (pw.Context context) {
return pw.Center(
child: pw.Image(image),
); // Center
})); // Page
Related
I did to make a simple pokedex application for trying myself. I completed my project and I did not get any issue in android studio.Other hand, When I started my application, I cant see images to get in my project in emulator. Can anyone help me for this issue .
Can look at this extension.
https://github.com/AlejandroTaichu/Pokedex.git
I want to see images in my project when I was opened my project.I am new on programming so I cant fix that.
You have forgotten extension of image in your code
child: Image.asset("images/${pokemon.name}")),
Change to below code
child: Image.asset("images/${pokemon.name}.png")),
Or add image extension(.png) in names of pokeList
You need to change the image name(path) according to the assets image path include the image type.
Next you need to create a future and call future on Future Builder widget.
late final future = callPokemon();
class _PokemonHomepageState extends State<PokemonHomepage> {
Future<List<Pokemons>> callPokemon() async {
var pokeList = <Pokemons>[];
var p1 = Pokemons(pokeId: 1, name: "Charmender.png", health: 100, power: 250);
var p2 = Pokemons(pokeId: 2, name: "squirtle.png", health: 150, power: 300);
var p3 = Pokemons(pokeId: 3, name: "balbazar.png", health: 300, power: 500);
pokeList.add(p1);
pokeList.add(p2);
pokeList.add(p3);
return pokeList;
}
late final future = callPokemon();
#override
Widget build(BuildContext context) {
return Scaffold(
appBar:
AppBar(title: const Text("POKEDEX"), backgroundColor: Colors.green),
body: FutureBuilder<List<Pokemons>>(
future: future,
builder: (context, snapshot) {
Made a pr on git, you can merge it
I suggest you to use flutter_gen (https://pub.dev/packages/flutter_gen) for assets. I recently found this package & its really helpful when using multiple images from assets.
With flutter_gen you can just setup few things one time & you can directly get image widgets from this package.
Setup flutter_gen
dart pub global activate flutter_gen
Add these runners in your dev dependencies
dev_dependencies:
build_runner:
flutter_gen_runner:
Setup path of generated assets file
flutter_gen:
output: lib/generated/
There are many options in this step. You can check their documentation.
Set image folder path
assets:
- assets/images/
Put your images in the path added
After doing these steps you just need to run
flutter packages pub run build_runner build
This file will generate an assets file name assets.gen.dart inside the lib/generated folder as we setup in step 3.
Note that you have to run this command whenever you change folder name or images to regerenated the assets.gen.dart
Thats it.
When you are done with these steps, you can directly get the images from this assets.gen.dart file like this
import 'package:flutter_boilerplate/generated/assets.gen.dart';
Padding(
padding: const EdgeInsets.all(20),
child: SizedBox(
height: 200, child: Assets.images.cat1.image(width: 200),
),
),
The plus benefit is that these assets provided widget support intellisense, so there is no chance for spelling mistake. Plus you directly get a widget from this with all the properties of default Image widget.
It also supports advance image types like svg, lottie, flare as well.
I have a game a bit like Wordle, and I want to add a share capability much like Wordle does. I have a flag on my game grid widget which allows me to render the normal displayed version, or a special version for sharing. I'd like to use the widget to get a PNG file (or PNG byte data). I'd prefer to not actually draw this to the screen, just render it to some framebuffer and convert to PNG, although rendering to the screen is okay if the alternative is not possible. Looking through the docs, its not obvious whether what I am trying to do is possible or even makes sense (it seems I probably have to get the widget instantiated as an element and then get a render object, which seems to imply having to put it in my layout and draw it to the display), but maybe I am missing something. Is there a way to do this?
You might want to look at flutter's screenshot package.
A simple package to capture widgets as Images. Now you can also capture the widgets that are not rendered on the screen!
1. Create Instance of Screenshot Controller
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
Uint8List _imageFile;
//Create an instance of ScreenshotController
ScreenshotController screenshotController = ScreenshotController();
#override
void initState() {
// TODO: implement initState
super.initState();
}
...
}
2. Wrap the widget that you want to capture inside Screenshot Widget. Assign the controller to screenshotController that you have created earlier
Screenshot(
controller: screenshotController,
child: Text("This text will be captured as image"),
),
3. Take the screenshot by calling capture method. This will return a Uint8List
screenshotController.capture().then((Uint8List image) {
//Capture Done
setState(() {
_imageFile = image;
});
}).catchError((onError) {
print(onError);
});
Extra: Saving images to Specific Location
final directory = (await getApplicationDocumentsDirectory ()).path; //from path_provide package
String fileName = DateTime.now().microsecondsSinceEpoch;
path = '$directory';
screenshotController.captureAndSave(
path //set path where screenshot will be saved
fileName:fileName
);
Refer this example
I was once working on an app in which I needed something similar. After searching for a while I found a package named 'screenshot'
This package lets you convert both visible or invisible widgets to an image.
Here is the sample code from their document
ScreenshotController screenshotController = ScreenshotController();
function createScreenshot(){
screenshotController
.captureFromWidget(Container(
padding: const EdgeInsets.all(30.0),
decoration: BoxDecoration(
border: Border.all(color: Colors.blueAccent, width: 5.0),
color: Colors.redAccent,
),
child: Text("This is an invisible widget"),
),
).then((capturedImage) {
// Here you will get image object
});
}
Problem: One of screen in my app has bunch of network images that are being fetched from an API. When user navigates to that screen some images load faster than others, hence users sees a screen that is not fully loaded.
Expected behaviour: I want to show a CircularProgressIndicator until all the network images are fully loaded.
P.S. Below code doesn't do what I wanted, as it executes the function while images are still loading.
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) => yourFunction(context));
}
Also I am using SvgPicture.network from flutter_svg package.
final Widget networkSvg = SvgPicture.network(
'https://site-that-takes-a-while.com/image.svg',
semanticsLabel: 'A shark?!',
placeholderBuilder: (BuildContext context) => Container(
padding: const EdgeInsets.all(30.0),
child: const CircularProgressIndicator()),
);
Maybe this could help Flutter image preload
I want to generate PDF files including self drawn graphics within a Flutter App. Of course with the pdf library provided it is quite simple to show a pdf preview containing for example two text lines, but i want to be able to insert some graphics that i want to draw myself, as i need to draw (myself)some very unconventional graphs. In order to do that i need to be able to draw within a pdf widget (some lines, curves, points, of several colors, etc...). As per now i didn't manage to even draw a point !!!, the pdf library of flutter dart describes dozens of methods, but doesn't show any example, that's a pitty in fact. Is there somebody who could help me in order to "draw" graphics within PDF Dart Flutter Object. The PdfLibrary includes PdfGraphics class that is supposed to have the methods i try tu use without success !!
Many thank's in advance
Please find my code :
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:printing/printing.dart';
void main() => runApp(const MyApp('Ceci est mon premier PDF'));
class MyApp extends StatelessWidget {
const MyApp(this.title);
final String title;
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text(title)),
body: PdfPreview(
build: (format) => _generatePdf(format, title),
),
),
);
}
Future<Uint8List> _generatePdf(PdfPageFormat format, String title) async {
final pdf = pw.Document();
pdf.addPage(
pw.Page(
pageFormat: format,
build: (context) {
return pw.Center(
child: pw.Column (
children: [
pw.Text(title),
pw.Text(title),
//pw.drawBox(10,10,100,100), <---- if i remove the comment the app
crashes saying "Method not found"
otherwise i have a PDF generated with two
lines of text, and i want that just under a
self drawn graphic could be displayed
],
),
);//pw.Text(title),
},
),
);
return pdf.save();
}
}
You have to use the CustomPaint class instead of just drawing directly.
Try
pw.CustomPaint(
size: const PdfPoint(110, 110),
painter: (PdfGraphics canvas, PdfPoint size) {
canvas
..setColor(PdfColors.indigo)
..drawRect(10, 10, 100, 100)
..fillPath();
},
);
instead of
pw.drawBox(10,10,100,100)
Check out the list of drawable shapes here: https://pub.dev/documentation/pdf/latest/pdf/PdfGraphics-class.html
For those looking for more information
(pdf's) CustomPaint expects a child and one or two painter functions. Unlike Flutter's CustomPaint
this uses a PdfGraphics instead of a Canvas
the painting functions are functions not CustomPainters
I struggled for days to figure this out and found my answer on this comment: https://github.com/DavBfr/dart_pdf/issues/145#issuecomment-530798498
I need to add the overlay above the camera like rectangle box and need to save the image to gallery
Tried the basic flutter camera exampleenter image description here
If you are not too worried about limiting the image resolution to the phone's display resolution, you can opt to automatically take a screenshot of the display and save it.
For this to work, you'll need Flutter native_screenshot package.
Capturing the screenshot:
Future<void> takeScreenShot() async{
String path = await NativeScreenshot.takeScreenshot();
print(path);
}
The image will be saved in the folder indicated by the path.
Since the function captures the whole screen, you can use a Stack() widget to display your camera preview and the overlay on top of each other. A simple build would look like,
#override
Widget build(BuildContext context) {
if (controller == null || !controller.value.isInitialized) {
return Container();
}
return OverflowBox(
child: Stack(
children: <Widget>[
CameraPreview(controller),
Container(),
],
),
);
}
In the above code you'll need to initialize the camera controller in order to display the CamerarPreview(). You can edit the Container() child widget (or anything similar to that) to create your overlay box.