Skip to content

Commit

Permalink
Design changes (#324)
Browse files Browse the repository at this point in the history
* Refactoring and updates

* Improvements and refactoring

* New home screen

* Format

* Update config

* Don't extract version from FVM

* Removed intl_utils from CI
  • Loading branch information
hawkkiller authored Mar 30, 2024
1 parent c51ae3d commit adf99cc
Show file tree
Hide file tree
Showing 26 changed files with 257 additions and 285 deletions.
3 changes: 1 addition & 2 deletions .fvm/fvm_config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"flutterSdkVersion": "3.16.0",
"flavors": {}
"flutterSdkVersion": "3.19.4"
}
3 changes: 3 additions & 0 deletions .fvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"flutter": "3.19.4"
}
8 changes: 1 addition & 7 deletions .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,21 @@ jobs:
- name: 📚 Git Checkout
uses: actions/checkout@v3

- name: Get Flutter Version From FVM config
id: get_flutter_version
run: echo "::set-output name=version::$(cat .fvm/fvm_config.json | jq -r '.flutterSdkVersion')"

- name: 🐦 Setup Flutter
uses: subosito/[email protected]
with:
flutter-version: ${{ steps.get_flutter_version.outputs.version }}
flutter-version: 3.19.4
channel: stable
cache: true
cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }}

- name: 📦 Install Dependencies
run: |
flutter pub global activate very_good_cli
flutter pub global activate intl_utils
flutter pub global activate coverage
- name: 🦄 Generate Code
run: |
flutter pub global run intl_utils:generate
dart run build_runner build --delete-conflicting-outputs
- name: Install DCM
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,6 @@ pubspec.lock
.metadata

# FVM
.fvm/flutter_sdk

# FVM Version Cache
.fvm/
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"drift"
],
"dart.lineLength": 80,
"dart.flutterSdkPath": ".fvm/flutter_sdk"
"dart.flutterSdkPath": ".fvm/versions/3.19.4"
}
4 changes: 2 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,5 @@ dart_code_metrics:
- prefer-trailing-comma
- unnecessary-trailing-comma
- prefer-declaring-const-constructor
- prefer-single-widget-per-file:
ignore-private-widgets: true
# - prefer-single-widget-per-file:
# ignore-private-widgets: true
2 changes: 1 addition & 1 deletion l10n.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
arb-dir: lib/src/core/localization/translations
arb-dir: lib/src/core/constant/localization/translations
template-arb-file: intl_en.arb
output-localization-file: app_localizations.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import 'package:sizzle_starter/src/feature/initialization/model/environment.dart';

