Skip to content
Back to skills

Flutter Layer Based Clean Architecture

ASecurity

Remove the HTTP call from the widget. Define an order domain contract, implement the request and DTO mapping in infrastructure, and have a Cubit/BLoC coordinate the use case. The widget should only trigger the event and render state. ```dart // lib/domain/repositories/order_repository.dart abstract interface class OrderRepository { Future<Either<Failure, List<Order>>> fetchOrders(); } ``` ```dart // lib/infrastructure/datasources/order_remote_data_source.dart class DioOrderRemoteDataSource im...

  • 584 stars
  • 0 votes
  • 0 copies
  • 8 views
  • Added September 5, 2026
development

Security analysis

A100/100

Pro scans all 12 files and shows the line behind each finding

Scanned September 5, 2026

npx -y skills add HoangNguyen0403/agent-skills-standard --skill flutter-layer-based-clean-architecture --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Flutter Layer Based Clean Architecture?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Flutter Layer Based Clean Architecture
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hoangnguyen0403-flutter-layer-based-clean-architecture-bb67cb7d/badge)](https://www.skillsdirectory.com/skills/hoangnguyen0403-flutter-layer-based-clean-architecture-bb67cb7d)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
Remove the HTTP call from the widget. Define an order domain contract, implement the request and DTO mapping in infrastructure, and have a Cubit/BLoC coordinate the use case. The widget should only trigger the event and render state.

```dart
// lib/domain/repositories/order_repository.dart
abstract interface class OrderRepository {
  Future<Either<Failure, List<Order>>> fetchOrders();
}
```

```dart
// lib/infrastructure/datasources/order_remote_data_source.dart
class DioOrderRemoteDataSource implements OrderRemoteDataSource {
  DioOrderRemoteDataSource(this._dio);
  final Dio _dio;

  @override
  Future<List<OrderDto>> fetchOrders() async {
    final response = await _dio.get('/orders');
    return (response.data as List<dynamic>)
        .map((json) => OrderDto.fromJson(json as Map<String, dynamic>))
        .toList();
  }
}

// lib/infrastructure/repositories/order_repository_impl.dart
class OrderRepositoryImpl implements OrderRepository {
  OrderRepositoryImpl(this._remote);
  final OrderRemoteDataSource _remote;

  @override
  Future<Either<Failure, List<Order>>> fetchOrders() async {
    try {
      final dtos = await _remote.fetchOrders();
      return right(dtos.map((dto) => dto.toDomain()).toList());
    } on DioException catch (error) {
      return left(Failure.network(error.message ?? 'Unable to load orders'));
    }
  }
}
```

`OrderDto.toDomain()` maps wire-format fields to the immutable domain `Order`, so neither the generated DTO nor raw JSON crosses the infrastructure boundary.

```dart
// lib/application/orders/orders_cubit.dart
class OrdersCubit extends Cubit<OrdersState> {
  OrdersCubit(this._repository) : super(const OrdersState.initial());
  final OrderRepository _repository;

  Future<void> load() async {
    emit(const OrdersState.loading());
    final result = await _repository.fetchOrders();
    emit(result.fold(
      (failure) => OrdersState.error(failure.message),
      (orders) => OrdersState.loaded(orders),
    ));
  }
}
```

The widget becomes a presentation-only consumer:

```dart
@override
void initState() {
  super.initState();
  context.read<OrdersCubit>().load();
}

@override
Widget build(BuildContext context) => BlocBuilder<OrdersCubit, OrdersState>(
  builder: (context, state) => state.when(
    initial: () => const SizedBox.shrink(),
    loading: () => const Center(child: CircularProgressIndicator()),
    loaded: (orders) => OrdersList(orders: orders),
    error: (message) => ErrorView(message: message),
  ),
);
```

Register `OrderRepository` to `OrderRepositoryImpl` and the Cubit in `get_it`/`BlocProvider`. Presentation depends on the Cubit; the Cubit depends on the domain interface; only infrastructure depends on Dio.

Files in this skill

  • eval-1.baseline.md1.3 KB
  • eval-1.with-skill.md2.8 KB
  • eval-2.baseline.md1.4 KB
  • eval-2.with-skill.md2.6 KB
  • eval-3.baseline.md1.5 KB
  • eval-3.with-skill.md1.7 KB
  • trigger-1.md211 B
  • trigger-2.md122 B
  • trigger-3.md166 B
  • trigger-4.md179 B
  • trigger-5.md212 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.