browser_detector 2.0.0-nullsafety.0 browser_detector: ^2.0.0-nullsafety.0 copied to clipboard
Dart browser detector library. Detects popular browsers, engines and platforms by analyzing the user agent string. Safe to use with Flutter Native.
browser_detector #
Dart browser detector library. Detects popular browsers, engines and platforms by analyzing the user agent string. Safe to use with Flutter Native.
Usage #
Basic usage:
import 'package:browser_detector/browser_detector.dart';
if (BrowserDetector().browser.isSafari) {
// do something if the browser is safari
}
Custom user agent string:
import 'package:browser_detector/browser_detector.dart';
final firefoxUserAgent = '...';
print(BrowserDetector(firefoxUserAgent).browser.isFirefox); // true
Using with dependency injection/service locator libraries (GetIt example):
final getIt = GetIt.instance;
getIt.registerLazySingleton(
() => BrowserDetector(),
);
final detector = getIt.get<BrowserDetector>();
Flutter Native #
This library can be safely used with Flutter Native and won't produce any compilation errors. All isUnknown
tests will return true
when running in native mode.
If this library is used with a Flutter Web project, all objects (browser, platform and engine) will be detected properly.
Mentions #
Some regular expressions are taken from the lancedickson/bowser library. Check it out if you need the same thing but in pure JS.