Skip to content

Commit

Permalink
version 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
YehudaKremer committed Mar 17, 2022
1 parent 0bd5ae4 commit 77023b8
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 68 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## 1.2.0

- enable to select a local background image
Binary file added assets/images/tulips-100_150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions lib/pages/background/BackgroundImageItem.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import 'dart:io';

import 'package:fluent_ui/fluent_ui.dart';
import 'package:provider/provider.dart';
import 'package:smart_watch_widget/pages/background/backgroundItem.dart';
import 'package:smart_watch_widget/state/appState.dart';

class BackgroundImageItem extends StatefulWidget {
final bool isSelected;
final void Function() onPressed;

const BackgroundImageItem(
{Key? key, required this.isSelected, required this.onPressed})
: super(key: key);

@override
State<BackgroundImageItem> createState() => _BackgroundImageItemState();
}

class _BackgroundImageItemState extends State<BackgroundImageItem>
with SingleTickerProviderStateMixin {
late Animation<double> animation;
late AnimationController controller;

@override
void initState() {
super.initState();
controller = AnimationController(
duration: const Duration(milliseconds: 75), vsync: this);
final Animation<double> curve =
CurvedAnimation(parent: controller, curve: Curves.easeIn);
animation = Tween<double>(begin: 0.8, end: 0.9).animate(curve);
}

final fit = BoxFit.fill;
final colorBlendMode = BlendMode.modulate;

@override
Widget build(BuildContext context) {
return MouseRegion(
onEnter: (_) => controller.forward(),
onExit: (_) => controller.reverse(),
child: BackgroundItem(
name: 'Image',
background: AnimatedBuilder(
animation: animation,
builder: (context, child) {
return context.watch<AppState>().background ==
Background.localImage &&
context.watch<AppState>().localImageBackground != null
? Image.file(
File(context.watch<AppState>().localImageBackground!),
fit: fit,
color: Colors.white.withOpacity(animation.value),
colorBlendMode: colorBlendMode)
: Image.asset('assets/images/tulips-100_150.png',
fit: fit,
color: Colors.white.withOpacity(animation.value),
colorBlendMode: colorBlendMode);
},
),
isSelected: widget.isSelected,
onPressed: widget.onPressed,
),
);
}
}
48 changes: 24 additions & 24 deletions lib/pages/background/backgroundItem.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,32 @@ class BackgroundItem extends StatelessWidget {

@override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(5)),
child: Button(
style: ButtonStyle(
padding: ButtonState.all(EdgeInsets.zero),
),
child: Stack(
alignment: Alignment.center,
children: [
background,
Text(name),
Positioned(
top: 5,
right: 5,
child: AnimatedSlideFade(
child: isSelected
? InfoBadge(
source: Icon(FluentIcons.accept),
)
: Container(),
),
return Button(
style: ButtonStyle(
padding: ButtonState.all(EdgeInsets.zero),
),
child: Stack(
fit: StackFit.expand,
children: [
ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(3)),
child: background,
),
Center(child: Text(name)),
Positioned(
top: 5,
right: 5,
child: AnimatedSlideFade(
child: isSelected
? InfoBadge(
source: Icon(FluentIcons.accept),
)
: Container(),
),
],
),
onPressed: onPressed,
),
],
),
onPressed: onPressed,
);
}
}
85 changes: 49 additions & 36 deletions lib/pages/background/backgroundPage.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import 'dart:io';

