Skip to content

Commit

Permalink
Fix systemuioverlay style, update flutter version (#29)
Browse files Browse the repository at this point in the history
* Fix systemuioverlay style, update flutter version

* Fix linting issues

* Fix docker container rust version
  • Loading branch information
EwuUwe authored Sep 26, 2024
1 parent ef54b91 commit a29d171
Show file tree
Hide file tree
Showing 13 changed files with 1,904 additions and 766 deletions.
4 changes: 3 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/cirruslabs/flutter:latest
FROM ghcr.io/cirruslabs/flutter:3.22.2

ENV ANDROID_NDK_VERSION 23.1.7779620
ENV PATH="/root/.cargo/bin:$PATH"
Expand Down Expand Up @@ -30,6 +30,8 @@ RUN apt update && apt install -y \
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y \
&& . "$HOME/.cargo/env" \
&& rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android \
&& rustup install 1.75.0 \
&& rustup default 1.75.0 \
&& echo "export ANDROID_NDK_HOME=/opt/android-sdk-linux/ndk/$ANDROID_NDK_VERSION" >> $HOME/.bashrc \
&& cargo install cargo-ndk

Expand Down
21 changes: 9 additions & 12 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
};
Expand Down Expand Up @@ -75,7 +74,7 @@
rustToolchain
flutter
androidSdk
gnome.zenity
zenity
fastlane
cargo-ndk
];
Expand Down
92 changes: 9 additions & 83 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import 'dart:io';

import 'package:dynamic_color/dynamic_color.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_displaymode/flutter_displaymode.dart';
import 'package:iyox_wormhole/pages/router.dart';
import 'package:flutter/services.dart';
import 'package:iyox_wormhole/utils/settings.dart';
import 'package:logger/logger.dart';
import 'package:path_provider/path_provider.dart';

import 'gen/ffi.dart';
import 'themed_app.dart';

void main() async {
await initApp();
Expand Down Expand Up @@ -42,8 +41,7 @@ Future<void> initApp() async {
};

PlatformDispatcher.instance.onError = (error, stack) {
log.f('PlatformDispatcher - Catch all error: $error',
error: error, stackTrace: stack);
log.f('PlatformDispatcher - Catch all error: $error', error: error, stackTrace: stack);
debugPrint("PlatformDispatcher - Catch all error: $error $stack");
return true;
};
Expand All @@ -60,19 +58,8 @@ class WormholeApp extends StatefulWidget {
WormholeAppState createState() => WormholeAppState();
}

class WormholeAppState extends State<WormholeApp> with WidgetsBindingObserver {
ThemeMode themeMode = ThemeMode.dark;

class WormholeAppState extends State<WormholeApp> {
Future<void> initApp() async {
// Draw the app from edge to edge
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);

// Sets the navigation bar color
SystemUiOverlayStyle overlayStyle = const SystemUiOverlayStyle(
systemNavigationBarColor: Colors.transparent,
);
SystemChrome.setSystemUIOverlayStyle(overlayStyle);

// Clear Cache
await FilePicker.platform.clearTemporaryFiles();
await Settings.setRecentFiles([]);
Expand All @@ -81,91 +68,30 @@ class WormholeAppState extends State<WormholeApp> with WidgetsBindingObserver {
@override
initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
initBackend();
initApp().then((_) => debugPrint("App Init Completed"));

var brightness =
WidgetsBinding.instance.platformDispatcher.platformBrightness;
getCurrentAppTheme().then((value) {
setState(() {
if (value == ThemeMode.system) {
themeMode =
brightness == Brightness.dark ? ThemeMode.dark : ThemeMode.light;
} else {
themeMode = value;
}
});
});
}

@override
Future<void> dispose() async {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}

@override
void didChangePlatformBrightness() {
super.didChangePlatformBrightness();

setTheme();
}

Future<ThemeMode> getCurrentAppTheme() async {
return await Settings.getThemeMode();
}

void setTheme() {
var brightness = View.of(context).platformDispatcher.platformBrightness;
getCurrentAppTheme().then((value) {
debugPrint(value.toString());

setState(() {
if (value == ThemeMode.system) {
themeMode =
brightness == Brightness.dark ? ThemeMode.dark : ThemeMode.light;
} else {
themeMode = value;
}
});
});
}

void initBackend() async {
final tempDir = (await getTemporaryDirectory()).path;
api.init(tempFilePath: tempDir);
}

@override
Widget build(BuildContext context) {
return DynamicColorBuilder(builder: (lightColorScheme, darkColorScheme) {
var lightScheme = lightColorScheme ??
ColorScheme.fromSeed(
seedColor: Colors.indigo, brightness: Brightness.light);
var darkScheme = darkColorScheme ??
ColorScheme.fromSeed(
seedColor: Colors.indigo, brightness: Brightness.dark);
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: themeMode == ThemeMode.dark
? darkScheme.background
: lightScheme.background,
systemNavigationBarColor: themeMode == ThemeMode.dark
? darkScheme.surface
: lightScheme.surface));
return MaterialApp(
navigatorKey: NavigationService.navigatorKey,
return ThemedApp(
builder: (lightScheme, darkScheme, isDarkMode) => MaterialApp(
theme: ThemeData(colorScheme: lightScheme, useMaterial3: true),
darkTheme: ThemeData(colorScheme: darkScheme, useMaterial3: true),
debugShowCheckedModeBanner: false,
title: 'Wormhole',
theme: ThemeData(
colorScheme: lightScheme,
),
darkTheme: ThemeData(
colorScheme: darkScheme,
),
themeMode: themeMode,
home: const BasePage(),
);
});
),
);
}
}
27 changes: 10 additions & 17 deletions lib/pages/receive_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:iyox_wormhole/gen/ffi.dart';
import 'package:iyox_wormhole/pages/qr_code_scanner_page.dart';
import 'package:iyox_wormhole/utils/type_helpers.dart';
import 'package:iyox_wormhole/utils/paths.dart';
import 'package:iyox_wormhole/utils/type_helpers.dart';

