how can i detect line feed in Flutter?
as I know CR can be detected by "\n" and it's working fine.
this is the code I used for CR
if (value.toString().contains("\n")) {
fetchProducts(value);
} else {}
},
I tried "\r" but its not working.
I am Using TextFormFiled and the setting in the device was set to send LF after reading a barcode
You can use the unicode value for LF, U+000A:
if (value.toString().contains("\u{000a}")) {
fetchProducts(value);
} else {}
},
EDIT
What is the type of value? In my code, to be sure that I'm converting correctly from bytes to String, instead of using toString I'm using this:
import 'dart:convert' show utf8;
[...]
String message = utf8.decode(data);
Related
I have a text field where I can paste text. I use this to paste URL's from the internet.
If I accidentally paste a large chunk of code from my clipboard instead of normal text or URL's, it gives me the following error:
Scheme not starting with alphabetic character (at character 1).
How can I catch this error so that the user has a good experience?
[EDIT]
There is a button with a clipboard icon that the user can tap. Here is where the error happens once this button is tapped by the user:
onTap: () async {
if (linkTextController.text.trim() == "") {
try {
ClipboardData? data = await Clipboard.getData(Clipboard.kTextPlain);
linkTextController.text = data!.text.toString();
} catch (error) {
print(error);
}
} else {
linkTextController.text = "";
}
setState(() {});
},
Try handling the onChanged event of the TextField using official document - Handle changes to a text field
UPDATE
You might want to use hasStrings() first, given here, because the official documentation for ClipboardData class clearly states that:<br /
The system clipboard can contain data of various media types. This data structure currently supports only plain text data, in the text property.
From time to time I need a non-breaking space in my Flutter Text widgets, e.g. a "Show more" link or a number with unit like "50 km/h".
The following code works fine but it looks overly complicated:
const int $nbsp = 0x00A0; // from https://pub.dev/packages/charcode
print('Hello${String.fromCharCode($nbsp)}World'); // --> prints "Hello World", does not break
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :/
I'm curious if there is a shorter way to use an integer constant from the charcode package in my interpolated string?
The easy way to do it is using escape combination [\u{00A0}]:
Text('Hello\u{00A0}world');
The best solution I have come up with is creating a String extension method.
// string_extension.dart
const int $nbsp = 0x00A0;
extension StringExtension on String {
String get nonBreaking => replaceAll(' ', String.fromCharCode($nbsp));
}
Usage example:
// import 'string_extension.dart';
Text('Hello World'.nonBreaking)
I have a list of customized icons to my app, it comes like below setted as IconData, note codePoint (0xe931).
IconData angry_face = IconData(0xe931, fontFamily: _fontFamily);
There's nothing wrong with that, but I've some cases where I need this icon as Unicode string to be used as a text. It should be done just like:
// It works too
Text('\ue931', style: TextStyle(fontFamily: _fontFamily));
The problem is:
I don't wanna use this code "by hand" because this icons are changed constantly by designers team and sometimes it changes its code messing up my app icons. What I need to do is get the icon object and parse it to the Unicode string, so I can use it with a Text widget.
I thought that would work to get programmatically that code and just use it, but it don't:
var iconcode = iconData.codePoint.toRadixString(16);
var result;
// Error: An escape sequence starting with '\u'
// must be followed by 4 hexadecimal digits or
// from 1 to 6 digits between '{' and '}'
result = '\u$iconcode';
// Just a simple string
result = '\\u$iconcode';
In few words: How can I parse programmatically int codePoint to a valid Unicode string?
Here's the right answer. I tried everything but this... Thank you #julemand101
final result = String.fromCharCode(iconData.codePoint);
I'm trying to set a text selection in CodeMirror based on a predefined string, similar to a find without prompt (i.e. http://perso.jojaba.fr/codemirror-test/codemirror/demo/search-element.html) except not marking the value, but actually putting a selection on the range (which might be multi line, depending on the predefined string). I can't seem to figure out how to set a selection in this way. Any idea.
well, as it turns out the findNext() offered by searchwithoutdialog.js actually does what I need. effectively it's:
instance.on("change", function (cm, change) {
// other code snipped! //
var str = "my replacement";
var token = cm.getTokenAt(change.from, false);
cm.replaceRange(str, { ch: token.start, line: line }, { ch: token.end, line: line });
CodeMirror.commands.findNext(cm, str);
}
I am reading data from a .csv file and displaying it. When I encounter the micro character (µ) some special symbols are displayed instead. How can I display the micro character?
class Scr extends MainScreen
{
public Scr() {
LabelField label = new LabelField();
String fontName = label.getFont().getFontFamily().getName();
String text = "Font name: "+fontName+" Symbol: µ";
label.setText(text);
add(label);
}
}
screen http://img207.imageshack.us/img207/9606/screenwx.jpg
Can't reproduce on RIM OS 4.5 Curve 8300, font "BBAlpha Sans".
Check what font are you using, there may be no "µ" symbol
Try to debug and see if symbol is readed correctly from file