Skip to content

Commit 859d108

Browse files
huycozyhuynguyennovem
authored andcommitted
upgrade to run on flutter 3.38.7;
migrate to kotlin dsl; replace qr scanner package
1 parent 289aa7f commit 859d108

13 files changed

Lines changed: 255 additions & 211 deletions

android/app/build.gradle

Lines changed: 0 additions & 80 deletions
This file was deleted.

android/app/build.gradle.kts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import java.util.Properties
2+
import java.io.FileInputStream
3+
4+
5+
val keystoreProperties = Properties()
6+
val keystorePropertiesFile = rootProject.file("key.properties")
7+
if (keystorePropertiesFile.exists()) {
8+
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
9+
}
10+
11+
plugins {
12+
id("com.android.application")
13+
id("kotlin-android")
14+
id("dev.flutter.flutter-gradle-plugin")
15+
}
16+
17+
android {
18+
namespace = "com.app.netshare"
19+
compileSdk = flutter.compileSdkVersion
20+
ndkVersion = flutter.ndkVersion
21+
compileOptions {
22+
sourceCompatibility = JavaVersion.VERSION_17
23+
targetCompatibility = JavaVersion.VERSION_17
24+
}
25+
26+
kotlinOptions {
27+
jvmTarget = JavaVersion.VERSION_17.toString()
28+
}
29+
30+
defaultConfig {
31+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
32+
applicationId = "com.app.netshare"
33+
// You can update the following values to match your application needs.
34+
// For more information, see: https://flutter.dev/to/review-gradle-config.
35+
minSdk = flutter.minSdkVersion
36+
targetSdk = flutter.targetSdkVersion
37+
versionCode = flutter.versionCode
38+
versionName = flutter.versionName
39+
}
40+
signingConfigs {
41+
create("release") {
42+
keyAlias = keystoreProperties["keyAlias"] as String
43+
keyPassword = keystoreProperties["keyPassword"] as String
44+
storeFile = keystoreProperties["storeFile"]?.let { file(it) }
45+
storePassword = keystoreProperties["storePassword"] as String
46+
}
47+
}
48+
buildTypes {
49+
debug {
50+
signingConfig = signingConfigs.getByName("debug")
51+
}
52+
release {
53+
// Signing with the debug keys for now, so `flutter run --release` works.
54+
// signingConfig signingConfigs.debug
55+
56+
signingConfig = signingConfigs.getByName("release")
57+
isShrinkResources = true
58+
isMinifyEnabled = true
59+
}
60+
}
61+
}
62+
63+
flutter {
64+
source = "../.."
65+
}

android/build.gradle

Lines changed: 0 additions & 18 deletions
This file was deleted.

android/build.gradle.kts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
allprojects {
2+
repositories {
3+
google()
4+
mavenCentral()
5+
}
6+
}
7+
8+
val newBuildDir: Directory =
9+
rootProject.layout.buildDirectory
10+
.dir("../../build")
11+
.get()
12+
rootProject.layout.buildDirectory.value(newBuildDir)
13+
14+
subprojects {
15+
val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
16+
project.layout.buildDirectory.value(newSubprojectBuildDir)
17+
}
18+
subprojects {
19+
project.evaluationDependsOn(":app")
20+
}
21+
22+
tasks.register<Delete>("clean") {
23+
delete(rootProject.layout.buildDirectory)
24+
}

android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
33
zipStoreBase=GRADLE_USER_HOME
44
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-all.zip

android/settings.gradle

Lines changed: 0 additions & 26 deletions
This file was deleted.

android/settings.gradle.kts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
pluginManagement {
2+
val flutterSdkPath =
3+
run {
4+
val properties = java.util.Properties()
5+
file("local.properties").inputStream().use { properties.load(it) }
6+
val flutterSdkPath = properties.getProperty("flutter.sdk")
7+
require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" }
8+
flutterSdkPath
9+
}
10+
11+
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
12+
13+
repositories {
14+
google()
15+
mavenCentral()
16+
gradlePluginPortal()
17+
}
18+
}
19+
20+
plugins {
21+
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
22+
id("com.android.application") version "8.11.1" apply false
23+
id("org.jetbrains.kotlin.android") version "2.2.20" apply false
24+
}
25+
26+
include(":app")

lib/data/global_scope_data.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ class GlobalScopeData {
77
String _connectedIPAddress = '';
88
String get connectedIPAddress => _connectedIPAddress;
99

10+
String _currentDeviceIPAddress = '';
11+
String get currentDeviceIPAddress => _currentDeviceIPAddress;
12+
13+
String _currentServerHostingPort = '';
14+
String get currentServerHostingPort => _currentServerHostingPort;
15+
1016
void updateConnectionStatus({required ConnectionStatus newStatus}) {
1117
_connectionStatus = newStatus;
1218
}
@@ -15,8 +21,18 @@ class GlobalScopeData {
1521
_connectedIPAddress = newIpAddress;
1622
}
1723

24+
void updateCurrentDeviceIPAddress({required String newIpAddress}) {
25+
_currentDeviceIPAddress = newIpAddress;
26+
}
27+
28+
void updateCurrentServerHostingPort({required String newPort}) {
29+
_currentServerHostingPort = newPort;
30+
}
31+
1832
void resetAllData() {
1933
_connectedIPAddress = '';
34+
_currentDeviceIPAddress = '';
35+
_currentServerHostingPort = '';
2036
_connectionStatus = ConnectionStatus.idle;
2137
}
2238
}

