How can I change the language of a PayPal Smart Payment Button?
My current code looks like this:
paypal.Buttons({
locale: 'en_US',
style: {
size: 'small',
color: 'gold',
shape: 'pill',
label: 'pay',
layout: 'horizontal',
fundingicons: 'false',
height: 46
}
}).render('#paypal-button-container');
Locale is not changing the language to English.
PayPal's sdk/js does not use 'locale' as an object key parameter. That syntax is from the old checkout.js
By default the language of the buttons will be according to the browser language setting. If you need to override this auto detection and force a particular language to match the rest of the site, for the current SDK you add the locale to the <script> query string, as documented here: https://developer.paypal.com/sdk/js/configuration/#locale
Related
I use the easy localization package, how can I check and change the language with just one button?
https://pub.dev/packages/easy_localization
TextButton(
onPressed: () {
// 'En'
// 'Ar'
},
child: Text('Switch lang'),
)
You need to have JSON file for changing the language.
if so, simply you need to take the language by calling
EasyLocalization.of(context)?.locale;
or after importing EasyLocalization package just write context.locale;
For changing use EasyLocalization.of(context)?.setLocale(Locale('EN')); or context.setLocale(Locale('EN'));
I am trying to send the page back to my button screen after receiving success url or cancel url being received from stripe payment after the completion of the transaction in flutter web view
Can someone please tell me how do I achieve this, on receiving success url I want to use navigator.pop() and on receiving cancel url I want to use snackbar
Please find below code :
payment.dart
const TextButton(
// textColor: Colors.white,
child: Text(
'PURCHASE',
style: TextStyle(
fontSize: 15.0,
color: Colors.black87,
fontWeight: FontWeight.bold),
),
onPressed: () => redirecToCheckout(plan[i]),
),
void redirectToCheckout(BuildContext _, var plan) async {
final stripe = Stripe(apiKey);
stripe.redirectToCheckout(CheckoutOptions(
lineItems: [
LineItem(price: plan, quantity: 1),
],
clientReferenceId: '1',
mode: 'payment',
successUrl: 'https://localhost:8080/#/success/{CHECKOUT_SESSION_ID}',
cancelUrl: 'https://localhost:8080/#/cancel',
));
}
Create 2 different dart files success.dart and failure.dart.. add these classes on route too. Now on initstate of success you have to use Navigator.pushAndRemoveUntil and move it to the necessary page. On failure.dart again on initState move to the required pageand display a snackbar. Thats the only way for now to handle payment for flutter web using stripe
I'm trying to localize my Flutter app by following the documentation.
What I'm trying to achieve is that while building widgets dynamically, I wanted to translate the data which comes from my model. This is what I've tried so far
List.generate(services.length, (index) {
final Service service = services[index];
return Material(
borderRadius: BorderRadius.circular(10.0),
child: Text(
AppLocalizations.of(context).{{service.title}} // Here I wanted to translate the service title
),
);
}
How can I achieve this in Flutter? or any other possible method to translate dynamic contents.
Dynamic translation is not supported by Flutter localization packages. You can try to integrate google translation API in you app. But I strongly convinced that it should be a server-side feature and Flutter client should obtain already translated messages in your models. To achieve this, for example, you can use http-headers with your device locale to tell client's language to server.
Also you need to use arguments for Intl messages according to this guide. Here is an example of message with String argument in AppLocalizations:
String someLocalizedString(String argument) => Intl.message(
'Localized part - $argument',
name: 'someLocalizedString',
locale: localeName,
args: [argument],
);
This string inside .arb file:
"someLocalizedString": "Localized part - {argument}",
"#someLocalizedString": {
"type": "text",
"placeholders": {
"argument": {}
}
}
I have a flutter blog application, and i am using this package to render the blog HTML content, I want this content to be selectable, I know of the SelectableText() widget, but this cant be used to render HTML.
Anyone has an idea how I can make my HTML text selectable from mobile?
Several hours ago, in flutter_html merged to master commit that solves this problem. Right not you can import plugin to your project like this:
flutter_html:
git:
url: git://github.com/Sub6Resources/flutter_html.git
ref: master
Maybe for the time you are reading this post, the last changes will be published to pub.dev
Then, use SelectableHtml instead of Html:
SelectableHtml(
data: menuButton.content ?? "",
style: {
"body": Style(
margin: EdgeInsets.zero,
color: Theme.of(context).primaryColor,
),
},
onLinkTap: (link, renderContext, map, element) async {
if (link != null && link.isNotEmpty) {
await launch(link);
}
},
)
Edit - It is now possible without any workarounds. Use K.Amanov's answer.
I achieved this using flutter_markdown and html2md packages. Not an ideal solution as markdown doesn't support all html tags.
import 'package:html2md/html2md.dart' as html2md;
import 'package:flutter_markdown/flutter_markdown.dart';
...
...
MarkdownBody(
selectable: true,
data: html2md.convert(
'Your HTML Text here',
),
),
Library flutter_html:
In code:
SelectableHtml(
data: 'Your text with html tag',
);
Just wrap it in SelectionArea().
For example:
SelectionArea(
child: Html(
data: '<p>Some data</p>',
),
);
The rendered html content will now be selectable.
The SelectableHtml() widget suggested by other answers has shortcomings as stated in their own docs on pub.dev and did not work well for me.
I want when a user types some text to make a post. But the thing is when the user types a hashtag (e.g. #avengers) I can parse and replace that hashtag with a link or ontap widget... Same goes with URL links
Assuming that you want to do this once the user has finished posting and not inside the typing bar:
The smart_text_view 0.1.0 package contains something called LinkTextSpan, which you can use to easily implement this on the view. Their example folder contains an example that was implemented.
As shown in the Flutter's Official Implementation here for the Flutter Gallery Drawyer, you can do this:
_LinkTextSpan(
style: linkStyle,
url: 'https://something.com',
text: 'flutter github repo',
),
and
_LinkTextSpan({ TextStyle style, String url, String text }) : super(
style: style,
text: text ?? url,
recognizer: TapGestureRecognizer()..onTap = () {
launch(url, forceSafariVC: false);
}
);