class ReceivePage extends StatefulWidget {
const ReceivePage({Key? key}) : super(key: key);
Expand Down Expand Up @@ -51,9 +51,8 @@ class _ReceivePageState extends State<ReceivePage> {
controller: _controller,
enabled: !transferring,
decoration: const InputDecoration(
border: OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(18))),
border:
OutlineInputBorder(borderRadius: BorderRadius.all(Radius.circular(18))),
floatingLabelBehavior: FloatingLabelBehavior.auto,
label: Text('Code'),
),
Expand Down Expand Up @@ -88,9 +87,7 @@ class _ReceivePageState extends State<ReceivePage> {
icon: const Icon(Icons.sim_card_download_outlined),
)
: LinearProgressIndicator(
value: downloadStarted
? receivedBytes / totalReceiveBytes
: null,
value: downloadStarted ? receivedBytes / totalReceiveBytes : null,
minHeight: 13,
borderRadius: BorderRadius.circular(18),
),
Expand All @@ -101,17 +98,17 @@ class _ReceivePageState extends State<ReceivePage> {
}

static final ButtonStyle buttonStyle = ButtonStyle(
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
shape: WidgetStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(200),
),
),
fixedSize: MaterialStateProperty.all<Size>(const Size(180, 60)),
fixedSize: WidgetStateProperty.all<Size>(const Size(180, 60)),
);

void _onQrButtonClicked() async {
final result = await Navigator.push(context,
MaterialPageRoute(builder: (context) => const QRScannerPage()));
final result = await Navigator.push(
context, MaterialPageRoute(builder: (context) => const QRScannerPage()));

if (!mounted) return;

Expand All @@ -127,8 +124,7 @@ class _ReceivePageState extends State<ReceivePage> {
Future<ServerConfig> _getServerConfig() async {
final rendezvousUrl = await api.defaultRendezvousUrl();
final transitUrl = await api.defaultTransitUrl();
final serverConfig =
ServerConfig(rendezvousUrl: rendezvousUrl, transitUrl: transitUrl);
final serverConfig = ServerConfig(rendezvousUrl: rendezvousUrl, transitUrl: transitUrl);
return serverConfig;
}

Expand All @@ -145,9 +141,7 @@ class _ReceivePageState extends State<ReceivePage> {

debugPrint('code: $code');
final stream = api.requestFile(
passphrase: code,
storageFolder: downloadPath,
serverConfig: await _getServerConfig());
passphrase: code, storageFolder: downloadPath, serverConfig: await _getServerConfig());

setState(() {
transferring = true;
Expand Down Expand Up @@ -193,5 +187,4 @@ class _ReceivePageState extends State<ReceivePage> {
}
});
}

}
4 changes: 1 addition & 3 deletions lib/pages/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class _BasePageState extends State<BasePage> {

@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
return Scaffold(
body: PageTransitionSwitcher(
transitionBuilder: (child, primaryAnimation, secondaryAnimation) =>
FadeThroughTransition(
Expand Down Expand Up @@ -61,7 +60,6 @@ class _BasePageState extends State<BasePage> {
selectedIcon: Icon(Icons.settings_rounded),
),
]),
),
);
}
}
Loading

0 comments on commit a29d171

Please sign in to comment.