Skip to content

Commit

Permalink
docs: add explanations to constants
Browse files Browse the repository at this point in the history
  • Loading branch information
BBarisKilic committed Mar 11, 2024
1 parent 3384118 commit 979370f
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 68 deletions.
2 changes: 1 addition & 1 deletion lib/src/app/presentation/cubits/app_cubit/app_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class AppCubit extends Cubit<AppState> {
emit(state.copyWith(themeMode: themeMode));
}

void updateMainColor({required AppColor mainColor}) {
void updateMainColor({required AppMainColor mainColor}) {
emit(state.copyWith(mainColor: mainColor));
}
}
4 changes: 2 additions & 2 deletions lib/src/app/presentation/cubits/app_cubit/app_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ final class AppState extends Equatable {
});

final ThemeMode themeMode;
final AppColor mainColor;
final AppMainColor mainColor;

AppState copyWith({
ThemeMode? themeMode,
AppColor? mainColor,
AppMainColor? mainColor,
}) {
return AppState(
themeMode: themeMode ?? this.themeMode,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/app/presentation/widgets/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class App extends StatelessWidget {
create: (_) => AppCubit(
const AppState(
themeMode: ThemeMode.dark,
mainColor: AppColor.indigo,
mainColor: AppMainColor.indigo,
),
),
child: const _AppView(),
Expand Down
4 changes: 4 additions & 0 deletions lib/src/core/constants/app_animation_duration.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2022 BBK Development. All rights reserved.
// Use of this source code is governed by a GPL-style license that can be found
// in the LICENSE file.

/// A class that provides constant animation duration values to use app-wide.
abstract final class AppAnimationDuration {
/// [short] duration equals to `400 milliseconds`.
Expand Down
4 changes: 4 additions & 0 deletions lib/src/core/constants/app_border_radius.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2022 BBK Development. All rights reserved.
// Use of this source code is governed by a GPL-style license that can be found
// in the LICENSE file.

import 'package:flutter/material.dart';

/// A class that provides constant border radius values to use app-wide.
Expand Down
6 changes: 6 additions & 0 deletions lib/src/core/constants/app_button_size.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Copyright 2023 BBK Development. All rights reserved.
// Use of this source code is governed by a GPL-style license that can be found
// in the LICENSE file.

import 'package:flutter/material.dart';

/// A class that provides constant button size values to use app-wide.
abstract final class AppButtonSize {
/// [small] size equals to `48.0`.
static const small = kMinInteractiveDimension;
}
45 changes: 0 additions & 45 deletions lib/src/core/constants/app_color.dart

This file was deleted.

20 changes: 20 additions & 0 deletions lib/src/core/constants/app_icon_size.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
// Copyright 2022 BBK Development. All rights reserved.
// Use of this source code is governed by a GPL-style license that can be found
// in the LICENSE file.

/// A class that provides constant icon size values to use app-wide.
abstract final class AppIconSize {
/// [xxSmall] size equals to `16.0`.
static const xxSmall = 16.0;

/// [xSmall] size equals to `20.0`.
static const xSmall = 20.0;

/// [small] size equals to `24.0`.
static const small = 24.0;

/// [medium] size equals to `32.0`.
static const medium = 32.0;

/// [large] size equals to `48.0`.
static const large = 48.0;

/// [xLarge] size equals to `64.0`.
static const xLarge = 64.0;

/// [xxLarge] size equals to `96.0`.
static const xxLarge = 96.0;

/// [xxxLarge] size equals to `128.0`.
static const xxxLarge = 128.0;
}
70 changes: 70 additions & 0 deletions lib/src/core/constants/app_main_color.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import 'package:flutter/material.dart';

/// An enum that provides constant main color values to use app-wide.
enum AppMainColor {
/// [red] color value equals to `Colors.red`.
red,

/// [pink] color value equals to `Colors.pink`.
pink,

/// [purple] color value equals to `Colors.purple`.
purple,

/// [indigo] color value equals to `Colors.indigo`.
indigo,

/// [blue] color value equals to `Colors.blue`.
blue,

/// [cyan] color value equals to `Colors.cyan`.
cyan,

/// [teal] color value equals to `Colors.teal`.
teal,

/// [green] color value equals to `Colors.green`.
green,

/// [lime] color value equals to `Colors.lime`.
lime,

/// [yellow] color value equals to `Colors.yellow`.
yellow,

/// [orange] color value equals to `Colors.orange`.
orange,

/// [brown] color value equals to `Colors.brown`.
brown;

/// Returns [Color] based on the enum value.
Color get value {
switch (this) {
case red:
return Colors.red;
case pink:
return Colors.pink;
case purple:
return Colors.purple;
case indigo:
return Colors.indigo;
case blue:
return Colors.blue;
case cyan:
return Colors.cyan;
case teal:
return Colors.teal;
case green:
return Colors.green;
case lime:
return Colors.lime;
case yellow:
return Colors.yellow;
case orange:
return Colors.orange;
case brown:
return Colors.brown;
}
}
}
6 changes: 5 additions & 1 deletion lib/src/core/constants/app_padding.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2021 BBK Development. All rights reserved.
// Use of this source code is governed by a GPL-style license that can be found
// in the LICENSE file.

import 'package:flutter/widgets.dart';

/// A class that provides constant padding values to use app-wide.
Expand Down Expand Up @@ -34,7 +38,7 @@ abstract final class AppPadding {
vertical: vertical ?? 0.0,
);

/// Returns [EdgeInsets] in which the horizotal insets are `20.0` and the
/// Returns [EdgeInsets] in which the horizontal insets are `20.0` and the
/// vertical insets are `12.0`.
static EdgeInsets get general =>
const EdgeInsets.symmetric(horizontal: large, vertical: medium);
Expand Down
6 changes: 5 additions & 1 deletion lib/src/core/constants/constants.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright 2021 BBK Development. All rights reserved.
// Use of this source code is governed by a GPL-style license that can be found
// in the LICENSE file.

export 'app_animation_duration.dart';
export 'app_border_radius.dart';
export 'app_button_size.dart';
export 'app_color.dart';
export 'app_icon_size.dart';
export 'app_main_color.dart';
export 'app_padding.dart';
26 changes: 13 additions & 13 deletions lib/src/core/extensions/app_color_ext.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import 'package:flutter/material.dart';
import 'package:vmerge/src/core/core.dart';

extension AppColorExt on AppColor {
extension AppColorExt on AppMainColor {
String name(BuildContext context) {
return switch (this) {
AppColor.red => context.l10n.red,
AppColor.pink => context.l10n.pink,
AppColor.purple => context.l10n.purple,
AppColor.indigo => context.l10n.indigo,
AppColor.blue => context.l10n.blue,
AppColor.cyan => context.l10n.cyan,
AppColor.teal => context.l10n.teal,
AppColor.green => context.l10n.green,
AppColor.lime => context.l10n.lime,
AppColor.yellow => context.l10n.yellow,
AppColor.orange => context.l10n.orange,
AppColor.brown => context.l10n.brown,
AppMainColor.red => context.l10n.red,
AppMainColor.pink => context.l10n.pink,
AppMainColor.purple => context.l10n.purple,
AppMainColor.indigo => context.l10n.indigo,
AppMainColor.blue => context.l10n.blue,
AppMainColor.cyan => context.l10n.cyan,
AppMainColor.teal => context.l10n.teal,
AppMainColor.green => context.l10n.green,
AppMainColor.lime => context.l10n.lime,
AppMainColor.yellow => context.l10n.yellow,
AppMainColor.orange => context.l10n.orange,
AppMainColor.brown => context.l10n.brown,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class MoreCubit extends Cubit<MoreState> {
emit(state.copyWith(isDarkModeEnabled: isDarkModeEnabled));
}

void updateMainColor({required AppColor mainColor}) {
void updateMainColor({required AppMainColor mainColor}) {
emit(state.copyWith(mainColor: mainColor));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ final class MoreState extends Equatable {
});

final bool isDarkModeEnabled;
final AppColor mainColor;
final AppMainColor mainColor;

MoreState copyWith({
bool? isDarkModeEnabled,
AppColor? mainColor,
AppMainColor? mainColor,
}) {
return MoreState(
isDarkModeEnabled: isDarkModeEnabled ?? this.isDarkModeEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class _MainColorSelector extends StatelessWidget {
),
CustomDropdownButton(
items: [
for (final color in AppColor.values)
for (final color in AppMainColor.values)
DropdownMenuItem(
value: color,
child: Center(
Expand Down

0 comments on commit 979370f

Please sign in to comment.