Remove wallpaperPhoto view and related logic (saved in feature/wallpaper-sharing branch if needed in the future)

This commit is contained in:
Shawn 2023-10-19 16:25:02 -06:00
parent 1b07243f25
commit 48e9b5fc25
9 changed files with 0 additions and 288 deletions

View File

@ -1,59 +0,0 @@
import 'dart:async';
import 'dart:io';
import 'dart:ui' as ui;
import 'package:flutter/rendering.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:path_provider/path_provider.dart';
import 'package:share_plus/share_plus.dart';
import 'package:wonders/common_libs.dart';
import 'package:wonders/logic/common/platform_info.dart';
import 'package:wonders/ui/common/modals/app_modals.dart';
class WallPaperLogic {
/// Walks user through flow to save a Wonder Poster to their gallery
Future<void> save(State state, RenderRepaintBoundary boundary, {required String name}) async {
// Time to create an image!
Uint8List? pngBytes = await _getPngFromBoundary(boundary);
final context = state.context, mounted = state.mounted;
if (pngBytes != null && mounted) {
bool? result = await showModal(context,
child: OkCancelModal(
msg: $strings.wallpaperModalSave,
));
if (result == true && mounted) {
showModal(context, child: LoadingModal(msg: $strings.wallpaperModalSaving));
if (PlatformInfo.isMobile) {
await ImageGallerySaver.saveImage(pngBytes, quality: 95, name: name);
} else {
await Future.delayed(500.ms);
}
if (state.mounted) {
Navigator.pop(context);
showModal(context, child: OkModal(msg: $strings.wallpaperModalSaveComplete));
}
}
}
}
Future<void> share(BuildContext context, RenderRepaintBoundary boundary,
{required String name, String wonderName = 'Wonderous'}) async {
Uint8List? pngBytes = await _getPngFromBoundary(boundary);
if (pngBytes != null) {
final directory = (await getApplicationDocumentsDirectory()).path;
File imgFile = File('$directory/$name.png');
await imgFile.writeAsBytes(pngBytes);
Share.shareXFiles([XFile(imgFile.path)],
subject: '$wonderName Wallpaper', text: 'Check out this $wonderName wallpaper from the Wonderous app!');
}
}
}
Future<Uint8List?> _getPngFromBoundary(RenderRepaintBoundary boundary) async {
ui.Image uiImage = await boundary.toImage();
ByteData? byteData = await uiImage.toByteData(format: ui.ImageByteFormat.png);
if (byteData != null) {
return byteData.buffer.asUint8List();
}
return null;
}

View File

@ -8,7 +8,6 @@ import 'package:wonders/logic/artifact_api_logic.dart';
import 'package:wonders/logic/artifact_api_service.dart';
import 'package:wonders/logic/timeline_logic.dart';
import 'package:wonders/logic/unsplash_logic.dart';
import 'package:wonders/logic/wallpaper_logic.dart';
import 'package:wonders/logic/wonders_logic.dart';
void main() async {
@ -79,7 +78,6 @@ SettingsLogic get settingsLogic => GetIt.I.get<SettingsLogic>();
UnsplashLogic get unsplashLogic => GetIt.I.get<UnsplashLogic>();
ArtifactAPILogic get metAPILogic => GetIt.I.get<ArtifactAPILogic>();
CollectiblesLogic get collectiblesLogic => GetIt.I.get<CollectiblesLogic>();
WallPaperLogic get wallpaperLogic => GetIt.I.get<WallPaperLogic>();
LocaleLogic get localeLogic => GetIt.I.get<LocaleLogic>();
/// Global helpers for readability

View File

@ -9,7 +9,6 @@ import 'package:wonders/ui/screens/collection/collection_screen.dart';
import 'package:wonders/ui/screens/home/wonders_home_screen.dart';
import 'package:wonders/ui/screens/intro/intro_screen.dart';
import 'package:wonders/ui/screens/timeline/timeline_screen.dart';
import 'package:wonders/ui/screens/wallpaper_photo/wallpaper_photo_screen.dart';
import 'package:wonders/ui/screens/wonder_details/wonders_details_screen.dart';
/// Shared paths / urls used across the app
@ -69,9 +68,6 @@ final appRouter = GoRouter(
AppRoute('/maps/:type', (s) {
return FullscreenMapsViewer(type: _parseWonderType(s.params['type']));
}),
AppRoute('/wallpaperPhoto/:type', (s) {
return WallpaperPhotoScreen(type: _parseWonderType(s.params['type']));
}),
]),
],
);