lib/data/preload_data.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import 'package:netshare/data/global_scope_data.dart';
2+
import 'package:netshare/di/di.dart';
3+
import 'package:netshare/util/utility_functions.dart';
4+
5+
class PreloadData {
6+
static Future inject() async {
7+
// current device IP address
8+
final ip = await UtilityFunctions.getIPAddress() ?? '';
9+
getIt.get<GlobalScopeData>().updateCurrentDeviceIPAddress(newIpAddress: ip);
10+
}
11+
}

lib/main.dart

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ import 'package:netshare/util/utility_functions.dart';
2121
import 'package:netshare/config/constants.dart';
2222
import 'package:netshare/ui/send/uploading_widget.dart';
2323

24+
import 'data/preload_data.dart';
25+
2426
void main() async {
2527
WidgetsFlutterBinding.ensureInitialized();
2628
await initPlugins();
2729
setupDI();
30+
await PreloadData.inject();
2831
runApp(const MyApp());
2932
}
3033

@@ -41,7 +44,8 @@ class _MyAppState extends State<MyApp> {
4144

4245
final GoRouter _router = GoRouter(
4346
navigatorKey: _navigatorKey,
44-
errorBuilder: (BuildContext context, GoRouterState state) => ErrorWidget(state.error!),
47+
errorBuilder: (BuildContext context, GoRouterState state) =>
48+
ErrorWidget(state.error!),
4549
routes: <GoRoute>[
4650
GoRoute(
4751
path: mRootPath,
@@ -71,7 +75,8 @@ class _MyAppState extends State<MyApp> {
7175
GoRoute(
7276
name: mSendPath,
7377
path: mSendPath,
74-
builder: (BuildContext context, GoRouterState state) => const SendWidget(),
78+
builder: (BuildContext context, GoRouterState state) =>
79+
const SendWidget(),
7580
routes: [
7681
GoRoute(
7782
name: mUploadingPath,
@@ -88,7 +93,8 @@ class _MyAppState extends State<MyApp> {
8893
GoRoute(
8994
name: mScanningPath,
9095
path: mScanningPath,
91-
builder: (BuildContext context, GoRouterState state) => const ScanQRWidget(),
96+
builder: (BuildContext context, GoRouterState state) =>
97+
const ScanQRWidget(),
9298
),
9399
],
94100
),
@@ -110,29 +116,36 @@ class _MyAppState extends State<MyApp> {
110116
theme: ThemeData(
111117
useMaterial3: true,
112118
appBarTheme: const AppBarTheme(color: backgroundColor),
113-
colorScheme: ColorScheme.fromSeed(seedColor: seedColor, background: backgroundColor),
119+
colorScheme: ColorScheme.fromSeed(
120+
seedColor: seedColor, background: backgroundColor),
121+
iconButtonTheme: const IconButtonThemeData(
122+
style: ButtonStyle(
123+
iconColor: MaterialStatePropertyAll<Color>(textIconButtonColor),
124+
),
125+
),
114126
),
115127
routerConfig: _router,
116128
builder: (context, child) {
117129
// Handle keyboard listener here
118-
RawKeyboard.instance.addListener((RawKeyEvent value) => _handleKeyEvent(value));
130+
RawKeyboard.instance
131+
.addListener((RawKeyEvent value) => _handleKeyEvent(value));
119132
return child ?? const SizedBox.shrink();
120133
},
121134
),
122135
);
123136
}
124137

125138
void _handleKeyEvent(RawKeyEvent value) async {
126-
if (!_isKeyboardListenerEnabled) return;
139+
if (!_isKeyboardListenerEnabled) return;
127140

128141
// If user pressed Command/Control + W keys, quit the app
129142
if (value.isMetaPressed && value.logicalKey == LogicalKeyboardKey.keyW ||
130143
value.isControlPressed && value.logicalKey == LogicalKeyboardKey.keyW) {
131-
132-
if(_navigatorKey.currentContext == null) return;
144+
if (_navigatorKey.currentContext == null) return;
133145

134146
// show confirm dialog
135-
_showQuitAppConfirmationDialog(_navigatorKey.currentContext!, (confirmCallback) {
147+
_showQuitAppConfirmationDialog(_navigatorKey.currentContext!,
148+
(confirmCallback) {
136149
if (confirmCallback) {
137150
SystemNavigator.pop(); // Quit the app
138151
}
@@ -142,7 +155,8 @@ class _MyAppState extends State<MyApp> {
142155
}
143156
}
144157

145-
void _showQuitAppConfirmationDialog(BuildContext context, Function(bool)? confirmCallback) {
158+
void _showQuitAppConfirmationDialog(
159+
BuildContext context, Function(bool)? confirmCallback) {
146160
// Disable the keyboard listener.
147161
_isKeyboardListenerEnabled = false;
148162

0 commit comments

Comments
 (0)