Skip to content

Commit

Permalink
Clean up and adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Sep 29, 2023
1 parent 22c3bad commit 8b021ca
Show file tree
Hide file tree
Showing 31 changed files with 529 additions and 278 deletions.
4 changes: 0 additions & 4 deletions .fvm/fvm_config.json

This file was deleted.

3 changes: 3 additions & 0 deletions .fvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"flutter": "stable"
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,6 @@ yarn.lock
node_modules

# FVM
.fvm/flutter_sdk
.fvm/flutter_sdk
# FVM Version Cache
.fvm
17 changes: 5 additions & 12 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
{
"dart.flutterSdkPath": ".fvm/flutter_sdk",
// Remove .fvm files from search
"search.exclude": {
"**/.fvm": true
},
// Remove from file watching
"files.watcherExclude": {
"**/.fvm": true
},
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"source.fixAll": true
}
}
"source.fixAll": true,
"source.dcm.fixAll": true
},
"dart.flutterSdkPath": ".fvm/versions/stable"
}
15 changes: 10 additions & 5 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@ analyzer:
dart_code_metrics:
metrics:
cyclomatic-complexity: 20
number-of-parameters: 4
maximum-nesting-level: 5
metrics-exclude:
- test/**
rules:
- avoid-dynamic
- avoid-passing-async-when-sync-expected
- avoid-redundant-async
- avoid-unnecessary-type-assertions
- avoid-unnecessary-type-casts
- avoid-unrelated-type-assertions
- avoid-unused-parameters
- avoid-nested-conditional-expressions
- newline-before-return
- no-boolean-literal-compare
- no-empty-block
- prefer-trailing-comma
- prefer-conditional-expressions
- no-equal-then-else

anti-patterns:
- long-method
- long-parameter-list
- prefer-moving-to-variable
4 changes: 2 additions & 2 deletions demo/lib/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ MaterialStateProperty<Color?> getPropertyForTrack(ThemeData theme) {
if (states.contains(MaterialState.selected)) {
return theme.colorScheme.secondary;
}

return null;
});
}
Expand All @@ -59,7 +59,7 @@ ThemeData get darkTheme {
if (states.contains(MaterialState.hovered)) {
return Colors.white;
}

return Colors.white.withAlpha(230);
}),
),
Expand Down
181 changes: 181 additions & 0 deletions demo/lib/views/button_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:mix/mix.dart';

enum SizeVariantEnum {
small,
medium,
large,
}

enum LeadingPosition { left, center, right }

@immutable
class ButtonSizeVariant<T extends SizeVariantEnum> extends StyleVariant {
ButtonSizeVariant(T variant) : super(variant.name);
}

class ButtonSizeVariants {
static final small = ButtonSizeVariant(SizeVariantEnum.small);
static final medium = ButtonSizeVariant(SizeVariantEnum.medium);
static final large = ButtonSizeVariant(SizeVariantEnum.large);
}

StyleMix get _baseStyle => StyleMix(
rounded(4),
animation(
curve: Curves.easeIn,
duration: 100,
),
onPress(
scale(0.95),
),
mainAxisAlignment(MainAxisAlignment.center),
textStyle(
// added because of lack of style parameters (yellow lines)
decoration: TextDecoration.none,
fontWeight: FontWeight.w600,
fontFamily: $M3Text.bodySmall.fontFamily,
),
mainAxisSize(MainAxisSize.min), // For flexbox
ButtonSizeVariants.small(
paddingHorizontal(10),
paddingVertical(10),
textStyle(
fontSize: 16,
),
iconSize(24),
),
ButtonSizeVariants.medium(
paddingHorizontal(4),
paddingVertical(16),
textStyle(
fontSize: 16,
),
iconSize(24),
),
ButtonSizeVariants.large(
paddingHorizontal(4),
paddingVertical(2),
textStyle(
fontSize: 16,
),
iconSize(24),
),
);

abstract class Button extends StatelessWidget {
const Button(
this.text, {
super.key,
this.size,
this.style,
this.onPressed,
this.onLongPressed,
this.leading,
this.leadingPosition = LeadingPosition.left,
this.interPadding = 12, // ultrashotTheme.spacing.w15
});

final String text;
final ButtonSizeVariant? size;
final StyleMix? style;
final VoidCallback? onPressed;
final VoidCallback? onLongPressed;
final Widget? leading;
final LeadingPosition? leadingPosition;
final double? interPadding;

Widget get _leftContent {
if (leading == null ||
leading != null && leadingPosition != LeadingPosition.left) {
return SizedBox.fromSize(size: Size.zero);
}

return Padding(
padding: EdgeInsets.only(right: interPadding!),
child: leading,
);
}

Widget get _centerContent {
if (leading != null && leadingPosition == LeadingPosition.center) {
return leading!;
}

return StyledText(
text,
inherit: true,
style: StyleMix(),
);
}

Widget get _rightContent {
if (leading == null ||
leading != null && leadingPosition != LeadingPosition.right) {
return SizedBox.fromSize(size: Size.zero);
}

return Padding(
padding: EdgeInsets.only(left: interPadding!),
child: leading,
);
}

@override
Widget build(BuildContext context) {
final mergedStyle = _baseStyle
.selectVariant(size ?? ButtonSizeVariants.medium)
.mergeNullable(style);

return Pressable(
onPressed: onPressed,
onLongPress: onLongPressed,
child: HBox(
style: mergedStyle,
children: [
_leftContent,
_centerContent,
_rightContent,
],
),
);
}
}

StyleMix get _style => StyleMix(
textStyle(
color: const Color(0xFFFF004C),
),
backgroundColor(const Color(0x0F07E2FF)),
iconColor($MDColorScheme.onBackground),
onDisabled(
backgroundColor($MDColorScheme.background.withOpacity(0.3)),
textStyle(color: $MDColorScheme.onBackground.withOpacity(0.3)),
iconColor($MDColorScheme.onBackground.withOpacity(0.3)),
),
);

class PrimaryButton extends Button {
PrimaryButton(
String text, {
super.key,
super.size,
super.onPressed,
super.onLongPressed,
super.leading,
super.leadingPosition,
}) : super(text, style: _style);
}

class ButtonExample extends HookWidget {
const ButtonExample({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return PrimaryButton(
'Primary Button',
onPressed: () => {},
);
}
}
2 changes: 1 addition & 1 deletion demo/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
desktop_window: fb7c4f12c1129f947ac482296b6f14059d57a3c3
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
path_provider_foundation: c68054786f1b4f3343858c1e1d0caaded73f0be9
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943

PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7

Expand Down
2 changes: 1 addition & 1 deletion demo/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Loading

0 comments on commit 8b021ca

Please sign in to comment.