I have two problems with the url_launcher: ^5.7.10
First Problem:
When I try to send an email with html tag, on a real device, if I use Gmail application the body of my email is not well formated. I see the HTML tags. I tried with or without HTML5 doctype
Second Problem:
When I try to send an email with an Href tag the email body is cut at the equal sign.
My code is
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'URL Launcher',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'URL Launcher'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
Future<void> _sendMailHtml(String url) async {
if (await canLaunch(url)) {
await launch(
url
);
} else {
throw 'Could not launch $url';
}
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: ListView(
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
onPressed: () => setState(() {
_launched = _sendMailHtml('mailto:smith#example.org?subject=News&body=<h1>Header 1</h1><p>Paragraph</p>');
}),
child: const Text('Send Mail HTML'),
),
RaisedButton(
onPressed: () => setState(() {
_launched = _sendMailHtml('mailto:smith#example.org?subject=News&body=<h1>Header 1</h1><p>Paragraph</p>Link<p>End of mail</p>');
}),
child: const Text('Send Mail HTML With HREF'),
),
],
),
],
),
);
}
}
My pubspec.yaml is
name: flutter_app
description: A new Flutter application.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
url_launcher: ^5.7.10
cupertino_icons: ^1.0.0
dev_dependencies:
flutter_test:
sdk: flutter
# The following section is specific to Flutter.
flutter:
uses-material-design: true
I did not try with flutter 2 because my app is in production and I have some dependencies errors.
For the first problem if I try with another email app, I can see the good formatting.
On Android 10...
screenshots :
first problem on Gmail app
on other email app
Second problem with Gmail and anchor tag
The mailto body parameter only supports plaintext messages. See this question.
If you want you can check out the mailer package which has an interface for sending HTML emails, as shown in the linked page.
Related
Please I need assistance.
I have written below code to saved file selected from filepicker_windows to C: drive.
filepicker_windows worked well and it get my C: drive successfully But not saving the file.
It gives me ERROR "Exception has occurred.
NoSuchMethodError (NoSuchMethodError: Class 'String' has no instance getter 'bodyBytes'.
Receiver: "C:\Users\norak\OneDrive\Pictures\afdb\Capture.PNG"
Tried calling: bodyBytes)"
Below is my code, please help correct it.
pubspec.yaml File
name: file_manager
description: A new Flutter project.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
filepicker_windows: ^2.0.0
path_provider: ^2.0.1
provider: ^5.0.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
MAIN PAGE
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:filepicker_windows/filepicker_windows.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
Future<String> getPicturesPath() async {
Directory docDir = await getApplicationDocumentsDirectory();
var pathList = docDir.path.split('\\');
pathList[pathList.length - 1] = 'Pictures';
var picturePath = pathList.join('\\');
print(picturePath);
return picturePath;
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("File Management"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'Testing',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
final file = OpenFilePicker()
..filterSpecification = {'All Files': '*.*'}
..defaultFilterIndex = 0
..defaultExtension = 'doc'
..title = 'Select a document';
final result = file.getFile();
if (result != null) {
print(result.path);
saveImage(result.path, 'ik.jpg');
print("Saved");
}
},
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
void saveImage(imageData, String imageName) async {
var picturesPath = await getPicturesPath();
var thetaImage = await File(join(picturesPath, 'theta_images', imageName))
.create(recursive: true);
await thetaImage.writeAsBytes(imageData.bodyBytes);
}
}
await thetaImage.writeAsBytes(imageData.bodyBytes); //This is the line that is given error
Please advice
Why don't you debug your code? It's a string. That's why you got the error.
Change the code to:
await thetaImage.writeAsBytes(File(imageData).readAsBytesSync());
> final directory = await getApplicationDocumentsDirectory();
final path = directory.path;
final file = File(path);
Hello everyone and happy new year.
I am a beginner with flutter and dart an I have an issue on flutter whenever I add charts_flutter in my pubspec.yaml dependencies.
I tried running flutter clean, look out for the others topics with this kind of issue, and changed the Flutter SDK environment but it didn't work.
main.dart
import 'package:flutter/material.dart';
import 'package:charts_flutter/flutter.dart' as charts;
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => new _MyHomePageState();
}
class ClicksPerYear {
final String year;
final int clicks;
final charts.Color color;
ClicksPerYear(this.year, this.clicks, Color color)
: this.color = new charts.Color(r: color.red, g: color.green, b: color.blue, a: color.alpha);
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
#override
Widget build(BuildContext context) {
var data = [
new ClicksPerYear('2016', 12, Colors.red),
new ClicksPerYear('2017', 42, Colors.yellow),
new ClicksPerYear('2018', _counter, Colors.green),
];
var series = [
new charts.Series(
domainFn: (ClicksPerYear clickData, _) => clickData.year,
measureFn: (ClicksPerYear clickData, _) => clickData.clicks,
colorFn: (ClicksPerYear clickData, _) => clickData.color,
id: 'Clicks',
data: data,
),
];
var chart = new charts.BarChart<ClicksPerYear>(
series,
animate: true,
);
var chartWidget = new Padding(
padding: new EdgeInsets.all(32.0),
child: new SizedBox(
height: 200.0,
child: chart,
),
);
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text('You have pushed the button this many times:',
),
new Text('$_counter',
style: Theme.of(context).textTheme.display1,
),
chartWidget,
],
),
),
floatingActionButton: new FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: new Icon(Icons.add),
),
);
}
}
pubspec.yaml
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
charts_flutter: ^0.2.0
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
And these are the error messages:
Running "flutter pub get" in chat...
The current Dart SDK version is 2.8.0-dev.0.0.flutter-aa6709974d.
Because chat depends on charts_flutter >=0.0.1+1 <0.4.0 which requires SDK version >=1.23.0 <2.0.0, version solving failed.
pub get failed (1; Because chat depends on charts_flutter >=0.0.1+1 <0.4.0 which requires SDK version >=1.23.0 <2.0.0, version solving failed.)
exit code 1
What went wrong?
You are adding an outdated version of the charts_flutter plugin which relies on an older version of the Flutter SDK.
What can you do?
In your pubspec.yaml, replace:
charts_flutter: ^0.2.0
With
charts_flutter: ^0.8.1
Why am I encountering this issue?
Because chat depends on charts_flutter >=0.0.1+1 <0.4.0 which requires SDK version >=1.23.0 <2.0.0, version solving failed. pub get failed (1; Because chat depends on charts_flutter >=0.0.1+1 <0.4.0 which requires SDK version >=1.23.0 <2.0.0, version solving failed.) exit code 1
As seen in the logs, charts_flutter v0.2.0 requires Flutter SDK >=1.23.0 <2.0.0. In your case, it's currently using Flutter SDK version >=2.1.0 <3.0.0.
pubspec.yaml
environment:
sdk: ">=2.1.0 <3.0.0"
Just run flutter upgrade in your terminal to upgrade flutter to the latest stable version. You can read this upgrading flutter
I am building a form that includes fields for notes. I want the user to be able to hit enter/return and start a new paragraph.
I am able to create a field that will accept and display large amounts of text. But I specifically want the user to be able to create paragraphs, otherwise their notes are just one long string with no breaks making it hard to read and edit.
I filed an issue here, but was told that I just need to do something like this.
This does not do want I want. I am trying to do something like this.
It looks like this should be possible (https://github.com/flutter/flutter/issues/43935). I don't know what I'm missing.
I am building for web, not iOS or Android.
main.dart:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) =>Scaffold(
body: Center(
child: Center(
child:TextFormField(
textInputAction: TextInputAction.newline,
keyboardType: TextInputType.multiline,
maxLines: 10,
),
),
),
);
}
pubspec.yaml:
name: textformfield_demo
description: A new Flutter project.
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
There is a property of flutter to set max and min line. You can set maxLine:(int) Or maxLine: null, here maxLine:(int) restrict user to (int) number of line and maxLine: null will provide new line text without limit.
As-
class MultiLineEt extends StatefulWidget {
#override
State<StatefulWidget> createState() {
return _MyHomePageState();
}
}
class _MyHomePageState extends State<MultiLineEt> {
#override
Widget build(BuildContext context) =>Scaffold(
body: ListView(children: <Widget>[
new TextField(
keyboardType: TextInputType.multiline,
maxLines: null,
),
],
) );
}
Using ListView to prevent from pixels error
I'm just experimenting with Flutter for the past couple of days. I am trying to add an image but it won't show up at all.
Am I missing something obvious?
main.dart
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) {
return MaterialApp(
title: 'PicHuntingNigga',
home: Scaffold(
appBar: AppBar(
title: Text('PicHunting-Nigga'),
centerTitle: true,
backgroundColor: Colors.red,
),
body: new Center(
child: new MyCameraWidget(),
),
),
);
}
}
class MyCameraWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
var assetImage = new AssetImage('assets/images/camera1.png');
var image = new Image(image: assetImage, width: 225.0, height: 225.0);
return new Container(child: image);
}
}
and my pubspec.yaml
name: flutter_app
description: A new Flutter application.
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- assets/images/camera.png
- assets/images/camera1.png
- assets/images/
My folder structure
After I run the emulator - everything shows up minus the picture.I can replace the image with child: Text('asdasdasda'), and it will render the text but not the image.
Also see this example here https://flutter.dev/docs/development/ui/assets-and-images
Widget build(BuildContext context) {
// ...
return DecoratedBox(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/background.png'),
// ...
),
// ...
),
);
// ...
}
So I solved it!
Not sure how....I just turned off my laptop and then turned it on. I also had dinner and now it's working.
So if you're stuck with a similar issue - have dinner? that seemed to have been the solution for me.
Error says:
NoSuchMethodError: The getter 'length' was called on null
It is a basic flutter music player App.
main.dart
import 'package:flute_music_player/flute_music_player.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
List<Song> _songs;
#override
void initState() {
// TODO: implement initState
super.initState();
initPlayer();
}
void initPlayer() async{
var songs = await MusicFinder.allSongs();
songs=new List.from(songs);
setState(() {
_songs = songs;
});
}
#override
Widget build(BuildContext context) {
Widget home(){
new Scaffold(
appBar: new AppBar(title: new Text("Music App"),
),
body: new ListView.builder(
itemCount: _songs.length,
itemBuilder: (context,int index){
return new ListTile(
leading: new CircleAvatar(
child: new Text(_songs[index].title[0]),
),
title: new Text(_songs[index].title),
);
}),
);
}
return new MaterialApp(
home: home(),
);
}
}
pubspec.yaml
name: music_player
description: A new Flutter application.
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
flute_music_player:
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
It should show the list of musics as result but gives an unexpected error.I am running on android.Plz help me out.
It should show the list of musics as result but gives an unexpected error.I am running on android.Plz help me out.
Change itemCount: _songs.length to itemCount: _songs?.length ?? 0 - it helps to avoid exception
Since you're performing an async operation, that would take certain amount of time so when your app first builds, the songs array is null. Try to start with an empty array instead of a null array: List<Song> _songs = []; then, when the async operation is completed the setState will make the widget to rebuild and show the array with data.