mobile flutter application, NFC does not start session - android

i am using the nfc_manager pack age: https://pub.dev/packages/nfc_manager
so once my app reaches the " NfcManager.instance.startSession " part( third code line ) it just skips over it and moves on, I do not know what is causing this, the app does not crash or anything it just never works, can anybody who has worked in NFC before help?
if (scannedFingerprint!) {
//context.pushNamed('STAttendance2');
NfcManager.instance.startSession (onDiscovered: (NfcTag tag) async {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'NFC reader is Listing!!!!!',
style: TextStyle(
color: FlutterFlowTheme.of(context)
.primaryText,
),
),
duration: Duration(milliseconds: 8000),
backgroundColor: Color(0x00000000),
),
);
result.value = tag.data;
if (result.value != null){
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'Scan is Successful!! Finally: ' + result.value,
style: TextStyle(
color: FlutterFlowTheme.of(context)
.primaryText,
),
),
duration: Duration(milliseconds: 8000),
backgroundColor: Color(0x00000000),
),
);
NfcManager.instance.stopSession();
}
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'HOME PAGE!!!!',
style: TextStyle(
color: FlutterFlowTheme.of(context)
.primaryText,
),
),
duration: Duration(milliseconds: 8000),
backgroundColor: Color(0x00000000),
),
);
}

Related

ShowDialog did not pop out

i have created global method that call showDialog, whenever i call it, it wont come out if i put Navigator.pop(context) , if i remove the navigator it will come out. I cannot close the errordialog if i dont have the navigator. Did i do something wrong? below is my code
class GlobalMethod {
static void showErrorDialog(
{required String error, required BuildContext ctx}) {
showDialog(
context: ctx,
builder: (context) {
return AlertDialog(
title: Row(children: [
Padding(
padding: EdgeInsets.all(8.0),
child: Icon(
Icons.logout,
color: Colors.grey,
size: 35,
),
),
Padding(
padding: EdgeInsets.all(8.0),
child: Text('Error Occured'),
),
]),
content: Text(error,
style: TextStyle(
color: Colors.black,
fontSize: 20,
fontStyle: FontStyle.italic)),
actions: [
TextButton(
onPressed: () {
Navigator.canPop(context) ? Navigator.canPop(context) : null;
},
child: Text(
'Okay',
style: TextStyle(
color: Colors.red,
),
),
)
],
);
});
}
This is example when i call the method. If i remove the Navigator.pop the error dialog will pop out, if i put the navigator.pop nothing will come out
else if (balance < price! ){
GlobalMethod.showErrorDialog(error: "you dont have enough balance , please top up first", ctx: context);
Navigator.pop(context);
}
You need to remove Navigator after the showErrorDialog:
else if (balance < price! ){
GlobalMethod.showErrorDialog(error: "you dont have enough balance , please top up first", ctx: context);
}
then change this in your showErrorDialog:
onPressed: () {
Navigator.canPop(context) ? Navigator.pop(context): null;
},
you are use canPop but you need to use pop for navigation, canPop just return you a bool result.
For the pop use Navigator.pop(context)
class GlobalMethod {
static void showErrorDialog(
{required String error, required BuildContext ctx}) {
showDialog(
context: ctx,
builder: (context) {
return AlertDialog(
title: Row(children: [
Padding(
padding: EdgeInsets.all(8.0),
child: Icon(
Icons.logout,
color: Colors.grey,
size: 35,
),
),
Padding(
padding: EdgeInsets.all(8.0),
child: Text('Error Occured'),
),
]),
content: Text(error,
style: TextStyle(
color: Colors.black,
fontSize: 20,
fontStyle: FontStyle.italic)),
actions: [
TextButton(
onPressed: () {
Navigator.canPop(ctx) ? Navigator.pop(context) : null;
},
child: Text(
'Okay',
style: TextStyle(
color: Colors.red,
),
),
)
],
);
});
}
}
Remove pop
else if (balance < price! ){
GlobalMethod.showErrorDialog(error: "you dont have enough balance , please top up first", ctx: context);
}

launch a button(url) and then open browser in flutter

I want when the Sign Up is clicked, the browser be open and go to my website but i dont know how to do that.
here is my code, when i tap on Sign Up it doesn't work:
return Container(
child: GestureDetector(
onTap: () => launch("https://my.drclubs.ir/"),
child: RichText(
text: TextSpan(
children: [
TextSpan(
text: "Don\`t have an Account?",
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w500),
),
TextSpan(
text: "Sign Up",
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold),
),
],
),
),
),
);
}
You can use a package called url_launcher here.
Example:
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
const _url = 'https://flutter.dev'; /// Put your custom url here.
void main() => runApp(
const MaterialApp(
home: Material(
child: Center(
child: RaisedButton(
onPressed: _launchURL,
child: Text('Show Flutter homepage'),
),
),
),
),
);
void _launchURL() async =>
await canLaunch(_url) ? await launch(_url) : throw 'Could not launch $_url';
You can try this:
return Container(
child: GestureDetector(
onTap: _launchURL,
child: RichText(
text: TextSpan(
children: [
TextSpan(
text: "Don\`t have an Account?",
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w500),
),
TextSpan(
text: "Sign Up",
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold),
),
],
),
),
),
);