View File

@ -1,176 +0,0 @@
import 'dart:async';
import 'package:flutter/rendering.dart';
import 'package:wonders/common_libs.dart';
import 'package:wonders/logic/common/platform_info.dart';
import 'package:wonders/logic/data/wonder_data.dart';
import 'package:wonders/ui/common/app_icons.dart';
import 'package:wonders/ui/common/controls/checkbox.dart';
import 'package:wonders/ui/wonder_illustrations/common/animated_clouds.dart';
import 'package:wonders/ui/wonder_illustrations/common/wonder_illustration.dart';
import 'package:wonders/ui/wonder_illustrations/common/wonder_illustration_config.dart';
import 'package:wonders/ui/wonder_illustrations/common/wonder_title_text.dart';
class WallpaperPhotoScreen extends StatefulWidget {
const WallpaperPhotoScreen({Key? key, required this.type}) : super(key: key);
final WonderType type;
@override
State<WallpaperPhotoScreen> createState() => _WallpaperPhotoScreenState();
}
class _WallpaperPhotoScreenState extends State<WallpaperPhotoScreen> {
final GlobalKey _containerKey = GlobalKey();
Widget? _illustration;
bool _showTitleText = true;
Timer? _photoRetryTimer;
@override
void dispose() {
_photoRetryTimer?.cancel();
super.dispose();
}
void _handleTakePhoto(BuildContext context, String wonderName) async {
final boundary = _containerKey.currentContext?.findRenderObject() as RenderRepaintBoundary?;
if (boundary != null) {
wallpaperLogic.save(this, boundary, name: '${wonderName}_wallpaper');
}
}
void _handleSharePhoto(BuildContext context, String wonderName) async {
final boundary = _containerKey.currentContext!.findRenderObject() as RenderRepaintBoundary;
wallpaperLogic.share(context, boundary, name: '${wonderName}_wallpaper', wonderName: wonderName);
}
void _handleTextToggle(bool? isActive) {
setState(() => _showTitleText = isActive ?? !_showTitleText);
}
@override
Widget build(BuildContext context) {
WonderData wonderData = wondersLogic.getData(widget.type);
WonderIllustrationConfig bgConfig = WonderIllustrationConfig.bg(
enableAnims: false,
enableHero: false,
);
WonderIllustrationConfig fgConfig = WonderIllustrationConfig(
enableAnims: false,
enableHero: false,
enableBg: false,
);
Color fgColor = wonderData.type.bgColor; //.withOpacity(.5);
_illustration = RepaintBoundary(
key: _containerKey,
child: ClipRect(
child: Stack(
children: [
// Background - apply additional filter to make moon brighter
WonderIllustration(
widget.type,
config: bgConfig,
),
// Clouds
FractionallySizedBox(
widthFactor: 1,
heightFactor: .5,
child: AnimatedClouds(
wonderType: wonderData.type,
opacity: 1,
enableAnimations: false,
),
),
// Wonder illustration
WonderIllustration(
widget.type,
config: fgConfig,
),
// Foreground gradient
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
fgColor.withOpacity(0),
fgColor.withOpacity(fgColor.opacity * .75),
],
stops: const [0, 1],
),
),
),
// Title text
if (_showTitleText)
BottomCenter(
child: Transform.translate(
offset: Offset(0.0, -$styles.insets.xl * 2),
child: WonderTitleText(wonderData, enableShadows: true),
),
),
],
),
),
);
return Stack(children: [
Container(
decoration: BoxDecoration(backgroundBlendMode: BlendMode.color, color: Colors.blue),
child: _illustration ?? Container(),
),
TopCenter(
child: SafeArea(
child: Padding(
padding: EdgeInsets.all($styles.insets.md),
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: BackBtn.close(
bgColor: $styles.colors.offWhite,
iconColor: $styles.colors.black,
),
),
Expanded(child: Container()),
Padding(
padding: const EdgeInsets.only(top: 10.0, bottom: 10.0, right: 16.0),
child: CircleIconBtn(
icon: PlatformInfo.isIOS ? AppIcons.share_ios : AppIcons.share_android,
bgColor: $styles.colors.offWhite,
color: $styles.colors.black,
onPressed: () => _handleSharePhoto(context, wonderData.title),
semanticLabel: $strings.wallpaperSemanticSharePhoto,
size: 44,
),
),
CircleIconBtn(
icon: AppIcons.download,
onPressed: () => _handleTakePhoto(context, wonderData.title),
semanticLabel: $strings.wallpaperSemanticTakePhoto,
size: 64,
),
],
),
),
),
),
BottomCenter(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SimpleCheckbox(
active: _showTitleText, label: $strings.wallpaperCheckboxShowTitle, onToggled: _handleTextToggle),
Gap($styles.insets.xl),
],
),
),
]);
}
}

