TF-1487 Apply linter rule

This commit is contained in:
dab246
2023-02-24 12:12:54 +07:00
committed by Dat Vu
parent 117a8a8fc6
commit 2b71aba278
155 changed files with 798 additions and 1039 deletions
+3 -16
View File
@@ -10,20 +10,7 @@
include: package:flutter_lints/flutter.yaml
linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at
# https://dart-lang.github.io/linter/lints/index.html.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
constant_identifier_names: false
non_constant_identifier_names: false
unnecessary_string_escapes: false
-3
View File
@@ -73,7 +73,6 @@ export 'presentation/views/bottom_popup/confirmation_dialog_action_sheet_builder
export 'presentation/views/modal_sheets/edit_text_modal_sheet_builder.dart';
export 'presentation/views/search/search_bar_view.dart';
export 'presentation/views/popup_menu/popup_menu_item_widget.dart';
export 'presentation/views/tab_bar/custom_tab_indicator.dart';
export 'presentation/views/quick_search/quick_search_input_form.dart';
export 'presentation/views/toast/toast_position.dart';
export 'presentation/views/toast/tmail_toast.dart';
@@ -95,8 +94,6 @@ export 'data/network/dio_client.dart';
export 'data/network/download/download_client.dart';
export 'data/network/download/download_manager.dart';
export 'data/network/download/downloaded_response.dart';
export 'data/network/download/download_client.dart';
export 'domain/exceptions/web_session_exception.dart';
// State
export 'presentation/state/success.dart';
@@ -1,5 +1,3 @@
import 'dart:ui' show Color;
import 'package:flutter/material.dart';
extension AppColor on Color {
@@ -197,3 +195,12 @@ extension AppColor on Color {
.toUpperCase()}';
}
extension ColorNullableExtension on Color? {
ColorFilter? asFilter({BlendMode? blendMode}) {
if (this == null) {
return null;
} else {
return ColorFilter.mode(this!, blendMode ?? BlendMode.srcIn);
}
}
}
@@ -11,7 +11,7 @@ extension URLExtension on String {
} else if (startsWith(prefixUrlHttp)) {
return kReleaseMode ? replaceAll(prefixUrlHttp, prefixUrlHttps) : this;
} else {
return '$prefixUrlHttps${this}';
return '$prefixUrlHttps$this';
}
}
return '';
+3 -2
View File
@@ -1,7 +1,8 @@
import 'package:core/core.dart';
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:meta/meta.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
@immutable
abstract class AppState with EquatableMixin {
+1 -1
View File
@@ -171,7 +171,7 @@ class AppToast {
width: 24,
height: 24,
fit: BoxFit.fill,
color: iconColor),
colorFilter: iconColor.asFilter()),
if (icon != null)
const SizedBox(width: 10.0),
Expanded(child: Text(
+2 -2
View File
@@ -21,8 +21,8 @@ class ThemeUtils {
static TextTheme get _textTheme {
return const TextTheme(
bodyText1: TextStyle(color: AppColor.baseTextColor),
bodyText2: TextStyle(color: AppColor.baseTextColor),
bodyMedium: TextStyle(color: AppColor.baseTextColor),
bodySmall: TextStyle(color: AppColor.baseTextColor),
);
}
@@ -43,6 +43,7 @@ class BackgroundWidgetBuilder extends StatelessWidget {
return Container(
color: Colors.transparent,
padding: const EdgeInsets.symmetric(horizontal: 12),
height: MediaQuery.of(context).size.height,
child: Column(
mainAxisAlignment: responsiveUtils.isLandscapeMobile(context)
? MainAxisAlignment.start
@@ -83,7 +84,6 @@ class BackgroundWidgetBuilder extends StatelessWidget {
)
],
),
height: MediaQuery.of(context).size.height,
);
}
}
@@ -161,7 +161,7 @@ class ButtonBuilder {
width: _size ?? 24,
height: _size ?? 24,
fit: BoxFit.fill,
color: _iconColor));
colorFilter: _iconColor.asFilter()));
Widget _buildText() {
return Text(
@@ -6,7 +6,7 @@ import 'package:flutter_svg/flutter_svg.dart';
typedef IconWebCallback = void Function();
typedef IconWebHasPositionCallback = void Function(RelativeRect);
typedef OnTapIconButtonCallbackAction = void Function();
typedef OnTapDownIconButtonCallbackAction = void Function(TapDownDetails TapDetails);
typedef OnTapDownIconButtonCallbackAction = void Function(TapDownDetails tapDetails);
Widget buildIconWeb({
required Widget icon,
@@ -51,7 +51,7 @@ Widget buildSVGIconButton({
width: iconSize,
height: iconSize,
fit: BoxFit.fill,
color: iconColor,
colorFilter: iconColor.asFilter(),
),
);
@@ -107,15 +107,20 @@ Widget buildTextCircleButton(String text, {
shape: const CircleBorder(),
color: Colors.transparent,
child: TextButton(
child: Text(
text,
style: textStyle ?? const TextStyle(fontWeight: FontWeight.normal, fontSize: 15, color: AppColor.lineItemListColor)),
style: ButtonStyle(
overlayColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) => AppColor.colorFocusButton),
shape: MaterialStateProperty.all(const CircleBorder()),
padding: MaterialStateProperty.resolveWith<EdgeInsets>((Set<MaterialState> states) => EdgeInsets.zero),
elevation: MaterialStateProperty.resolveWith<double>((Set<MaterialState> states) => 0)),
onPressed: () => onTap?.call()
onPressed: () => onTap?.call(),
child: Text(
text,
style: textStyle ?? const TextStyle(
fontWeight: FontWeight.normal,
fontSize: 15,
color: AppColor.lineItemListColor
)
)
)
);
}
@@ -166,7 +166,7 @@ class ConfirmDialogBuilder {
height: _heightDialog,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: const BorderRadius.all(Radius.circular(16))),
borderRadius: BorderRadius.all(Radius.circular(16))),
margin: _margin,
child: Wrap(children: [
if (_onCloseButtonAction != null)
@@ -57,7 +57,7 @@ class ScrollingFloatingButtonAnimated extends StatefulWidget {
: super(key: key);
@override
_ScrollingFloatingButtonAnimatedState createState() =>
State<ScrollingFloatingButtonAnimated> createState() =>
_ScrollingFloatingButtonAnimatedState();
}
@@ -93,10 +93,10 @@ class _ScrollingFloatingButtonAnimatedState
/// Function to add listener for scroll
void _handleScroll() {
ScrollController _scrollController = widget.scrollController!;
_scrollController.addListener(() {
if (_scrollController.position.pixels > widget.limitIndicator! &&
_scrollController.position.userScrollDirection ==
ScrollController scrollController = widget.scrollController!;
scrollController.addListener(() {
if (scrollController.position.pixels > widget.limitIndicator! &&
scrollController.position.userScrollDirection ==
ScrollDirection.reverse) {
if (widget.animateIcon!) _animationController.forward();
if (mounted) {
@@ -104,8 +104,8 @@ class _ScrollingFloatingButtonAnimatedState
_onTop = false;
});
}
} else if (_scrollController.position.pixels <= widget.limitIndicator! &&
_scrollController.position.userScrollDirection ==
} else if (scrollController.position.pixels <= widget.limitIndicator! &&
scrollController.position.userScrollDirection ==
ScrollDirection.forward) {
if (widget.animateIcon!) _animationController.reverse();
if (mounted) {
@@ -145,14 +145,14 @@ class _ScrollingFloatingButtonAnimatedState
Container(
padding: EdgeInsets.only(left: 16, right: _onTop ? 10 : 16),
child: AnimatedBuilder(
child: widget.icon!,
animation: _animationController,
builder: (BuildContext context, Widget? _widget) {
builder: (BuildContext context, Widget? widget) {
return Transform.rotate(
angle: (_animationController.value * 3 * math.pi) / 180,
child: _widget!,
child: widget!,
);
}),
},
child: widget.icon!),
),
...(_onTop
? [
@@ -1,4 +1,5 @@
import 'package:core/core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
@@ -28,7 +29,13 @@ class PopupMenuItemWidget extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
child: SizedBox(
child: Row(children: [
SvgPicture.asset(icon, width: 20, height: 20, fit: BoxFit.fill, color: iconColor),
SvgPicture.asset(
icon,
width: 20,
height: 20,
fit: BoxFit.fill,
colorFilter: iconColor.asFilter()
),
const SizedBox(width: 12),
Expanded(child: Text(name,
style: const TextStyle(fontSize: 15, color: Colors.black, fontWeight: FontWeight.w500))),
@@ -156,7 +156,7 @@ class QuickSearchInputForm<T, R> extends FormField<String> {
});
@override
_TypeAheadFormFieldState<T, R> createState() => _TypeAheadFormFieldState<T, R>();
FormFieldState<String> createState() => _TypeAheadFormFieldState<T, R>();
}
class _TypeAheadFormFieldState<T, R> extends FormFieldState<String> {
@@ -567,7 +567,7 @@ class TypeAheadFieldQuickSearch<T, R> extends StatefulWidget {
super(key: key);
@override
_TypeAheadFieldQuickSearchState<T, R> createState() => _TypeAheadFieldQuickSearchState<T, R>();
State<TypeAheadFieldQuickSearch<T, R>> createState() => _TypeAheadFieldQuickSearchState<T, R>();
}
class _TypeAheadFieldQuickSearchState<T, R> extends State<TypeAheadFieldQuickSearch<T, R>>
@@ -678,13 +678,9 @@ class _TypeAheadFieldQuickSearchState<T, R> extends State<TypeAheadFieldQuickSea
void didChangeDependencies() {
super.didChangeDependencies();
ScrollableState? scrollableState = Scrollable.of(context);
if (scrollableState != null) {
// The TypeAheadFieldQuickSearch is inside a scrollable widget
_scrollPosition = scrollableState.position;
_scrollPosition!.removeListener(_scrollResizeListener);
_scrollPosition!.isScrollingNotifier.addListener(_scrollResizeListener);
}
_scrollPosition = scrollableState.position;
_scrollPosition!.removeListener(_scrollResizeListener);
_scrollPosition!.isScrollingNotifier.addListener(_scrollResizeListener);
}
void _scrollResizeListener() {
@@ -1176,7 +1172,6 @@ class _SuggestionsListState<T, R> extends State<_SuggestionsList<T, R>>
return Padding(
padding: const EdgeInsets.only(right: 8, bottom: kIsWeb ? 8 : 0),
child: InkWell(
child: widget.actionButtonBuilder!(context, action),
borderRadius: const BorderRadius.all(Radius.circular(10)),
onTap: () {
if (widget.buttonActionCallback != null) {
@@ -1184,6 +1179,7 @@ class _SuggestionsListState<T, R> extends State<_SuggestionsList<T, R>>
invalidateSuggestions();
}
},
child: widget.actionButtonBuilder!(context, action),
),
);
} else {
@@ -1257,7 +1253,6 @@ class _SuggestionsListState<T, R> extends State<_SuggestionsList<T, R>>
return Padding(
padding: const EdgeInsets.only(right: 8, bottom: kIsWeb ? 8 : 0),
child: InkWell(
child: widget.actionButtonBuilder!(context, action),
borderRadius: const BorderRadius.all(Radius.circular(10)),
onTap: () {
if (widget.buttonActionCallback != null) {
@@ -1265,6 +1260,7 @@ class _SuggestionsListState<T, R> extends State<_SuggestionsList<T, R>>
invalidateSuggestions();
}
},
child: widget.actionButtonBuilder!(context, action),
),
);
} else {
@@ -1680,7 +1676,7 @@ class _SuggestionsBox {
if (isOpened) return;
assert(_overlayEntry != null);
resize();
Overlay.of(context)!.insert(_overlayEntry!);
Overlay.of(context).insert(_overlayEntry!);
isOpened = true;
}
@@ -1726,7 +1722,7 @@ class _SuggestionsBox {
await Future<void>.delayed(const Duration(milliseconds: 170));
timer += 170;
if (widgetMounted &&
if (widgetMounted && context.mounted &&
(MediaQuery.of(context).viewInsets != initial ||
_findRootMediaQuery() != initialRootMediaQuery)) {
return true;
@@ -1,61 +0,0 @@
import 'package:flutter/widgets.dart';
enum CustomIndicatorSize {
tiny,
normal,
full,
}
class CustomIndicator extends Decoration {
final double indicatorHeight;
final Color indicatorColor;
final CustomIndicatorSize indicatorSize;
const CustomIndicator({
required this.indicatorHeight,
required this.indicatorColor,
required this.indicatorSize
});
@override
_CustomPainter createBoxPainter([VoidCallback? onChanged]) {
return _CustomPainter(this, onChanged);
}
}
class _CustomPainter extends BoxPainter {
final CustomIndicator decoration;
_CustomPainter(this.decoration, VoidCallback? onChanged) : super(onChanged);
@override
void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
assert(configuration.size != null);
Rect? rect;
if (decoration.indicatorSize == CustomIndicatorSize.full) {
rect = Offset(offset.dx,
(configuration.size!.height - decoration.indicatorHeight)) &
Size(configuration.size!.width, decoration.indicatorHeight);
} else if (decoration.indicatorSize == CustomIndicatorSize.normal) {
rect = Offset(offset.dx + 6,
(configuration.size!.height - decoration.indicatorHeight)) &
Size(configuration.size!.width - 12, decoration.indicatorHeight);
} else if (decoration.indicatorSize == CustomIndicatorSize.tiny) {
rect = Offset(offset.dx + configuration.size!.width / 2 - 8,
(configuration.size!.height - decoration.indicatorHeight)) &
Size(16, decoration.indicatorHeight);
}
if (rect != null) {
final Paint paint = Paint();
paint.color = decoration.indicatorColor;
paint.style = PaintingStyle.fill;
canvas.drawRRect(
RRect.fromRectAndCorners(rect,
topRight: const Radius.circular(8),
topLeft: const Radius.circular(8)),
paint);
}
}
}
+4 -4
View File
@@ -3,17 +3,17 @@ import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
_Dispatcher logHistory = _Dispatcher("");
final logHistory = _Dispatcher("");
void log(String? value) {
String v = value ?? "";
logHistory.value = v + "\n" + logHistory.value;
if (kReleaseMode == false) {
logHistory.value = "$v\n${logHistory.value}";
if (kDebugMode) {
print(v);
}
}
void logError(String? value) => log("[ERROR] " + (value ?? ""));
void logError(String? value) => log("[ERROR] ${value ?? ""}");
// Take from: https://flutter.dev/docs/testing/errors
void initLogger(VoidCallback runApp) {
+1 -1
View File
@@ -33,4 +33,4 @@ class _Benchmark {
}
}
final _Benchmark bench = _Benchmark();
final bench = _Benchmark();
+6 -5
View File
@@ -1,11 +1,12 @@
import 'package:flutter/foundation.dart' as Foundation;
import 'package:flutter/foundation.dart';
abstract class BuildUtils {
static const bool isDebugMode = Foundation.kDebugMode;
static const bool isDebugMode = kDebugMode;
static const bool isReleaseMode = Foundation.kReleaseMode;
static const bool isReleaseMode = kReleaseMode;
static const bool isWeb = Foundation.kIsWeb;
static const bool isWeb = kIsWeb;
static const bool isProfileMode = Foundation.kProfileMode;
static const bool isProfileMode = kProfileMode;
}
+3 -3
View File
@@ -34,8 +34,8 @@ class FpsManager {
final List<FpsCallback> _fpsCallbacks = [];
/// Temporarily save 120 frames
static const int _queue_capacity = 120;
final ListQueue framesQueue = ListQueue<FrameTiming>(_queue_capacity);
static const int queueCapacity = 120;
final ListQueue framesQueue = ListQueue<FrameTiming>(queueCapacity);
void addFpsCallback(FpsCallback callback) {
_fpsCallbacks.add(callback);
@@ -69,7 +69,7 @@ class FpsManager {
for (FrameTiming timing in timings) {
framesQueue.addFirst(timing);
}
while (framesQueue.length > _queue_capacity) {
while (framesQueue.length > queueCapacity) {
framesQueue.removeLast();
}