Skip to content

Commit

Permalink
Clear cache fix (#22)
Browse files Browse the repository at this point in the history
* [WIP] Clear cache on exit

* clear cache
  • Loading branch information
EwuUwe authored Mar 20, 2024
1 parent ea76708 commit f1ea88c
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 72 deletions.
19 changes: 14 additions & 5 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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';
Expand Down Expand Up @@ -71,6 +72,10 @@ class WormholeAppState extends State<WormholeApp> with WidgetsBindingObserver {
systemNavigationBarColor: Colors.transparent,
);
SystemChrome.setSystemUIOverlayStyle(overlayStyle);

// Clear Cache
await FilePicker.platform.clearTemporaryFiles();
await Settings.setRecentFiles([]);
}

@override
Expand All @@ -95,9 +100,9 @@ class WormholeAppState extends State<WormholeApp> with WidgetsBindingObserver {
}

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

@override
Expand All @@ -119,7 +124,7 @@ class WormholeAppState extends State<WormholeApp> with WidgetsBindingObserver {
setState(() {
if (value == ThemeMode.system) {
themeMode =
brightness == Brightness.dark ? ThemeMode.dark : ThemeMode.light;
brightness == Brightness.dark ? ThemeMode.dark : ThemeMode.light;
} else {
themeMode = value;
}
Expand All @@ -135,8 +140,12 @@ class WormholeAppState extends State<WormholeApp> with WidgetsBindingObserver {
@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);
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
Expand Down
6 changes: 0 additions & 6 deletions lib/pages/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ class BasePage extends StatefulWidget {

class _BasePageState extends State<BasePage> {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
final pageController = PageController(
initialPage: 0,
);

int selectedPageIndex = 0;

Expand Down Expand Up @@ -43,9 +40,6 @@ class _BasePageState extends State<BasePage> {
setState(() {
selectedPageIndex = index;
});
pageController.animateToPage(index,
duration: const Duration(milliseconds: 2000),
curve: Curves.ease);
},
destinations: const [
NavigationDestination(
Expand Down
108 changes: 54 additions & 54 deletions lib/pages/sending_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ class _SendingPageState extends State<SendingPage> {
}

for (var file in widget.files) {
await Settings.addRecentFile(file);
setState(() {
Settings.addRecentFile(file);
});
}

stream.listen((e) {
Expand Down Expand Up @@ -181,65 +183,63 @@ class _SendingPageState extends State<SendingPage> {
return Center(
child: codeText == ''
? Padding(
padding: const EdgeInsets.all(10),
padding: const EdgeInsets.all(14),
child: LinearProgressIndicator(
value: shareProgress,
minHeight: 10,
borderRadius: BorderRadius.circular(18),
))
: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Card(
margin: const EdgeInsets.all(20),
child: Padding(
padding: const EdgeInsets.all(15),
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: QrImageView(
data: "wormhole-transfer:$codeText",
backgroundColor: Colors.white),
))),
const Gap(10),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Column(mainAxisSize: MainAxisSize.min, children: [
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
child: InkWell(
borderRadius: BorderRadius.circular(20),
onTap: () {
Clipboard.setData(ClipboardData(text: codeText));
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(
content: Text("Copied code to clipboard"),
));
},
child: Padding(
padding: const EdgeInsets.fromLTRB(15, 15, 15, 15),
child: Text(
codeText,
style: TextStyle(
height: 1.6,
fontSize: Theme.of(context)
.textTheme
.titleMedium!
.fontSize! +
1.5,
fontWeight: Theme.of(context)
.textTheme
.titleMedium
?.fontWeight),
)
),
),
: Padding(
padding: const EdgeInsets.all(20),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Card(
child: Padding(
padding: const EdgeInsets.all(15),
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: QrImageView(
data: "wormhole-transfer:$codeText",
backgroundColor: Colors.white),
))),
const Gap(10),
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(26),
),
]),
),
],
),
child: InkWell(
borderRadius: BorderRadius.circular(26),
onTap: () {
Clipboard.setData(ClipboardData(text: codeText));
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(
content: Text("Copied code to clipboard"),
));
},
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 13, vertical: 9),
child: Text(
codeText,
textAlign: TextAlign.center,
style: TextStyle(
height: 1.6,
fontSize: Theme.of(context)
.textTheme
.titleMedium!
.fontSize! +
1.5,
fontWeight: Theme.of(context)
.textTheme
.titleMedium
?.fontWeight),
)),
),
),
],
),
),
);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/pages/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class _SettingsPageState extends State<SettingsPage> {

@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(
return ListView(
children:[ Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Padding(
Expand Down Expand Up @@ -249,6 +249,6 @@ class _SettingsPageState extends State<SettingsPage> {
);
}),
],
));
)]);
}
}
8 changes: 4 additions & 4 deletions lib/widgets/recent_files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RecentFiles extends StatefulWidget {

class _RecentFilesState extends State<RecentFiles>
with SingleTickerProviderStateMixin {
bool recentCollapsed = false;
bool recentCollapsed = true;
late final AnimationController _controller;

@override
Expand Down Expand Up @@ -60,7 +60,7 @@ class _RecentFilesState extends State<RecentFiles>
),
const Spacer(),
RotationTransition(
turns: Tween(begin: 0.0, end: 1.0).animate(_controller),
turns: Tween(begin: 1.0, end: 0.0).animate(_controller),
child: IconButton.filledTonal(
iconSize: 23,
padding: const EdgeInsets.all(0),
Expand All @@ -69,9 +69,9 @@ class _RecentFilesState extends State<RecentFiles>
onPressed: () => {
setState(() {
if (recentCollapsed) {
_controller.reverse(from: 0.5);
} else {
_controller.forward(from: 0.0);
} else {
_controller.reverse(from: 0.5);
}
recentCollapsed = !recentCollapsed;
})
Expand Down

0 comments on commit f1ea88c

Please sign in to comment.