What does this speech recognition error mean in my flutter app?

I have an error with my flutter app, so basically I have made a speech to text app, and it works on my iOS simulator and device perfectly. But on my android emulator, when I start the speech to text function, it outputs this error:
I/flutter ( 4958): onError: SpeechRecognitionError msg: error_permission, permanent: true
I am also using this speech to text package:
speech_to_text: ^2.3.0
Does anyone know what this means? I have also added the requirements in the AndroidManifest.xml, the "RECORD_AUDIO" and "INTERNET" ones. (these were listed on the pub.dev page for this package)
Here is my code:
class SpeechScreen extends StatefulWidget {
#override
_SpeechScreenState createState() => _SpeechScreenState();
}
class _SpeechScreenState extends State<SpeechScreen> {
final Map<String, HighlightedWord> _highlights = {
'Hablas': HighlightedWord(
onTap: () => print('voice'),
textStyle: const TextStyle(
color: Colors.green,
fontWeight: FontWeight.bold,
),
),
};
stt.SpeechToText _speech;
bool _isListening = false;
String _text = 'Press the button and start speaking';
double _confidence = 1.0;
#override
void initState() {
super.initState();
_speech = stt.SpeechToText();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Speech To Text'),
centerTitle: true,
backgroundColor: Colors.orange,
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: AvatarGlow(
animate: _isListening,
glowColor: Colors.red,
endRadius: 75.0,
duration: const Duration(milliseconds: 2000),
repeatPauseDuration: const Duration(milliseconds: 100),
repeat: true,
child: RawMaterialButton(
onPressed: _listen,
child: Icon(
_isListening ? Icons.mic : Icons.mic_none,
size: 32,
color: Colors.white,
),
fillColor: Colors.red,
elevation: 2.0,
padding: EdgeInsets.all(15.0),
shape: CircleBorder(),
constraints: BoxConstraints.tight(Size(64, 64)),
splashColor: Colors.red),
),
body: SingleChildScrollView(
reverse: true,
child: Container(
padding: const EdgeInsets.fromLTRB(30.0, 30.0, 30.0, 150.0),
width: double.infinity,
child: Column(
children: [
Text(
'AI Confidence Level: ${(_confidence * 100.0).toStringAsFixed(1)}%',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 32.0,
color: Colors.black,
fontWeight: FontWeight.w700,
),
),
SizedBox(
height: 50,
),
TextHighlight(
text: _text,
words: _highlights,
textAlign: TextAlign.center,
textStyle: const TextStyle(
fontSize: 32.0,
color: Colors.black,
fontWeight: FontWeight.w400),
),
],
)),
),
);
}
void _listen() async {
if (!_isListening) {
bool available = await _speech.initialize(
onStatus: (val) => print('onStatus: $val'),
onError: (val) => print('onError: $val'),
);
if (available) {
setState(() => _isListening = true);
_speech.listen(
onResult: (val) => setState(() {
_text = val.recognizedWords;
if (val.hasConfidenceRating && val.confidence > 0) {
_confidence = val.confidence;
}
}),
);
}
} else {
setState(() => _isListening = false);
_speech.stop();
}
}
}
It Doesn't work on android because you didn't give it the permissions to Record Audio. Navigate to this file:
<project root>/android/app/src/main/AndroidManifest.xml
and add these two lines to it
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.INTERNET"/>
at the end it should look something like this:

