Ad
How Can I Prevent A Production Flutter App From Running In Emulators?
I have no idea how to block or prevent my production application from running on emulators or softwares such as BlueStacks
Does anyone come up with a solution for this problem?
Ad
Answer
you can use package https://pub.dev/packages/device_info
add dependency in pubspec.yaml
dependencies:
device_info: ^0.4.0+3
and here is example how to detect is it real device or not
import 'package:device_info/device_info.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(title: const Text('Is am i in matrix?')),
body: Test(),
),
);
}
}
class Test extends StatelessWidget {
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: _isRealDevice(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Center(child: Text('is it real device: ${snapshot.data}'));
} else {
return const SizedBox.shrink();
}
},
);
}
Future<bool> _isRealDevice() async {
AndroidDeviceInfo androidInfo = await DeviceInfoPlugin().androidInfo;
return androidInfo.isPhysicalDevice;
}
}
I don't have installed Genymotion but on AS emulators it shows false
as intended.
Ad
source: stackoverflow.com
Related Questions
- → How do you create a 12 or 24 mnemonics code for multiple cryptocurrencies (ETH, BTC and so on..)
- → Flutter: input text field don't work properly in a simple example..... where am I wrong?
- → Can I customize the code formatting of Dart code in Atom?
- → Is it possible to develop iOS apps with Flutter on a Linux virtual machine?
- → Display SnackBar in Flutter
- → JSON ObjectMapper in Flutter
- → Material flutter app source code
- → TabBarSelection No such method error
- → How do I set the animation color of a LinearProgressIndicator?
- → Add different routes/screens to Flutter app
- → Is there a way to get the size of an existing widget?
- → How to share a file using flutter
- → Is there an easy way to find particular text built from RichText in a Flutter test?
Ad