Tried to use both NetworkImage and Image.network() methods to load jpg image from the Web, in both cases it says that there is "ImageCodecException" and it's "Fialed to load network image". Tried in DartPad.
This code:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body:
// Load image from network
new Image.network(
'https://www.nasa.gov/images/content/162056main_PIA08329.jpg'),
),
);
}
}
At first try to wrap your Image.network to Center or something to align Image and the second one is check your url that you provide, you need to provide actual path for that just click to image and simply select "copy image adress" and put it in url. You can also check how to do it here - https://youtu.be/Ln2xvLs6dc4
Related
Guys I'm using file_picker to get files from the device. I use open_file to display the file. Is there any way to get the number of pages from the file? I have already seen the possibility with .pdf, but I would like to get from .docs as well.
Try Flutter FileReader
https://pub.dev/packages/flutter_filereader
A local file view widget,Support a variety of file types, such as Doc Eexcl PPT TXT and so on,Android is implemented by Tencent X5,iOS is implemented by WKWebView
import 'package:flutter/material.dart';
import 'package:flutter_filereader/flutter_filereader.dart';
class FileReaderPage extends StatefulWidget {
final String filePath;
FileReaderPage({Key: Key, this.filePath});
#override
_FileReaderPageState createState() => _FileReaderPageState();
}
class _FileReaderPageState extends State<FileReaderPage> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("doc"),
),
body: FileReaderView(
filePath: widget.filePath,
),
);
}
}
OR open_document
Opening pdf, xlsx, docs, ppt and zip files #
https://pub.dev/packages/open_document
Currently in the company where I work, they are using Flutter, before I created the animations in After Effects, created a JSON and sent it to the developers. Now, I need to find a way in which After Affects talks to FLUTTER.
Use the lottie package. Add your JSON as an asset or host it somewhere. Then you can follow the example code(shown below) to display it.
import 'package:flutter/material.dart';
import 'package:lottie/lottie.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: ListView(
children: [
// Load a Lottie file from your assets
Lottie.asset('assets/LottieLogo1.json'),
// Load a Lottie file from a remote url
Lottie.network(
'https://raw.githubusercontent.com/xvrh/lottie-flutter/master/example/assets/Mobilo/A.json'),
// Load an animation and its images from a zip file
Lottie.asset('assets/lottiefiles/angel.zip'),
],
),
),
);
}
}
Actually , i need a camera where after capturing a picture i can draw anything on that picture and save it.For that i already build a camera using camera plugin and custom paint . So now i want to merge this two. I am really confused about this matter. How can i do this ?
Here is my main.dart:
import 'package:flutter/material.dart';
import 'package:flutter_better_camera/new/src/support_android/camera.dart';
import 'package:painter_demo/camera.dart';
import 'package:painter_demo/painting.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Camera App',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Draw(),
);
}
}
Here i called the drawing class but i want to show over camera How can i do this ?
First, put your camera view and custom paint(or image from your assets) in Stack, and there are 2 approaches for image generation:
Capture your picture with camera shot, merge camera image and your custom paint (or asset image) with this package, image, with this function:
Image copyInto(Image dst, Image src, {int dstX, int dstY, int srcX, int srcY, int srcW, int srcH, bool blend = true});
Copy an area of the src image into dst.
Returns the modified dst image.
Make a custom button for screenshot (not camera shutter button), and follow the demo for screen shooting the Stack widget, screenshot
When removing system overlays with SystemChrome.setEnabledSystemUIOverlays([]) the app does not expand to fill the screen.
Complete main.dart file:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setEnabledSystemUIOverlays([]);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Container(
color: Colors.red,
),
);
}
}
Without SystemChrome.setEnabledSystemUIOverlays([]):
Flutter version: 1.22.2
I'm unable to reproduce with Flutter 1.22(stable) but in https://github.com/flutter/flutter/issues/14432 people seem to have had good results with
setting Scaffold.resizeToAvoidBottomPadding to true.
You can also try to update Flutter and/or changing channels. Perhaps even trying on a physical device.
Hot reload is not working in a simple Hello World example. When trying to change the text, a string, to something else under run-time and hot reload it, nothing happens. I'm debugging on a physical device and I'm using VSCode.
import 'package:flutter/material.dart';
void main() {
String text = "Hello world";
runApp(Center(child: new Text(text, textDirection: TextDirection.ltr)));
}
Is hot reload not reliable or am i doing something wrong here?
EDIT: Found out that restarting the app, CTRL+SHIFT+F5, worked as the hot reload should.
Specifically, a hot reload causes all the existing widgets to rebuild. Only code involved in the rebuilding of the widgets are automatically re-executed.
https://flutter.dev/docs/development/tools/hot-reload
This means that you need a widget class which implements the build method to ensure the code is going to be re-executed on a hot reload.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
String text = "Hello world";
return Center(
child: new Text(text, textDirection: TextDirection.ltr),
);
}
}
If you create your class like this i think there are no problems :
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
String text="Hello World"
return MaterialApp(
home: Scaffold(
body: Center(
child: Text(text,textDirection: TextDirection.ltr),
)));
}
}
A few types of code changes cannot be hot reloaded though:
Global variable initializers
Static field initializers
The main() method of the app
For these changes you can fully restart your application, without having to end your > debugging session:
Don’t click the Stop button; simply re-click the Run button (if in a run session) or Debug button (if in a debug session), or shift-click the ‘hot reload’ button.
Found this on the Flutter developer portal.