url_launcher: canLaunch / launch don't work on iOS for simple URL scheme?

I'm using url_launcher: ^5.4.10 for launching different url scheme but is that external link is working fine on ios simulator but not working opening phone dialpad and default email address while its working fine on android devices
i tested it on ios simulator not real device
if i try to open dialpad here is exception
{PTS: 6.000 s, decode: 32.021 ms},
]
flutter: could not launch tel:+18002509646
when i try open email box here is exception i received
*** First throw call stack:
(
0 CoreFoundation 0x00000001084f4a2a __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00000001083874ce objc_exception_throw + 48
2 Foundation 0x0000000107f2e808 -[__NSConcreteURLComponents initWithString:] + 0
3 CoreServices 0x000000010f7c2db2 -[_LSURLOverride initWithOriginalURL:checkingForAvailableApplications:] + 136
4 CoreServices 0x000000010f7c35b5 -[_LSURLOverride initWithOriginalURL:] + 22
5 CoreServices 0x000000010f7c3d97 _ZN14LaunchServices12URLOverridesL20getURLOverrideCommonEP5NSURL + 374
6 CoreServices 0x000000010f7c3c10 -[LSApplicationWorkspace(LSURLOverride) URLOverrideForURL:] + 12
7 UIKitCore <…>
my code url launcher
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/services.dart';
import 'package:url_launcher/url_launcher.dart';
class Contactcus extends StatelessWidget {
void customLaunch(command) async {
if (await canLaunch(command)) {
await launch(command);
} else {
print(' could not launch $command');
}
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 10),
child: Container(
child: Column(
children: <Widget>[
Text(
'Contact us'.toUpperCase(),
style: TextStyle(
fontFamily: 'TT NORMS',
fontWeight: FontWeight.w100,
fontSize: 25,
),
),
Padding(
padding: EdgeInsets.only(left: 0),
child: Row(
children: <Widget>[
Expanded(
child: SizedBox(
child: ListTile(
leading: Icon(Icons.phone,
size: 25, color: Colors.black87),
onTap: () {
customLaunch('tel:+18001569647');
},
title: Text(
'Phone'.toUpperCase(),
style: TextStyle(
fontFamily: 'TT NORMS',
fontSize: 20,
fontWeight: FontWeight.w100,
),
),
subtitle: Text(
'1 (800) 250-9646 ',
style: TextStyle(
color: Colors.black87,
),
),
),
),
),
],
),
),
Padding(
padding: EdgeInsets.only(left: 0),
child: Row(
children: <Widget>[
Expanded(
child: SizedBox(
child: ListTile(
leading: Icon(Icons.email,
size: 25, color: Colors.black87),
onTap: () {
customLaunch(
'mailto:livinghopetv#cornerstoneasianchurch.com?subject=Feed%20back&body=Write your%20feedback');
},
title: Text(
'Email',
style: TextStyle(
fontFamily: 'TT NORMS',
fontWeight: FontWeight.w100,
fontSize: 20
),
),
subtitle: Text(
'livinghopetv#cornerstoneasianchurch.com',
style: TextStyle(color: Colors.black87,
),
),
),
),
),
],
),
),
Padding(
padding: EdgeInsets.only(left: 0),
child: Row(
children: <Widget>[
Expanded(
child: SizedBox(
child: ListTile(
leading: Icon(Icons.location_on,
size: 28, color: Colors.black87),
onTap:(){
customLaunch('https://www.google.ca/maps/place/3434+Cawthra+Rd,+Mississauga,+ON+L5A+2X7/#43.6025224,-79.6147441,17z/data=!3m1!4b1!4m5!3m4!1s0x882b470c94e668ff:0x62c956c363a795d9!8m2!3d43.6025185!4d-79.6125554');
},
title: Text(
'MAILING ADDRESS',
style: TextStyle(
fontFamily: 'TT NORMS',
fontWeight: FontWeight.w100,
fontSize: 20
),
),
subtitle: Text(
'Att: Living Hope TV\n'
'Cornerstone Asian Church\n'
'3434 Cawthra Rd\n'
'Mississauga, ON L5A 2X7\n'
'Canada',
style: TextStyle(
color: Colors.black87,
),
),
),
),
),
],
),
),
Padding(
padding: EdgeInsets.only(top: 70),
child: Row(
mainAxisAlignment:MainAxisAlignment.center,
children: <Widget>[
IconButton(
icon: Image.asset('images/youtube.png'),
iconSize: 30,
onPressed: () {
customLaunch('https://www.youtube.com/channel/UCsnohhaCJvkT3prNnMwlvnA');
},
),
IconButton(
icon: Image.asset('images/twitter.png'),
iconSize:30,
onPressed: () {
customLaunch('https://twitter.com/livinghopetv1');
},
),
IconButton(
icon: Image.asset('images/instagram.png'),
iconSize: 30,
onPressed: () {
customLaunch('https://www.instagram.com/livinghopetv/');
},
),
IconButton(
icon: Image.asset('images/facebook.png'),
iconSize: 30,
onPressed: () {
customLaunch('https://www.facebook.com/livinghopetelevision');
},
),
IconButton(
icon: Image.asset('images/web.png'),
iconSize: 30,
onPressed: () {
customLaunch('https://www.livinghopetv.org');
},
),
],
),
)
],
),
),
),
],
),
),
);
}
}
I have a suggestion to make, can you try giving the command like this:
Checks
1. Code Check
command = "tel://214324234"
// Also, try using Future in place of void
Future<void> customLaunch(command) async {
if (await canLaunch(command)) {
await launch(command);
} else {
print(' could not launch $command');
}
}
2. Formatting Check: Do check, if there is no space between tel: and the <phone number>, it has to be written without space, that is, tel:<phone_number>
3. Update Check: Also, there is a new update, that is, 5.5.0, please upgrade your packages accordingly in your pubspec.yaml file. Why, am I telling you cos, sometimes, previous version does not support some functionalities in your Mobile Platform
4. Real Device Check: Sometimes what happens is, the simulator does not support some functionalities. I would request you to please get a real iOS Device, and check it. If the above doesn't solve your issue, this might do the job
Add these lines to your myproject/ios/Runner/Info.plist file if you want to use external links.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>http</string>
<string>https</string>
</array>
This work for me:
import 'dart:io' show Platform;
/// Dial
Future<void> contactDial(String number) async {
await _launchCaller(number);
}
_launchCaller(String number) async {
String url = Platform.isIOS ? 'tel://$number' : 'tel:$number';
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}

