5. What we want
- Make the code easy to write
- Avoid errors caused by distraction
- Minimize code duplication
- Make the IDE our best friend
- Improve our productivity
11. How to use Paddinger?
dependencies:
paddinger_annotations: [latestVersionHere]
dev_dependencies:
paddinger: [latestVersionHere]
Add these dependencies to your pubspec.yaml
12. How to use Paddinger?
Create a paddings.dart file which contains your
PADDING_ definitions
@paddinger
const double PADDING_MEDIUM = 16.0;
@paddinger
const double PADDING_LARGE = 24.0;
13. How to use Paddinger?
Add material or cupertino import
Add part directive
// ignore: unused_import
import 'package:flutter/material.dart';
part 'paddings.g.dart';
14. Start the code generation
Now run
flutter pub run build_runner build --delete-conflicting-
outputs
17. Do not add it to your version control system
How to use them
Just import paddings.dart in your widgets,
it also contains all the generated classes created in
paddings.g.dart
31. Test the generated code
test(
'GIVEN a valid padding constant name, WHEN validatePaddingConstantName(), THEN it
returns normally',
() {
expect(
() => validatePaddingConstantName("PADDING_MEDIUM"), returnsNormally);
});
test(
'GIVEN a not valid padding constant name, WHEN validatePaddingConstantName(),
THEN an exception is thrown',
() {
expect(() => validatePaddingConstantName("PADDIN_MEDIUM"),
throwsA(isA<Exception>()));
});
32. Test the generated code
test(
'GIVEN a valid padding constant name, WHEN toNameForGeneration(), THEN a
valid name is generated',
() {
expect(toNameForGeneration("PADDING_MEDIUM"), "Medium");
});
test(
'GIVEN a valid padding constant name with two underscores, WHEN
toNameForGeneration(), THEN a valid name is generated',
() {
expect(toNameForGeneration("PADDING_VERY_LARGE"), "VeryLarge");
});
33. Test the generated code
test(
'GIVEN a valid paddingName and a valid constantName, WHEN generatePaddingWidgets(), THEN valid padding widgets are
generated',
() {
expect(generatePaddingWidgets("Medium", "PADDING_MEDIUM"), '''
// **************************************************************************
// START Medium
// **************************************************************************
class MediumAllPadding extends Padding {
const MediumAllPadding({Key? key, required Widget child})
: super(
key: key,
padding: const EdgeInsets.all(PADDING_MEDIUM),
child: child);
}
///Other classes here, this line is not part of the real generated code
''');
});
34. Nice helpful tips
IDE code completion will be able to:
- suggest you all the available Padding classes
- transforms TLMP into TopLeftMediumPadding