Skip to content

Commit

Permalink
🎨 Package Structure and Code Improvement
Browse files Browse the repository at this point in the history
- Fixed the package structure to not expose all files under lib folder to end users.
- Created appropriate files for constants, asset paths, enumerations, etc.
- Removed raw string from codebase and moved to constants.dart.
- Moved text field validators to validators.dart.
- Utilised typedefs instead of raw function definitions in the codebase.
  • Loading branch information
aditya-css committed Oct 2, 2023
1 parent 35650cc commit 0454ba6
Show file tree
Hide file tree
Showing 31 changed files with 789 additions and 699 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Fixed [#138](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/issues/138)
AutoValidateMode only applied to Card Number text field.
- Added dart 3 support [#146](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/pull/146).
- Fixed package structure and improved code overall [#150](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/pull/150).

# [3.0.7](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/tree/3.0.7)

Expand Down
1 change: 0 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ linter:
- prefer_const_literals_to_create_immutables
# - prefer_constructors_over_static_methods # not yet tested
- prefer_contains
- prefer_equal_for_default_values
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
- prefer_final_fields
- prefer_final_locals
Expand Down
1 change: 0 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:example/app_colors.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_credit_card/credit_card_brand.dart';
import 'package:flutter_credit_card/flutter_credit_card.dart';

void main() => runApp(const MySample());
Expand Down
30 changes: 0 additions & 30 deletions lib/constants.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/extension.dart

This file was deleted.

14 changes: 8 additions & 6 deletions lib/flutter_credit_card.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
library flutter_credit_card;

export 'credit_card_form.dart';
export 'credit_card_model.dart';
export 'credit_card_widget.dart';
export 'custom_card_type_icon.dart';
export 'floating_animation/floating_config.dart';
export 'glassmorphism_config.dart';
export 'src/credit_card_form.dart';
export 'src/credit_card_widget.dart';
export 'src/floating_animation/floating_config.dart';
export 'src/models/credit_card_brand.dart';
export 'src/models/credit_card_model.dart';
export 'src/models/custom_card_type_icon.dart';
export 'src/models/glassmorphism_config.dart';
export 'src/utils/enumerations.dart' show CardType;
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import 'dart:ui' as ui;
import 'dart:ui';

import 'package:flutter/material.dart';

import 'constants.dart';
import 'floating_animation/floating_config.dart';
import 'floating_animation/floating_controller.dart';
import 'floating_animation/glare_effect_widget.dart';
import 'glassmorphism_config.dart';
import 'models/glassmorphism_config.dart';
import 'utils/constants.dart';
import 'utils/extensions.dart';

class CardBackground extends StatelessWidget {
const CardBackground({
Expand All @@ -24,9 +25,7 @@ class CardBackground extends StatelessWidget {
this.shadowConfig,
super.key,
}) : assert(
(backgroundImage == null && backgroundNetworkImage == null) ||
(backgroundImage == null && backgroundNetworkImage != null) ||
(backgroundImage != null && backgroundNetworkImage == null),
backgroundImage == null || backgroundNetworkImage == null,
'You can\'t use network image & asset image at same time as card'
' background',
);
Expand Down Expand Up @@ -54,14 +53,20 @@ class CardBackground extends StatelessWidget {
final double screenWidth = constraints.maxWidth.isInfinite
? screenSize.width
: constraints.maxWidth;
final double screenHeight = screenSize.height;
final double implicitHeight = orientation.isPortrait
? ((width ?? screenWidth) - (padding * 2)) *
AppConstants.creditCardAspectRatio
: screenSize.height / 2;
return Stack(
alignment: Alignment.center,
children: <Widget>[
Container(
margin: EdgeInsets.all(padding),
width: width ?? screenWidth,
height: height ?? implicitHeight,
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
borderRadius: AppConstants.creditCardBorderRadius,
boxShadow: shadowConfig != null && floatingController != null
? <BoxShadow>[
BoxShadow(
Expand Down Expand Up @@ -90,39 +95,26 @@ class CardBackground extends StatelessWidget {
)
: null,
),
width: width ?? screenWidth,
height: height ??
(orientation == Orientation.portrait
? (((width ?? screenWidth) - (padding * 2)) *
AppConstants.creditCardAspectRatio)
: screenHeight / 2),
child: ClipRRect(
clipBehavior: Clip.hardEdge,
borderRadius: BorderRadius.circular(8),
child: GlareEffectWidget(
border: border,
glarePosition: glarePosition,
child: glassmorphismConfig == null
? child
: BackdropFilter(
filter: ui.ImageFilter.blur(
sigmaX: glassmorphismConfig!.blurX,
sigmaY: glassmorphismConfig!.blurY,
),
child: child,
child: GlareEffectWidget(
border: border,
glarePosition: glarePosition,
child: glassmorphismConfig == null
? child
: BackdropFilter(
filter: ImageFilter.blur(
sigmaX: glassmorphismConfig!.blurX,
sigmaY: glassmorphismConfig!.blurY,
),
),
child: child,
),
),
),
if (glassmorphismConfig != null)
Padding(
padding: const EdgeInsets.all(16),
padding: EdgeInsets.all(padding),
child: _GlassmorphicBorder(
width: width ?? screenWidth,
height: height ??
(orientation == Orientation.portrait
? ((screenWidth - 32) * 0.5714)
: screenHeight / 2),
height: height ?? implicitHeight,
),
),
],
Expand All @@ -148,7 +140,7 @@ class _GlassmorphicBorder extends StatelessWidget {
size: MediaQuery.of(context).size,
child: Container(
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(10)),
borderRadius: AppConstants.creditCardBorderRadius,
),
width: width,
height: height,
Expand Down
Loading

0 comments on commit 0454ba6

Please sign in to comment.