How to add hyperlink to text in a markdown in flutter

I would like to add a hyperlink at the bottom of the screen where the Markdown widget is read.
I tried to include the hyperlink in the markdown file but flutter is not launching it.
Then I tried this:
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Protective measures'),
),
body: Column(
children: <Widget>[
Flexible(
child: FutureBuilder(
future: DefaultAssetBundle.of(context)
.loadString("assets/docs/protective_measures.md"),
builder:
(BuildContext context, AsyncSnapshot<String> snapshot) {
if (snapshot.hasData) {
return Markdown(
data: snapshot.data,
styleSheet: MarkdownStyleSheet(
textAlign: WrapAlignment.start,
p: TextStyle(
fontSize: 16,
color: isDark ? Colors.white : Colors.black,
),
h2: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: isDark ? Colors.white : Colors.black,
),
h1: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 25,
color: isDark ? Colors.white : Colors.black,
),
),
);
}
return Center(
child: CircularProgressIndicator(),
);
},
),
),
InkWell(
child: Text(
'My Hyperlink',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
color: Colors.blue,
decoration: TextDecoration.underline
),
),
onTap: () => launch('https://stackoverflow.com'),
),
],
),
);
}
The result is not really what I wanted. I want a hypertext at the bottom of the screen, just after the Markdown. I also tried with ListView instead of Column but it's not working.
Any hint ?
For plugin flutter_markdown you can do like this
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:url_launcher/url_launcher.dart';
final String _markdownData = "-This is [Google link](https://www.google.com)";
// view
MarkdownBody(
data: _markdownData,
onTapLink: (text, url, title){
launch(url);
},
)
Update for flutter_markdown version 0.5.1 or lower:
MarkdownBody(
data: _markdownData,
onTapLink: (url) {
launch(url);
},
)
I got it. The Markdown() widget has a onTapLink method and I just need to do:
onTapLink(url){
launch(url);
}
It is always good to do a null reference check to:
MarkdownBody(
data: privacyPolicy._privacyPolicy,
onTapLink: (text, url, title){
launch(url!);
},
Expanding upon the code written by: Azamat Mirvosiqov

Categories

Resources