fca 0.0.11 copy "fca: ^0.0.11" to clipboard
fca: ^0.0.11 copied to clipboard

A Flutter template based on Clean Architecture, designed for scalable and maintainable apps with a structured layer system and pre-configured state management.

example/example.md

FCA Example #

This example demonstrates how to use the fca package to build a Flutter app following Clean Architecture principles.

Project Structure #

The fca package provides a structured project layout with three main layers:

  • Domain Layer: Contains business logic, entities, and use cases.
  • Data Layer: Manages data sources, repositories, and data models.
  • Presentation Layer: Handles UI, widgets, and state management.

Step-by-Step Guide #

1. Setting Up the Project #

Start by adding the fca package to your pubspec.yaml:

dependencies:
    fca: ^1.0.0

Run flutter pub get to install the package.

2. Creating a Use Case #

In the Domain layer, create a use case that defines the core business logic:

class GetUserProfile implements UseCase<User, NoParams>{
  final UserRepository repository;

  GetUserProfile(this.repository);

  @overide
  Future<User> execute(NoParmas params) {
    return repository.getUserById();
  }
}

3. Implementing the Repository #

In the Data layer, implement the repository to handle data fetching:

class UserRepositoryImpl implements UserRepository {
  final UserRemoteDataSource remoteDataSource;

  UserRepositoryImpl(this.remoteDataSource);

  @override
  Future<User> getUserById(String userId) {
    return remoteDataSource.fetchUser(userId);
  }
}

4. Managing State with Bloc #

In the Presentation layer, use Bloc to manage the state:

class UserBloc extends Bloc<UserEvent, UserState> {
  final GetUserProfile getUserProfile;

  UserBloc(this.getUserProfile) : super(UserInitial());

  @override
  Stream<UserState> mapEventToState(UserEvent event) async* {
    if (event is GetUserEvent) {
      yield UserLoading();
      final user = await getUserProfile.execute(event.userId);
      yield UserLoaded(user);
    }
  }
}

5. Building the UI #

Finally, create the UI to display the user profile:

class UserProfilePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (_) => UserBloc(GetUserProfile(UserRepositoryImpl())),
      child: Scaffold(
        appBar: AppBar(title: Text('User Profile')),
        body: BlocBuilder<UserBloc, UserState>(
          builder: (context, state) {
            if (state is UserLoading) {
              return CircularProgressIndicator();
            } else if (state is UserLoaded) {
              return Text('Hello, ${state.user.name}');
            } else {
              return Text('Error loading user');
            }
          },
        ),
      ),
    );
  }
}

6. Running the App #

With everything set up, run your Flutter app, and navigate to the UserProfilePage to see the Clean Architecture in action.

Full Example Code #

For a complete implementation, refer to the full source code in the example directory of this package.

2
likes
140
points
40
downloads

Publisher

verified publisherforezyy.id

Weekly Downloads

A Flutter template based on Clean Architecture, designed for scalable and maintainable apps with a structured layer system and pre-configured state management.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_bloc, fpdart, get_it, google_fonts, http, internet_connection_checker_plus

More

Packages that depend on fca