Skip to content

Commit 0cb22bd

Browse files
committed
chore: updated example app
Signed-off-by: Denis Dobanda <[email protected]>
1 parent 09e28d2 commit 0cb22bd

File tree

11 files changed

+254
-211
lines changed

11 files changed

+254
-211
lines changed

example/android/app/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ android {
3333
targetCompatibility = JavaVersion.VERSION_1_8
3434
}
3535

36+
kotlinOptions {
37+
jvmTarget = JavaVersion.VERSION_1_8
38+
}
39+
3640
defaultConfig {
3741
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
3842
applicationId = "com.example.flutter_security_toolkit_example"

example/android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
36
zipStoreBase=GRADLE_USER_HOME
47
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip

example/android/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pluginManagement {
1818

1919
plugins {
2020
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
21-
id "com.android.application" version "7.3.0" apply false
21+
id "com.android.application" version "8.7.0" apply false
2222
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
2323
}
2424

example/lib/app/app.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_security_toolkit_example/app/home_content.dart';
3+
4+
class App extends StatelessWidget {
5+
const App({super.key});
6+
7+
@override
8+
Widget build(BuildContext context) {
9+
return const MaterialApp(
10+
debugShowCheckedModeBanner: false,
11+
home: HomeContent(),
12+
);
13+
}
14+
}

example/lib/app/home_content.dart

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter/services.dart';
3+
import 'package:flutter_security_toolkit/flutter_security_toolkit.dart';
4+
import 'package:flutter_security_toolkit_example/threat/threat_overview.dart';
5+
6+
class HomeContent extends StatefulWidget {
7+
const HomeContent({super.key});
8+
9+
@override
10+
State<HomeContent> createState() => _HomeContentState();
11+
}
12+
13+
class _HomeContentState extends State<HomeContent> {
14+
bool _rootPrivileges = false;
15+
bool _hooks = false;
16+
bool _simulator = false;
17+
18+
@override
19+
void initState() {
20+
super.initState();
21+
initPlatformState();
22+
}
23+
24+
Future<void> initPlatformState() async {
25+
try {
26+
final (jailbroken, hooks, simulator) = await (
27+
ThreatDetectionCenter.areRootPrivilegesDetected(),
28+
ThreatDetectionCenter.areHooksDetected(),
29+
ThreatDetectionCenter.isSimulatorDetected(),
30+
).wait;
31+
32+
if (!mounted) return;
33+
34+
setState(() {
35+
_rootPrivileges = jailbroken ?? _rootPrivileges;
36+
_hooks = hooks ?? _hooks;
37+
_simulator = simulator ?? _simulator;
38+
});
39+
} on PlatformException {
40+
// Do nothing
41+
}
42+
}
43+
44+
@override
45+
Widget build(BuildContext context) {
46+
return ThreatOverview(
47+
hasRootPrivileges: _rootPrivileges,
48+
hasHooks: _hooks,
49+
isInSimulator: _simulator,
50+
);
51+
}
52+
}

example/lib/main.dart

Lines changed: 2 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -1,184 +1,6 @@
1-
import 'dart:async';
2-
31
import 'package:flutter/material.dart';
4-
import 'package:flutter/services.dart';
5-
import 'package:flutter_security_toolkit/flutter_security_toolkit.dart';
2+
import 'package:flutter_security_toolkit_example/app/app.dart';
63

74
void main() {
8-
runApp(const MyApp());
9-
}
10-
11-
class MyApp extends StatefulWidget {
12-
const MyApp({super.key});
13-
14-
@override
15-
State<MyApp> createState() => _MyAppState();
16-
}
17-
18-
class _MyAppState extends State<MyApp> {
19-
bool _jailbroken = false;
20-
bool _hooks = false;
21-
bool _simulator = false;
22-
23-
@override
24-
void initState() {
25-
super.initState();
26-
initPlatformState();
27-
}
28-
29-
// Platform messages are asynchronous, so we initialize in an async method.
30-
Future<void> initPlatformState() async {
31-
// Platform messages may fail, so we use a try/catch PlatformException.
32-
// We also handle the message potentially returning null.
33-
try {
34-
final (jailbroken, hooks, simulator) = await (
35-
ThreatDetectionCenter.areRootPrivilegesDetected(),
36-
ThreatDetectionCenter.areHooksDetected(),
37-
ThreatDetectionCenter.isSimulatorDetected(),
38-
).wait;
39-
40-
if (!mounted) return;
41-
42-
setState(() {
43-
_jailbroken = jailbroken ?? _jailbroken;
44-
_hooks = hooks ?? _hooks;
45-
_simulator = simulator ?? _simulator;
46-
});
47-
} on PlatformException {
48-
// Do nothing
49-
}
50-
}
51-
52-
@override
53-
Widget build(BuildContext context) {
54-
return MaterialApp(
55-
debugShowCheckedModeBanner: false,
56-
home: Scaffold(
57-
body: SafeArea(
58-
child: Center(
59-
child: Builder(builder: (context) {
60-
final textTheme = Theme.of(context).textTheme;
61-
return SingleChildScrollView(
62-
child: Column(
63-
crossAxisAlignment: CrossAxisAlignment.center,
64-
mainAxisAlignment: MainAxisAlignment.center,
65-
children: [
66-
Icon(
67-
_jailbroken || _hooks ? Icons.lock_open : Icons.lock,
68-
size: 80,
69-
).padding(bottom: 24),
70-
Text(
71-
'Protection',
72-
style: textTheme.headlineLarge,
73-
).padding(bottom: 8),
74-
Text(
75-
'Here is a list of the threats that could put you at risk',
76-
style:
77-
textTheme.titleMedium?.copyWith(color: Colors.grey),
78-
textAlign: TextAlign.center,
79-
).padding(bottom: 16),
80-
ThreatCard(
81-
title: 'Jailbreak / Root',
82-
description:
83-
'Is a way of acquiring privileged control over the operating system of a device. Tools such as Magisk or Shadow can hide the privileged access',
84-
status: _jailbroken,
85-
),
86-
ThreatCard(
87-
title: 'Hooks',
88-
description:
89-
'Intercept system or application calls and then modify them (modify the return value of a function call for example)',
90-
status: _hooks,
91-
),
92-
ThreatCard(
93-
title: 'Simulator',
94-
description: 'Running the application in an Simulator',
95-
status: _simulator,
96-
),
97-
],
98-
),
99-
);
100-
}),
101-
).padding(left: 20, right: 20),
102-
),
103-
),
104-
);
105-
}
106-
}
107-
108-
class ThreatCard extends StatelessWidget {
109-
final String title;
110-
final String description;
111-
final bool status;
112-
113-
const ThreatCard({
114-
required this.title,
115-
required this.description,
116-
required this.status,
117-
super.key,
118-
});
119-
120-
@override
121-
Widget build(BuildContext context) {
122-
final textTheme = Theme.of(context).textTheme;
123-
return Card(
124-
shape: RoundedRectangleBorder(
125-
borderRadius: BorderRadius.circular(8),
126-
),
127-
color: Colors.white,
128-
child: Column(
129-
crossAxisAlignment: CrossAxisAlignment.start,
130-
children: [
131-
Row(
132-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
133-
children: [
134-
Text(
135-
title,
136-
style: textTheme.titleLarge?.copyWith(color: Colors.black),
137-
),
138-
Card(
139-
shape: RoundedRectangleBorder(
140-
borderRadius: BorderRadius.circular(8),
141-
),
142-
color: !status ? Colors.green : Colors.red,
143-
child: Column(
144-
children: [
145-
Text(
146-
!status ? 'SAFE' : 'DETECTED',
147-
style: textTheme.bodySmall?.copyWith(color: Colors.white),
148-
),
149-
],
150-
).paddingAll(8),
151-
)
152-
],
153-
).padding(bottom: 8),
154-
Text(
155-
description,
156-
style: textTheme.titleMedium?.copyWith(color: Colors.grey),
157-
textAlign: TextAlign.start,
158-
),
159-
],
160-
).paddingAll(16),
161-
).paddingAll(8);
162-
}
163-
}
164-
165-
extension PaddedWidget on Widget {
166-
Widget padding({
167-
double left = 0.0,
168-
double top = 0.0,
169-
double right = 0.0,
170-
double bottom = 0.0,
171-
}) =>
172-
Padding(
173-
padding: EdgeInsets.only(
174-
left: left,
175-
top: top,
176-
right: right,
177-
bottom: bottom,
178-
),
179-
child: this,
180-
);
181-
182-
Widget paddingAll(double all) =>
183-
padding(left: all, top: all, right: all, bottom: all);
5+
runApp(const App());
1846
}

example/lib/shared/extensions.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import 'package:flutter/material.dart';
2+
3+
extension PaddedWidget on Widget {
4+
Widget padding({
5+
double left = 0.0,
6+
double top = 0.0,
7+
double right = 0.0,
8+
double bottom = 0.0,
9+
}) =>
10+
Padding(
11+
padding: EdgeInsets.only(
12+
left: left,
13+
top: top,
14+
right: right,
15+
bottom: bottom,
16+
),
17+
child: this,
18+
);
19+
20+
Widget paddingAll(double all) =>
21+
padding(left: all, top: all, right: all, bottom: all);
22+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_security_toolkit_example/shared/extensions.dart';
3+
4+
class ThreatCard extends StatelessWidget {
5+
final String title;
6+
final String description;
7+
final bool status;
8+
9+
const ThreatCard({
10+
required this.title,
11+
required this.description,
12+
required this.status,
13+
super.key,
14+
});
15+
16+
@override
17+
Widget build(BuildContext context) {
18+
final textTheme = Theme.of(context).textTheme;
19+
return Card(
20+
shape: RoundedRectangleBorder(
21+
borderRadius: BorderRadius.circular(8),
22+
),
23+
color: Colors.white,
24+
child: Column(
25+
crossAxisAlignment: CrossAxisAlignment.start,
26+
children: [
27+
Row(
28+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
29+
children: [
30+
Text(
31+
title,
32+
style: textTheme.titleLarge?.copyWith(color: Colors.black),
33+
),
34+
Card(
35+
shape: RoundedRectangleBorder(
36+
borderRadius: BorderRadius.circular(8),
37+
),
38+
color: !status ? Colors.green : Colors.red,
39+
child: Column(
40+
children: [
41+
Text(
42+
!status ? 'SAFE' : 'DETECTED',
43+
style: textTheme.bodySmall?.copyWith(color: Colors.white),
44+
),
45+
],
46+
).paddingAll(8),
47+
)
48+
],
49+
).padding(bottom: 8),
50+
Text(
51+
description,
52+
style: textTheme.titleMedium?.copyWith(color: Colors.grey),
53+
textAlign: TextAlign.start,
54+
),
55+
],
56+
).paddingAll(16),
57+
).paddingAll(8);
58+
}
59+
}

0 commit comments

Comments
 (0)