View File

@ -8,7 +8,6 @@ import Foundation
import desktop_window
import package_info_plus
import path_provider_foundation
import share_plus
import shared_preferences_foundation
import url_launcher_macos
@ -16,7 +15,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
DesktopWindowPlugin.register(with: registry.registrar(forPlugin: "DesktopWindowPlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}

View File

@ -73,14 +73,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.1.1"
cross_file:
dependency: transitive
description:
name: cross_file
sha256: fd832b5384d0d6da4f6df60b854d33accaaeb63aa9e10e736a87381f08dee2cb
url: "https://pub.dev"
source: hosted
version: "0.3.3+5"
crypto:
dependency: transitive
description:
@ -480,14 +472,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.9.1"
mime:
dependency: transitive
description:
name: mime
sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e
url: "https://pub.dev"
source: hosted
version: "1.0.4"
nested:
dependency: transitive
description:
@ -672,22 +656,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.0"
share_plus:
dependency: "direct main"
description:
name: share_plus
sha256: f86c5acc512b20e074137075824fc29e29b2cf395dcbfcc371e96e3e6290cce1
url: "https://pub.dev"
source: hosted
version: "8.0.0"
share_plus_platform_interface:
dependency: transitive
description:
name: share_plus_platform_interface
sha256: "357412af4178d8e11d14f41723f80f12caea54cf0d5cd29af9dcdab85d58aea7"
url: "https://pub.dev"
source: hosted
version: "3.3.0"
shared_preferences:
dependency: "direct main"
description:
@ -893,14 +861,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.8"
uuid:
dependency: transitive
description:
name: uuid
sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313"
url: "https://pub.dev"
source: hosted
version: "3.0.7"
vector_graphics:
dependency: transitive
description:

View File

@ -43,7 +43,6 @@ dependencies:
pointer_interceptor: ^0.9.3+6
provider: ^6.0.5
rnd: ^0.2.0
share_plus: ^8.0.0
shared_preferences: ^2.0.17
sized_context: ^1.0.0+1
smooth_page_indicator: ^1.0.1

View File

@ -7,14 +7,11 @@
#include "generated_plugin_registrant.h"
#include <desktop_window/desktop_window_plugin.h>
#include <share_plus/share_plus_windows_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
DesktopWindowPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("DesktopWindowPlugin"));
SharePlusWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}

View File

@ -4,7 +4,6 @@
list(APPEND FLUTTER_PLUGIN_LIST
desktop_window
share_plus
url_launcher_windows
)