Skip to content

Commit

Permalink
+breaking: Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
robmllze committed Sep 27, 2024
1 parent b47168b commit 57f3a97
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 82 deletions.
3 changes: 2 additions & 1 deletion lib/src/sc_on_num_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ import 'scalable_app.dart';

extension ScOnNumExtension on num {
/// Multiples the num with the current app scale.
double get sc => this * (ScalableApp.snapshot ?? 1.0);
// ignore: invalid_use_of_protected_member
double get sc => this * (AppScale.di.getSyncOrNull() ?? 1.0);
}
90 changes: 11 additions & 79 deletions lib/src/scalable_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,88 +10,20 @@
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//.title~

import 'dart:async';

import 'package:df_di/df_di.dart';
import 'package:df_pod/df_pod.dart';
import 'package:flutter/widgets.dart';

// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

class ScalableApp extends StatelessWidget {
//
//
//

final Widget child;

//
//
//

const ScalableApp({
super.key,
required this.child,
});

//
//
//

@override
Widget build(BuildContext context) {
return PodBuilder(
pod: ScalableApp.pod,
builder: (context, snapshot) {
return SizedBox(
key: UniqueKey(),
child: child,
);
},
child: child,
);
}

//
//
//

static TSharedGlobalDoublePod? _pAppScale;
static double? get snapshot => _pAppScale?.value;

//
//
//

static const _KEY = '<SCALE>';

//
//
//

static final Future<TSharedGlobalDoublePod> _pFutureAppScale =
SharedDoublePodCreator.global(_KEY).then((e) => _pAppScale = e);

//
//
//

static Future<void> set(double value) async {
final e = await _pFutureAppScale;
await e.set(value);
}

//
//
//

static Future<double?> get() async {
final e = await _pFutureAppScale;
return e.value;
}

//
//
//

static Future<PodListenable<double?>> get pod async {
return _pFutureAppScale;
}
final class AppScale {
AppScale._();
@protected
static final di = DI();
static final Future<TSharedGlobalDoublePod> _pValue =
SharedDoublePodCreator.global('<AppScale.pValue>')
.then((e) => di.register<TSharedGlobalDoublePod>(_pValue));
static FutureOr<TSharedGlobalDoublePod> get pAppScale => di.until<TSharedGlobalDoublePod>();
}
5 changes: 3 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

name: df_scalable
description: A package that provides a convenient method to scale your app UI up or down.
version: 0.2.9
version: 0.3.0
repository: https://github.com/robmllze/df_scalable
funding:
- https://www.buymeacoffee.com/robmllze
Expand All @@ -33,7 +33,8 @@ environment:
dependencies:
flutter:
sdk: flutter
df_pod: ^0.12.2
df_pod: ^0.13.0
df_di: ^0.6.0

## -----------------------------------------------------------------------------

Expand Down

0 comments on commit 57f3a97

Please sign in to comment.