Browse Source

[flutter_example_packages] Add photo_view, refactoring

merge-requests/21/head
Vitaliy Zarubin 2 years ago
parent
commit
253ed53dc4
  1. 19
      README.md
  2. BIN
      example/assets/images/large_image.jpg
  3. 1
      example/data/raw/gingerbread-man-christmas-treat-candy-cartoon.svg
  4. 1
      example/data/raw/links
  5. 5
      example/lib/packages/cached_network_image/page.dart
  6. 2
      example/lib/packages/packages.dart
  7. 8
      example/lib/packages/photo_view/model.dart
  8. 23
      example/lib/packages/photo_view/package.dart
  9. 82
      example/lib/packages/photo_view/page.dart
  10. 6
      example/lib/pages/home/page.dart
  11. 20
      example/lib/widgets/base/app_state.dart
  12. 7
      example/pubspec.lock
  13. 4
      example/pubspec.yaml
  14. 2
      example/run.sh
  15. 99
      script/build_example.sh
  16. 67
      script/vscode_properties.sh

19
README.md

@ -18,16 +18,24 @@ Packages made or for review
| [shared_preferences](https://pub.dev/packages/shared_preferences) | 2.1.2 | 4.0.2 | Review | - |
| [sqflite](https://pub.dev/packages/sqflite) | 2.2.6 | 4.0.2 | Review | - |
| [wakelock](https://pub.dev/packages/wakelock) | 0.6.2 | 4.0.2 | Review | - |
| xdga_directories | - | 4.0.2 | Review | Аналог [xdg_directories](https://pub.dev/packages/xdg_directories) |
| xdga_directories | 0.0.1 | 4.0.2 | Review | Аналог [xdg_directories](https://pub.dev/packages/xdg_directories) |
## Package verified
Verified packages on Aurora OS
| Package | Version | OS Version | State | Comment |
|-------------------------------------------------------------------------|----------|-------------|--------|------------------------------------|
| [flutter_cache_manager](https://pub.dev/packages/flutter_cache_manager) | 3.3.0 | 4.0.2 | Done | Depends on `path_provider` |
| [cached_network_image](https://pub.dev/packages/cached_network_image) | 3.2.3 | 4.0.2 | Done | Depends on `flutter_cache_manager` |
| Package | Version | OS Version | State | Comment |
|-------------------------------------------------------------------------|---------|-------------|--------|------------------------------------|
| [flutter_cache_manager](https://pub.dev/packages/flutter_cache_manager) | 3.3.0 | 4.0.2 | Done | Depends on `path_provider` |
| [cached_network_image](https://pub.dev/packages/cached_network_image) | 3.2.3 | 4.0.2 | Done | Depends on `flutter_cache_manager` |
| [crypto](https://pub.dev/packages/crypto) | 3.0.2 | 4.0.2 | Done | - |
| [cupertino_icons](https://pub.dev/packages/cupertino_icons) | 1.0.5 | 4.0.2 | Done | - |
| [get_it](https://pub.dev/packages/get_it) | 7.6.0 | 4.0.2 | Done | - |
| [google_fonts](https://pub.dev/packages/google_fonts) | 4.0.4 | 4.0.2 | Done | - |
| [intl](https://pub.dev/packages/intl) | 0.17.0 | 4.0.2 | Done | - |
| [photo_view](https://pub.dev/packages/photo_view) | 0.14.0 | 4.0.2 | Done | - |
| [scoped_model](https://pub.dev/packages/scoped_model) | 2.0.0 | 4.0.2 | Done | - |
| [universal_io](https://pub.dev/packages/universal_io) | 2.2.0 | 4.0.2 | Done | - |
## Package in progress
@ -39,7 +47,6 @@ Started development and its status
| [url_launcher](https://pub.dev/packages/url_launcher) | 6.1.11 | 5.0.0 | Waiting | [OpenURI](https://confluence.omprussia.ru/pages/viewpage.action?pageId=163055648) |
| [sensors_plus](https://pub.dev/packages/sensors_plus) | 3.0.2 | 4.0.2 | Blocked | Нет интерфейса для использования Sensors API без Qt |
## Package waiting
Packets waiting in line

BIN
example/assets/images/large_image.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

1
example/data/raw/gingerbread-man-christmas-treat-candy-cartoon.svg

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 52 KiB

1
example/data/raw/links

@ -1,2 +1,3 @@
https://iconduck.com/icons/94312/flutter
https://iconduck.com/icons/54169/package
https://iconduck.com/illustrations/108225/gingerbread-man-christmas-treat-candy-cartoon

5
example/lib/packages/cached_network_image/page.dart

@ -5,7 +5,6 @@ import 'package:flutter_example_packages/base/package/package.dart';
import 'package:flutter_example_packages/packages/cached_network_image/model.dart';
import 'package:flutter_example_packages/packages/cached_network_image/package.dart';
import 'package:flutter_example_packages/widgets/base/export.dart';
import 'package:flutter_example_packages/widgets/blocks/block_alert.dart';
import 'package:flutter_example_packages/widgets/blocks/block_info_package.dart';
import 'package:flutter_example_packages/widgets/layouts/block_layout.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
@ -46,9 +45,9 @@ class _CachedNetworkImagePageState extends AppState<CachedNetworkImagePage> {
child: CachedNetworkImage(
imageUrl: "https://via.placeholder.com/350x150",
placeholder: (context, url) =>
const CircularProgressIndicator(),
const CircularProgressIndicator(),
errorWidget: (context, url, error) =>
const Icon(Icons.error),
const Icon(Icons.error),
),
),
),

2
example/lib/packages/packages.dart

@ -11,6 +11,7 @@ import 'package:flutter_example_packages/packages/google_fonts/package.dart';
import 'package:flutter_example_packages/packages/intl/package.dart';
import 'package:flutter_example_packages/packages/package_info_plus/package.dart';
import 'package:flutter_example_packages/packages/path_provider/package.dart';
import 'package:flutter_example_packages/packages/photo_view/package.dart';
import 'package:flutter_example_packages/packages/scoped_model/package.dart';
import 'package:flutter_example_packages/packages/shared_preferences/package.dart';
import 'package:flutter_example_packages/packages/sqflite/package.dart';
@ -35,6 +36,7 @@ final packages = <Package>[
packageIntl,
packagePackageInfoPlus,
packagePathProvider,
packagePhotoView,
packageScopedModel,
packageSharedPreferences,
packageSqflite,

8
example/lib/packages/photo_view/model.dart

@ -0,0 +1,8 @@
import 'package:flutter/widgets.dart';
import 'package:scoped_model/scoped_model.dart';
/// Model for [PhotoViewPage]
class PhotoViewModel extends Model {
/// Get [ScopedModel]
static PhotoViewModel of(BuildContext context) => ScopedModel.of<PhotoViewModel>(context);
}

23
example/lib/packages/photo_view/package.dart

@ -0,0 +1,23 @@
import 'package:flutter_example_packages/base/package/package_page.dart';
import 'package:flutter_example_packages/packages/photo_view/page.dart';
import 'package:get_it/get_it.dart';
import 'model.dart';
/// Package values
final packagePhotoView = PackagePage(
key: 'photo_view',
descEN: '''
A simple zoomable image/content widget for Flutter.
''',
descRU: '''
Простой масштабируемый виджет изображения/контента для Flutter.
''',
version: '0.14.0',
isPlatformDependent: false,
page: () => PhotoViewPage(),
init: () {
GetIt.instance.registerFactory<PhotoViewModel>(
() => PhotoViewModel());
},
);

82
example/lib/packages/photo_view/page.dart

@ -0,0 +1,82 @@
import 'package:flutter/material.dart';
import 'package:flutter_example_packages/base/di/app_di.dart';
import 'package:flutter_example_packages/base/package/package.dart';
import 'package:flutter_example_packages/packages/photo_view/model.dart';
import 'package:flutter_example_packages/packages/photo_view/package.dart';
import 'package:flutter_example_packages/theme/radius.dart';
import 'package:flutter_example_packages/widgets/base/export.dart';
import 'package:flutter_example_packages/widgets/blocks/block_info_package.dart';
import 'package:flutter_example_packages/widgets/layouts/block_layout.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:photo_view/photo_view.dart';
class PhotoViewPage extends AppStatefulWidget {
PhotoViewPage({
super.key,
});
final Package package = packagePhotoView;
@override
State<PhotoViewPage> createState() => _PhotoViewPageState();
}
class _PhotoViewPageState extends AppState<PhotoViewPage> {
double _heightPhotoView = 1;
final _keyPhotoView = GlobalKey();
@override
void onDidChangeMetrics() {
setState(() {
_heightPhotoView = _getHeightPhotoView();
});
}
@override
Widget buildWide(
BuildContext context,
MediaQueryData media,
AppLocalizations l10n,
) {
return BlockLayout<PhotoViewModel>(
model: getIt<PhotoViewModel>(),
title: widget.package.key,
builder: (context, child, model) {
return SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
BlockInfoPackage(widget.package),
ClipRRect(
borderRadius: AppRadius.small,
child: SizedBox(
key: _keyPhotoView,
width: double.infinity,
height: _heightPhotoView,
child: PhotoView(
imageProvider:
const AssetImage("assets/images/large_image.jpg"),
),
),
),
],
),
),
);
},
);
}
double _getHeightPhotoView() {
if (_keyPhotoView.currentContext != null) {
RenderBox? box =
_keyPhotoView.currentContext?.findRenderObject() as RenderBox;
Offset position =
box.localToGlobal(Offset.zero); //this is global position
return MediaQuery.of(context).size.height - position.dy - 20;
}
return 1;
}
}

6
example/lib/pages/home/page.dart

@ -26,12 +26,6 @@ class _HomePageState extends AppState<HomePage> {
final HomeModel _model = getIt<HomeModel>();
final ScrollController _controllerListView = ScrollController();
@override
void initState() {
super.initState();
}
@override
void onDidChangeMetrics() {
setState(() {

20
example/lib/widgets/base/app_state.dart

@ -9,25 +9,24 @@ abstract class AppState<T extends StatefulWidget> extends State<T>
AppLocalizations l10n,
);
bool _isDispose = false;
void onPostFrameCallback() {}
void onDidChangeMetrics() {}
void _delayedChangeMetrics() {
onDidChangeMetrics();
Future.delayed(const Duration(milliseconds: 100), () {
onDidChangeMetrics();
});
Future.delayed(const Duration(milliseconds: 200), () {
onDidChangeMetrics();
});
Future.delayed(const Duration(milliseconds: 500), () {
onDidChangeMetrics();
});
for (int i = 0; i <= 5; i++) {
Future.delayed(Duration(milliseconds: 100 * i), () {
if (!_isDispose) {
onDidChangeMetrics();
}
});
}
}
@override
void initState() {
super.initState();
_isDispose = false;
WidgetsBinding.instance.addObserver(this);
WidgetsBinding.instance.addPostFrameCallback((_) {
_delayedChangeMetrics();
@ -41,6 +40,7 @@ abstract class AppState<T extends StatefulWidget> extends State<T>
@override
void dispose() {
_isDispose = true;
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}

7
example/pubspec.lock

@ -616,6 +616,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "5.1.0"
photo_view:
dependency: "direct main"
description:
name: photo_view
url: "https://pub.dartlang.org"
source: hosted
version: "0.14.0"
platform:
dependency: transitive
description:

4
example/pubspec.yaml

@ -20,7 +20,7 @@ dependencies:
## https://pub.dev/packages/scoped_model
scoped_model: ^2.0.0
## https://pub.dev/packages/get_it
get_it: ^7.2.0
get_it: ^7.6.0
## https://pub.dev/packages/intl
intl: ^0.17.0
## https://pub.dev/packages/universal_io
@ -31,6 +31,8 @@ dependencies:
cached_network_image: ^3.2.3
## https://pub.dev/packages/flutter_cache_manager
flutter_cache_manager: ^3.3.0
## https://pub.dev/packages/photo_view
photo_view: ^0.14.0
## https://os-git.omprussia.ru/non-oss/flutter/flutter-plugins/-/tree/master/packages/xdga_directories
xdga_directories:

2
example/run.sh

@ -14,7 +14,7 @@
## -s /home/user/sign/folder
## Flutter path
FLUTTER="$HOME/.local/opt/flutter-sdk/bin/flutter"
FLUTTER="$HOME/.local/opt/flutter/bin/flutter"
## https://developer.auroraos.ru/doc/software_development/psdk/setup
## Install Platform SDK path

99
script/build_example.sh

@ -1,99 +0,0 @@
#!/bin/bash
# Copyright (c) 2023. Open Mobile Platform LLC.
# License: Proprietary.
## Build example, sign rpm, upload/install/run rpm to device
## Usage
##
## chmod +x ./build_example.sh
##
## ./build_example.sh \
## -p xdga_directories \
## -d <ip>:<password> \
## -s /home/user/sign/system_keys
## Flutter path
FLUTTER="$HOME/.local/opt/flutter-sdk/bin/flutter"
## https://developer.auroraos.ru/doc/software_development/psdk/setup
## Install Platform SDK path
## You may not have set the PSDK_DIR environment variable.
## export PSDK_DIR=$HOME/AuroraPlatformSDK/sdks/aurora_psdk
while getopts p:d:s: flag; do
case "${flag}" in
p) package=${OPTARG} ;;
d) device=${OPTARG} ;;
s) sign=${OPTARG} ;;
*)
echo "usage: $0 [-p] [-d] [-s]" >&2
exit 1
;;
esac
done
if [ -z "$package" ]; then
echo "Specify a build package"
exit
else
cd "../packages/$package" 2>/dev/null || eval 'echo "Package \"$package\" not found." && exit'
## Update dependency
$FLUTTER pub get
## Run ffigen if has
$FLUTTER pub run ffigen --config ffigen.yaml 2>/dev/null
## Open example dir
cd "example" || exit
## Build aurora example app
{
$FLUTTER build aurora --release
} || {
exit 1;
}
fi
if [ -n "$sign" ]; then
key=$(ls "$sign"/*key.pem)
if [ -z "$key" ]; then
echo "Key *key.pem not found."
exit
fi
cert=$(ls "$sign"/*cert.pem)
if [ -z "$cert" ]; then
echo "Key *cert.pem not found."
exit
fi
## Sign rpm system key
"$PSDK_DIR"/sdk-chroot rpmsign-external sign \
--key "$key" \
--cert "$cert" \
build/aurora/arm/release/RPMS/*.rpm
fi
if [ -n "$device" ]; then
IFS=':' read -ra ADDR <<< "$device"
IFS='/' read -ra ADDP <<< "$package"
D_IP="${ADDR[0]}"
D_PASS="${ADDR[1]}"
APP_KEY="${ADDP[-1]}"
# shellcheck disable=SC2012
rpm=$(ls "$PWD"/build/aurora/arm/release/RPMS/*.rpm | sort -r | head -n 1)
# upload rpm
scp "$rpm" defaultuser@"$D_IP:/home/defaultuser/Downloads"
# install rpm
ssh -t defaultuser@$D_IP "echo $D_PASS | devel-su pkcon -y install-local /home/defaultuser/Downloads/*$APP_KEY*.rpm"
# run application
ssh -t defaultuser@$D_IP "/usr/bin/com.example.${APP_KEY}_example"
fi

67
script/vscode_properties.sh

@ -1,67 +0,0 @@
#!/bin/bash
# Copyright (c) 2023. Open Mobile Platform LLC.
# License: Proprietary.
## Script create c_cpp_properties.json with dependencies for flutter aurora
## Usage
##
## chmod +x ./vscode_properties.sh
## ./vscode_properties.sh
## https://developer.auroraos.ru/doc/software_development/psdk/setup
## Install Platform SDK path
## You may not have set the PSDK_DIR environment variable.
## export PSDK_DIR=$HOME/AuroraPlatformSDK/sdks/aurora_psdk
cd ../
## check file
[ -f .vscode/c_cpp_properties.json ] && { echo "File c_cpp_properties.json already exist!"; exit; }
## find target
TARGET=$($PSDK_DIR/sdk-chroot sdk-assistant list | grep armv | grep default | sed 's/^.*A/A/g' | sed 's/\s.*//g')
## mkdir .vscode if not exist
[ -d .vscode ] || mkdir .vscode
## find targets path
TARGETS_PATH=$(cd "$PSDK_DIR/../../" && pwd)/targets
## save file
tee -a .vscode/c_cpp_properties.json << END
{
"configurations": [
{
"name": "Linux",
"includePath": [
"\${workspaceFolder}/**",
"$TARGETS_PATH/$TARGET/usr/include",
"$TARGETS_PATH/$TARGET/usr/include/dconf",
"$TARGETS_PATH/$TARGET/usr/include/flutter-embedder",
"$TARGETS_PATH/$TARGET/usr/include/maliit",
"$TARGETS_PATH/$TARGET/usr/include/appmanifest-cpp",
"$TARGETS_PATH/$TARGET/usr/include/glib-2.0",
"$TARGETS_PATH/$TARGET/usr/lib/glib-2.0/include",
"$TARGETS_PATH/$TARGET/usr/include/sailfishapp",
"$TARGETS_PATH/$TARGET/usr/include/qt5",
"$TARGETS_PATH/$TARGET/usr/include/qt5/QtConcurrent",
"$TARGETS_PATH/$TARGET/usr/include/qt5/QtCore",
"$TARGETS_PATH/$TARGET/usr/include/qt5/QtDBus",
"$TARGETS_PATH/$TARGET/usr/include/qt5/QtGui",
"$TARGETS_PATH/$TARGET/usr/include/qt5/QtMultimedia",
"$TARGETS_PATH/$TARGET/usr/include/qt5/QtQuick"
],
"defines": [
"__ARM_PCS_VFP"
],
"compilerPath": "/usr/bin/g++",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
END
Loading…
Cancel
Save