So basically I have a QR code generator in the app, I already implemented a feature generating it with url, such as domain.com/userid?=111
.
So, now I want QR code scanner to scan it and get only the id part of the user out of it, like it scanned the url example provided above, and then I just want to get '111' part to process.
How can I implement it?
Asked
Active
Viewed 1,461 times
0
-
Shouldn't your url be `domain.com?userid=111` instead of `domain.com/userid?=111` – JideGuru Jun 24 '20 at 12:38
-
@JideGuru, no it should be `domain.com/?userid=111`, read more here: https://stackoverflow.com/a/1617074/1204153 – Andy Jun 24 '20 at 14:53
-
Ignore my comment, both should work and I don't want to start a debate about it like on that thread :) Either way, we can both agree OP's URI is wrong. – Andy Jun 24 '20 at 14:55
2 Answers
2
Use Uri
queryParametersAll:
Uri url = Uri.parse('https://www.example.com/?userid=111');
print(url.queryParametersAll['userid'][0]);

JideGuru
- 7,102
- 6
- 26
- 48
0
You can use substring method to get the part of it.
// Dart 2.6.1
main() {
String str = "domain.com/userid?=111";
print(str.substring(str.indexOf("=")+1));
}

Ketan Ramteke
- 10,183
- 2
- 21
- 41