Skip to content

A design solution to deal with decoupling features from entry-points component like app-bar, sidebar and bottom-navigation-bar .

License

Notifications You must be signed in to change notification settings

ebrahimmansur/contribution-design-pattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

contribution-design-pattern

A design solution to deal with decoupling features from entry-points component like app-bar, sidebar and bottom-navigation-bar.

Entry-point

  • bottom navigation bar

Features owned by a team

  • profile - team
  • home - team

The Contribution components

IContribution

  • The base component that encapsulate the Contribution information.
abstract class IContribution {
  String get contributionId;
  bool get isEnabled;
}

IBottomNavigationBarContribution

  • A component that extends IContribution and encapsulate specific contribution
abstract class IBottomNavigationBarContribution implements IContribution {
  BottomNavigationBarContributionData get state;
  Widget view(BuildContext context);
}

BottomNavigationBarContributionData

  • The Component that encapsulate the state of the contribution.
class BottomNavigationBarContributionData {
  final String label;
  final IconData icon;
  const BottomNavigationBarContributionData({
    required this.label,
    required this.icon,
  });
}

ContributionRegistry

  • The component that encapsulate the responsibility of registering contributions.
class ContributionRegistry {
  List<IContribution> get contributions => [
        //add contributions [we can use DI to avoid cycle-dependency reference]
        ProfileBottomNavigationBarContribution(),
        HomeBottomNavigationBarContribution()
      ];
}

ContributionManager

  • The component that encapsulate the responsibility of providing the right contributions to the consumers.
class ContributionManager<T extends IContribution> {
  final ContributionRegistry _registry = ContributionRegistry();
  List<T> get contributions {
    final list = _registry.contributions.whereType<T>();

    return list.where((element) => element.isEnabled).toList();
  }
}

Profile Team Contribution

class ProfileBottomNavigationBarContribution
    implements IBottomNavigationBarContribution {
  @override
  String get contributionId => 'profile-bottom-navigationBar-contribution';

  @override
  bool get isEnabled => true;

  @override
  Widget view(BuildContext context) {
    return const Text("Profile-Screen");
  }

  @override
  BottomNavigationBarContributionData get state =>
      const BottomNavigationBarContributionData(
        label: "Profile",
        icon: Icons.person,
      );
}

Home Team Contribution

class HomeBottomNavigationBarContribution
    implements IBottomNavigationBarContribution {
  @override
  String get contributionId => 'Home-BottomNavigationBar-Contribution';

  @override
  bool get isEnabled => true;

  @override
  Widget view(BuildContext context) {
    return const Text("Home-Screen");
  }

  @override
  BottomNavigationBarContributionData get state =>
      const BottomNavigationBarContributionData(
        icon: Icons.home,
        label: "Home",
      );
}

About

A design solution to deal with decoupling features from entry-points component like app-bar, sidebar and bottom-navigation-bar .

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published