My intention is to build a Flutter BLE application to blink an led as many times the number given as user input. I am using flutter_blue plugin( https://pub.dev/packages/flutter_blue). Also, I’ve imported ‘dart:convert’ for the utf8 conversion. I am getting the user input with TextEditingController(). Here is a piece of my code.
BluetoothCharacteristic characteristic;
final _writeController = TextEditingController();
TextField(
keyboardType: TextInputType.text,
controller: _writeController,
),
FlatButton(
child: Text("Send"),
onPressed: () {
characteristic.write(utf8.encode(_writeController.value.text));
Navigator.pop(context);
},
),
But, the led is blinking corresponding ASCII value times the user input. For example, when the user input is 5, the led is blinking 53 times. Please, help me get through this problem.
First, make keyboardType: TextInputType.number if all you expect is numbers.
Then
characteristic.write([int.parse(_writeController.text)]);
Related
I have a screen where some textfields I want to show a 'fake' keyboard. The keyboard should be able have as many buttons as I like and be displayed however I want. Just as shown below.
My question then is how do you accomplish something like this?
Is it possible to somehow override the interface to the keyboard so you consume the input and can display a 'fake' keyboard. And then remove the 'fake' keyboard when clicking on the back button on any other textfield which uses the normal keyboard.
Or do I have to create a custom #Composable or TextView with custom callbacks, and also render the text cursor manually?
You can implement your own TextInputService or provide null to completely disable the default input service:
CompositionLocalProvider(
LocalTextInputService provides null // or myTextInputService
) {
TextField(
value = text,
onValueChange = { text = it },
)
}
where myTextInputService is something like:
TextInputService(object : PlatformTextInputService {
//TODO implement methods
}
[enter image description here][1]
Hello, first of all, I have been dealing with a bug since yesterday and I could not find the problem, but it does not work.
It needs to go to _homepagestate but it doesn't
[1]: https://i.stack.imgur.com/GeonQ.png
I believe you are trying to navigate to the other page of your app. Try the following code.
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomePage(),
),
);
I deployed a flutter web app, but when the user browses to different screens the path in the browser bar is never updated.
You can experience it here: https://owleyes.codemagic.app/#/
I am navigating using the following method:
Navigator.push(
context,
MaterialPageRoute(builder: (context) => AboutPage()),
);
https://github.com/owleyesdev/owleyes/blob/master/lib/pages/home_page.dart#L24
To accomplish this you need to use named routes. Using named routes gives flutter a specific string to show when you navigate to a new route. The method of using named routes is well-documented here, but I will include the basics of what needs to be done.
You already have a MaterialApp at the top of your widget tree. You just need to define the routes that you need to be possible here with the routes named paramete, which accepts the type Map<String, WidgetBuilder> with the String key being the String that is appended to the URL after /#/.
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
brightness: Brightness.dark,
primaryColorDark: Colors.black,
fontFamily: "GoogleSansRegular",
),
routes: {
'/': (context) => HomePage(),
'/aboutPage': (context) => AboutPage(),
}
);
I would recommend just defining the String keys as a static variable of each widget. This way they can be accessed as something like HomePage.route, which helps in the next necessary modification.
Now instead of just Navigator.push, you should use Navigator.pushNamed, which does the same action, just accepting a String route as a parameter instead.
Usage example:
Navigator.pushNamed(context, '/aboutPage');
Using this will end up with a URL of https://owleyes.codemagic.app/#/aboutPage.
After taking Picture, how to select Ok in appium when tick mark cant be located?
only camara layout is Higlighted and i am not able to loacte tick mark or revert.
Please try below code snippet. If you are able to click using android keyboard then below code should work.
((AndroidDriver)driver).pressKey(new KeyEvent(AndroidKey.SEARCH));
I acheived this using TouchAction.
TouchAction touchAction = new TouchAction(driver);
touchAction.tap(new PointOption().withCoordinates(111, 222)).perform()
solution for accepting image using camera app in appium.
keyEvent=>27, is use to capture the image using camera app.
i used below code to accept the captured image. (but its not working)
i used keyEvent=> 66, Enter button to accept the image (but its not working).
i used keyEvent=> 84, Space button to accept the image (but its not working).
below working code.
i used keyEvent=> 22 and then i used keyEvent=> 66, it will accept the image.
$app.press_keycode(27) #click on camera accept button.
$app.press_keycode(22)
$app.press_keycode(66)
sleep 2
$app.press_keycode(27)
$app.press_keycode(22)
$app.press_keycode(66)
Note: repeat the code for 2 twice
i used keyEvent=> 21 and then i used keyEvent=> 66 and i used keyEvent=> 27, it will allow u to retake the image.
i used keyEvent=>4, it will take back u form camera app
The way I handled Camera and Tick button initially was using Android Key Codes:
Thread.sleep(2000);
androidDriver.pressKey(new KeyEvent(AndroidKey.CAMERA));
Thread.sleep(1000);
androidDriver.pressKey(new KeyEvent(AndroidKey.TAB));
Thread.sleep(1000);
androidDriver.pressKey(new KeyEvent(AndroidKey.TAB));
Thread.sleep(1000);
androidDriver.pressKey(new KeyEvent(AndroidKey.ENTER));
In most of the devices which I researched earlier, the above snippet worked like a charm for me. However, when I started testing on Android versions 9, 10 and 11 recently, this wasn't working and the number of tabs increased to 3 or 4. To handle this in most of the devices like Samsung, OnePlus, Google Pixel, I refactored the code as:
Thread.sleep(2000);
// Click Camera shutter button
androidDriver.pressKey(new KeyEvent(AndroidKey.CAMERA));
try {
WebDriverWait wait = new WebDriverWait(androidDriver, 10);
wait.until(ExpectedConditions.elementToBeClickable((MobileBy.AccessibilityId("Done");
// Click Done or Tick after clicking photo (Mostly visible in OnePlus, Nokia, Google Pixel devices)
androidDriver.findElementByAccessibilityId("Done").click();
} catch (NoSuchElementException e) {
flag = true;
System.out.println("NoSuchElement for DONE Button");
}
if (flag) {
try {
// Click OK after clicking photo (Mostly visible in Samsung devices)
// No need to put WebDriverWait here as we already waited for 10 secs after clicking on Camera
androidDriver.findElementByXPath("//android.widget.TextView[#text='OK']").click();
flag = false;
System.out.println("OK Button Clicked");
} catch (NoSuchElementException e) {
flag = true;
System.out.println("NoSuchElement for OK Button");
}
}
if (flag) {
// If both above methods failed, then this may work (Mostly works for Xiaomi, Nokia devices)
androidDriver.pressKey(new KeyEvent(AndroidKey.TAB));
hardStopWait(1000);
androidDriver.pressKey(new KeyEvent(AndroidKey.TAB));
hardStopWait(1000);
androidDriver.pressKey(new KeyEvent(AndroidKey.ENTER));
System.out.println("TABS & ENTER Pressed");
}
I am trying to create an Angular and Node program that utilizes a barcode scanner. I am building on a mac and I am using a Motorola DS9208 scanner which can read both qr codes and barcodes. When I console.log(devices) all of the devices are made by Apple except this one, which does not provide much information:
{
vendorId: 0,
productId: 0,
path: 'IOService:/AppleACPIPlatformExpert/PCI0#0/AppleACPIPCI/SBUS#1F,3/AppleSMBusPCI/BUS0#0/AppleSMBusControllerICH/MKY0/AppleMikeyDriver/AppleMikeyHIDDriver',
serialNumber: '',
manufacturer: '',
product: 'Apple Mikey HID Driver',
release: 0,
interface: -1,
usagePage: 12,
usage: 1
}
It is the only USB device plugged in so I assume that it is the HID it is referring to. However, My problem is when I try to actually scan things. When I set var device = new HID.HID(0,0) since the vendor and product IDs are 0, and use function
device.on('data', function(data) { console.log(data)} )
nothing happens. Same when I do the same for checking errors. When the scanner scans any barcode it beeps once then beeps four more times with red lights giving off some sort of error message. Can anyone help me out? Thank you