import 'package:file_picker/file_picker.dart';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:provider/provider.dart';
import 'package:smart_watch_widget/pages/background/BackgroundImageItem.dart';
import 'package:smart_watch_widget/pages/background/backgroundItem.dart';
import 'package:smart_watch_widget/pages/home/layout.dart';
import 'package:smart_watch_widget/pages/menu/menuItem.dart';
Expand All @@ -14,50 +18,59 @@ class BackgroundPage extends StatelessWidget {
return Layout(
child: Padding(
padding: const EdgeInsets.only(left: 30, right: 30, top: 30),
child: Column(
child: GridView.count(
primary: false,
crossAxisSpacing: 20,
mainAxisSpacing: 20,
crossAxisCount: 2,
children: [
MenuItem(
title: 'Go Back',
icon: FluentIcons.back,
onPressed: () => Navigator.pop(context),
),
Container(height: 10),
Expanded(
child: GridView.count(
primary: false,
crossAxisSpacing: 20,
mainAxisSpacing: 20,
crossAxisCount: 2,
children: [
BackgroundItem(
name: 'Empty',
background: Icon(
FluentIcons.blocked,
size: 50,
color: FluentTheme.of(context)
.typography
.body!
.color!
.withOpacity(0.2),
),
isSelected: context.watch<AppState>().background ==
Background.empty,
onPressed: () {
context.read<AppState>().setBackground(Background.empty);
},
),
BackgroundItem(
name: 'Waves',
background: Waves(),
isSelected: context.watch<AppState>().background ==
Background.waves,
onPressed: () {
context.read<AppState>().setBackground(Background.waves);
},
),
],
BackgroundItem(
name: 'Empty',
background: Icon(
FluentIcons.blocked,
size: 50,
color: FluentTheme.of(context)
.typography
.body!
.color!
.withOpacity(0.2),
),
isSelected:
context.watch<AppState>().background == Background.empty,
onPressed: () {
context.read<AppState>().setBackground(Background.empty);
},
),
BackgroundItem(
name: 'Waves',
background: Waves(),
isSelected:
context.watch<AppState>().background == Background.waves,
onPressed: () {
context.read<AppState>().setBackground(Background.waves);
},
),
BackgroundImageItem(
isSelected: context.watch<AppState>().background ==
Background.localImage,
onPressed: () async {
FilePickerResult? result =
await FilePicker.platform.pickFiles(type: FileType.image);

if (result != null) {
var path = result.files.single.path;
if (path != null && path.isNotEmpty) {
context.read<AppState>().setBackground(
Background.localImage,
localImage: path);
}
}
}),
],
),
),
Expand Down
19 changes: 16 additions & 3 deletions lib/pages/home/layout.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:fluent_ui/fluent_ui.dart';
import 'package:provider/provider.dart';
import 'package:smart_watch_widget/utils/animations.dart';
Expand All @@ -12,6 +14,8 @@ class Layout extends StatelessWidget {
@override
Widget build(BuildContext context) {
registerGeneralHotKeys(context);
var background = context.watch<AppState>().background;
var localImageBackground = context.watch<AppState>().localImageBackground;

return Padding(
padding: const EdgeInsets.all(2),
Expand All @@ -31,11 +35,20 @@ class Layout extends StatelessWidget {
),
child: ClipOval(
child: Stack(
fit: StackFit.expand,
children: [
AnimatedSlideFade(
child:
context.watch<AppState>().background == Background.waves
? Waves()
child: background == Background.waves
? Waves()
: background == Background.localImage &&
localImageBackground != null
? Container(
constraints: BoxConstraints.expand(),
child: Image.file(File(localImageBackground),
fit: BoxFit.fitHeight,
color: Colors.white.withOpacity(0.9),
colorBlendMode: BlendMode.modulate),
)
: Container(),
),
child,
Expand Down
24 changes: 21 additions & 3 deletions lib/state/appState.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import 'dart:io';

import 'package:fluent_ui/fluent_ui.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:system_theme/system_theme.dart';

const windowPositionDx = 'windowPositionDx';
const windowPositionDy = 'windowPositionDy';
const backgroundKey = 'background';
enum Background { empty, waves }
const localImageBackgroundKey = 'localImageBackground';
enum Background { empty, waves, localImage }

class AppState extends ChangeNotifier {
final SharedPreferences prefs;
bool _isWindowFocused = true;
String? _localImageBackground;
Brightness _brightness = Brightness.dark;
Background _background = Background.empty;
Offset? _windowPosition;
Offset? get windowPosition => _windowPosition;
bool get isWindowFocused => _isWindowFocused;
Brightness get brightness => _brightness;
Background get background => _background;
String? get localImageBackground => _localImageBackground;

AppState(this.prefs) {
_getWindowPosition();
Expand Down Expand Up @@ -52,17 +57,30 @@ class AppState extends ChangeNotifier {
prefs.setDouble(windowPositionDy, value.dy);
}

void _getBackground() {
Future<void> _getBackground() async {
var backgroundString = prefs.getString(backgroundKey);
if (backgroundString != null && backgroundString.isNotEmpty) {
_background = Background.values
.firstWhere((e) => e.toString() == prefs.getString(backgroundKey));
if (_background == Background.localImage) {
var path = prefs.getString(localImageBackgroundKey);
if (path != null && await File(path).exists()) {
_localImageBackground = path;
}
}
notifyListeners();
}
}

void setBackground(Background background) {
Future<void> setBackground(Background background,
{String? localImage}) async {
_background = background;
if (localImage != null &&
localImage.isNotEmpty &&
await File(localImage).exists()) {
_localImageBackground = localImage;
prefs.setString(localImageBackgroundKey, localImage);
}
notifyListeners();
prefs.setString(backgroundKey, background.toString());
}
Expand Down
14 changes: 14 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.2"
file_picker:
dependency: "direct main"
description:
name: file_picker
url: "https://pub.dartlang.org"
source: hosted
version: "4.5.1"
fluent_ui:
dependency: "direct main"
description:
Expand Down Expand Up @@ -190,6 +197,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
name: flutter_plugin_android_lifecycle
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down
6 changes: 4 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: smart_watch_widget
description: A smart watch widget for windows.
publish_to: "none"
version: 1.1.0
version: 1.2.0

environment:
sdk: ">=2.16.1 <3.0.0"
Expand Down Expand Up @@ -32,6 +32,7 @@ dependencies:
flutter_colorpicker: ^1.0.3
hexcolor: ^2.0.6
wave: ^0.2.0
file_picker: ^4.5.1

dev_dependencies:
flutter_test:
Expand All @@ -42,13 +43,14 @@ flutter:
uses-material-design: true
assets:
- assets/audio/Twin-bell-alarm-clock.mp3
- assets/images/

msix_config:
display_name: Smart Watch Widget
publisher_display_name: Kremer Software
identity_name: 48434KremerSoftware.SmartWatchWidget
publisher: CN=BF257F3F-5644-46DF-8668-014044C1B138
msix_version: 1.1.0.0
msix_version: 1.2.0.0
logo_path: images\logo-light.png
enable_at_startup : true
store: true

0 comments on commit 77023b8

Please sign in to comment.