/// {@template environment_store}
/// Environment store
/// {@endtemplate}
class EnvironmentStore {
/// {@macro environment_store}
const EnvironmentStore();
/// Application configuration
class Config {
/// Creates a new [Config] instance.
const Config();

/// The Sentry DSN.
String get sentryDsn => const String.fromEnvironment('SENTRY_DSN');

/// The environment.
/// The current environment.
Environment get environment {
var environment = const String.fromEnvironment('ENVIRONMENT');

Expand All @@ -23,6 +18,9 @@ class EnvironmentStore {
return Environment.from(environment);
}

/// The Sentry DSN.
String get sentryDsn => const String.fromEnvironment('SENTRY_DSN');

/// Whether Sentry is enabled.
bool get enableTrackingManager => sentryDsn.isNotEmpty;
bool get enableSentry => sentryDsn.isNotEmpty;
}
File renamed without changes.
2 changes: 2 additions & 0 deletions lib/src/core/utils/layout/layout.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'material_spacing.dart';
export 'window_size.dart';
44 changes: 44 additions & 0 deletions lib/src/core/utils/layout/material_spacing.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import 'dart:math' as math;

import 'package:flutter/widgets.dart';
import 'package:sizzle_starter/src/core/utils/layout/layout.dart';

/// {@template material_spacer}
/// A spacer refers to the space between two panes in a layout.
///
/// Spacers measure 24dp wide.
/// {@endtemplate}
class MaterialSpacer extends StatelessWidget {
/// {@macro material_spacer}
const MaterialSpacer({super.key, this.spacing = 24});

/// Creates a spacer that is 24dp wide.
final double spacing;

@override
Widget build(BuildContext context) => SizedBox(width: spacing);
}

/// {@template horizontal_spacing}
/// Spacing that is applied to element to both the left and right.
/// {@endtemplate}
class HorizontalSpacing extends EdgeInsets {
const HorizontalSpacing._(final double value)
: super.symmetric(horizontal: value);

/// Horizontal spacing for [WindowSize.compact].
const HorizontalSpacing.compact() : this._(16);

/// Horizontal spacing for [WindowSize.medium]+.
const HorizontalSpacing.mediumUp() : this._(24);

/// Spacing that is used to center
/// the element and keep at width of [maxWidth]
///
/// [windowWidth] is the width of a window.
factory HorizontalSpacing.centered(
double windowWidth, [
double maxWidth = 768,
]) =>
HorizontalSpacing._(math.max((windowWidth - maxWidth) / 2, 16));
}
92 changes: 92 additions & 0 deletions lib/src/core/utils/layout/window_size.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';

/// A breakpoint that is used to determine the layout of the application.
///
/// It follows the Material Design guidelines for breakpoints.
///
/// See more:
/// - https://m3.material.io/foundations/layout/applying-layout
enum WindowSize {
/// Layouts for compact window size classes
/// are for screen widths smaller than 600dp.
compact._(0, 600),

/// Layouts for medium window size classes
/// are for screen widths from 600dp to 839dp.
medium._(600, 839),

/// Layouts for expanded window size classes
/// are for screen widths 840dp to 1199dp.
expanded._(840, 1199),

/// Layouts for large window size classes
/// are for screen widths from 1200dp to 1599dp.
large._(1200, 1599),

/// Layouts for extra-large window size classes
/// are for screen widths of 1600dp and larger.
extraLarge._(1600, double.infinity);

/// The minimum width of the breakpoint.
final double min;

/// The maximum width of the breakpoint.
final double max;

/// Returns whether the given width is in the range of the breakpoint.
bool isInRange(double width) => width >= min && width <= max;

/// Returns whether the given width isless than
/// the minimum width of the breakpoint.
bool operator <(WindowSize other) => max < other.min;

/// Returns whether the given width is greater than
/// the maximum width of the breakpoint.
bool operator >(WindowSize other) => min > other.max;

/// Returns whether the given width is less than
/// or equal to the maximum width of the breakpoint.
bool operator <=(WindowSize other) => max <= other.max;

/// Returns whether the given width is greater than
/// or equal to the minimum width of the breakpoint.
bool operator >=(WindowSize other) => min >= other.min;

/// If the breakpoint is compact.
bool get isCompact => this == WindowSize.compact;

/// If the breakpoint is medium.
bool get isMedium => this == WindowSize.medium;

/// If the breakpoint is expanded.
bool get isExpanded => this == WindowSize.expanded;

/// If the breakpoint is large.
bool get isLarge => this == WindowSize.large;

/// If the breakpoint is extra-large.
bool get isExtraLarge => this == WindowSize.extraLarge;

const WindowSize._(this.min, this.max);
}

/// A set of extensions for [WindowSize] on [BoxConstraints].
extension WindowSizeConstrainsExtension on BoxConstraints {
/// Returns the [WindowSize] for the given constraints.
WindowSize get materialBreakpoint {
final side = biggest.width;

if (WindowSize.compact.isInRange(side)) {
return WindowSize.compact;
} else if (WindowSize.medium.isInRange(side)) {
return WindowSize.medium;
} else if (WindowSize.expanded.isInRange(side)) {
return WindowSize.expanded;
} else if (WindowSize.large.isInRange(side)) {
return WindowSize.large;
}

return WindowSize.extraLarge;
}
}
18 changes: 11 additions & 7 deletions lib/src/core/utils/preferences_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@ abstract base class PreferencesDao {
: _sharedPreferences = sharedPreferences;

/// Obtain [bool] entry from the preferences.
PreferencesEntry<bool> boolEntry(String key) => _PreferencesEntry<bool>(
PreferencesEntry<bool> boolEntry(String key) => TypedEntry<bool>(
key: key,
sharedPreferences: _sharedPreferences,
);

/// Obtain [double] entry from the preferences.
PreferencesEntry<double> doubleEntry(String key) => _PreferencesEntry<double>(
PreferencesEntry<double> doubleEntry(String key) => TypedEntry<double>(
key: key,
sharedPreferences: _sharedPreferences,
);

/// Obtain [int] entry from the preferences.
PreferencesEntry<int> intEntry(String key) => _PreferencesEntry<int>(
PreferencesEntry<int> intEntry(String key) => TypedEntry<int>(
key: key,
sharedPreferences: _sharedPreferences,
);

/// Obtain [String] entry from the preferences.
PreferencesEntry<String> stringEntry(String key) => _PreferencesEntry<String>(
PreferencesEntry<String> stringEntry(String key) => TypedEntry<String>(
key: key,
sharedPreferences: _sharedPreferences,
);

/// Obtain [Iterable<String>] entry from the preferences.
PreferencesEntry<Iterable<String>> iterableStringEntry(String key) =>
_PreferencesEntry<Iterable<String>>(
TypedEntry<Iterable<String>>(
key: key,
sharedPreferences: _sharedPreferences,
);
Expand Down Expand Up @@ -69,8 +69,12 @@ abstract base class PreferencesEntry<T extends Object> {
value == null ? remove() : set(value);
}

final class _PreferencesEntry<T extends Object> extends PreferencesEntry<T> {
_PreferencesEntry({
/// {@template typed_entry}
/// A [PreferencesEntry] that is typed to a specific type [T].
/// {@endtemplate}
final class TypedEntry<T extends Object> extends PreferencesEntry<T> {
/// {@macro typed_entry}
TypedEntry({
required SharedPreferences sharedPreferences,
required this.key,
}) : _sharedPreferences = sharedPreferences;
Expand Down
12 changes: 4 additions & 8 deletions lib/src/feature/app/logic/app_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:async';
import 'package:bloc_concurrency/bloc_concurrency.dart' as bloc_concurrency;
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:sizzle_starter/src/core/constant/config.dart';
import 'package:sizzle_starter/src/core/utils/app_bloc_observer.dart';
import 'package:sizzle_starter/src/core/utils/logger.dart';
import 'package:sizzle_starter/src/feature/app/widget/app.dart';
Expand All @@ -12,7 +13,7 @@ import 'package:sizzle_starter/src/feature/initialization/widget/initialization_
/// {@template app_runner}
/// A class which is responsible for initialization and running the app.
/// {@endtemplate}
final class AppRunner with InitializationFactoryImpl {
final class AppRunner {
/// {@macro app_runner}
const AppRunner();

Expand All @@ -31,13 +32,8 @@ final class AppRunner with InitializationFactoryImpl {
// Setup bloc observer and transformer
Bloc.observer = const AppBlocObserver();
Bloc.transformer = bloc_concurrency.sequential();

final environmentStore = getEnvironmentStore();

final initializationProcessor = InitializationProcessor(
trackingManager: createTrackingManager(environmentStore),
environmentStore: environmentStore,
);
const config = Config();
const initializationProcessor = InitializationProcessor(config);

Future<void> initializeAndRun() async {
try {
Expand Down
13 changes: 6 additions & 7 deletions lib/src/feature/app/logic/tracking_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:sizzle_starter/src/core/utils/logger.dart';
/// {@template error_tracking_manager}
/// A class which is responsible for enabling error tracking.
/// {@endtemplate}
abstract interface class ExceptionTrackingManager {
abstract interface class ErrorTrackingManager {
/// Enables error tracking.
///
/// This method should be called when the user has opted in to error tracking.
Expand All @@ -20,13 +20,12 @@ abstract interface class ExceptionTrackingManager {
Future<void> disableReporting();
}

/// {@template sentry_tracking_manager}
/// {@template error_tracking_manager_base}
/// A class that is responsible for managing Sentry error tracking.
/// {@endtemplate}
abstract base class ExceptionTrackingManagerBase
implements ExceptionTrackingManager {
/// {@macro sentry_tracking_manager}
ExceptionTrackingManagerBase(this._logger);
abstract base class ErrorTrackingManagerBase implements ErrorTrackingManager {
/// {@macro error_tracking_manager_base}
ErrorTrackingManagerBase(this._logger);

final Logger _logger;
StreamSubscription<LogMessage>? _subscription;
Expand Down Expand Up @@ -69,7 +68,7 @@ abstract base class ExceptionTrackingManagerBase
/// {@template sentry_tracking_manager}
/// A class that is responsible for managing Sentry error tracking.
/// {@endtemplate}
final class SentryTrackingManager extends ExceptionTrackingManagerBase {
final class SentryTrackingManager extends ErrorTrackingManagerBase {
/// {@macro sentry_tracking_manager}
SentryTrackingManager(
super._logger, {
Expand Down
7 changes: 2 additions & 5 deletions lib/src/feature/app/model/app_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,8 @@ final class AppTheme with Diagnosticable {
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is AppTheme &&
runtimeType == other.runtimeType &&
seed == other.seed &&
mode == other.mode;
other is AppTheme && seed == other.seed && mode == other.mode;

@override
int get hashCode => mode.hashCode ^ seed.hashCode;
int get hashCode => Object.hash(seed, mode);
}
Loading

0 comments on commit adf99cc

Please sign in to comment.