Skip to content

Commit

Permalink
Rename View to CleanView to avoid conflict with flutter
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadyBoukhary committed Jul 3, 2024
1 parent 7588258 commit 95c287f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 41 deletions.
17 changes: 8 additions & 9 deletions example/lib/src/app/pages/home/home_view.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import './home_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_clean_architecture/flutter_clean_architecture.dart'
as clean;
import 'package:flutter_clean_architecture/flutter_clean_architecture.dart';
import '../../../data/repositories/data_users_repository.dart';

class HomePage extends clean.View {
class HomePage extends CleanView {
const HomePage({Key? key, this.title = ""}) : super(key: key);

final String title;
Expand All @@ -15,7 +14,7 @@ class HomePage extends clean.View {
HomePageState();
}

class HomePageState extends clean.ViewState<HomePage, HomeController> {
class HomePageState extends CleanViewState<HomePage, HomeController> {
HomePageState() : super(HomeController(DataUsersRepository()));

@override
Expand All @@ -31,7 +30,7 @@ class HomePageState extends clean.ViewState<HomePage, HomeController> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
clean.ControlledWidgetBuilder<HomeController>(
ControlledWidgetBuilder<HomeController>(
builder: (context, controller) {
return Text(
'Button pressed ${controller.counter} times.',
Expand All @@ -41,15 +40,15 @@ class HomePageState extends clean.ViewState<HomePage, HomeController> {
const Text(
'The current user is',
),
clean.ControlledWidgetBuilder<HomeController>(
ControlledWidgetBuilder<HomeController>(
builder: (context, controller) {
return Text(
controller.user == null ? '' : '${controller.user}',
style: Theme.of(context).textTheme.headlineMedium,
);
},
),
clean.ControlledWidgetBuilder<HomeController>(
ControlledWidgetBuilder<HomeController>(
builder: (context, controller) {
return ElevatedButton(
onPressed: controller.getUser,
Expand All @@ -60,7 +59,7 @@ class HomePageState extends clean.ViewState<HomePage, HomeController> {
);
},
),
clean.ControlledWidgetBuilder<HomeController>(
ControlledWidgetBuilder<HomeController>(
builder: (context, controller) {
return ElevatedButton(
onPressed: controller.getUserwithError,
Expand All @@ -75,7 +74,7 @@ class HomePageState extends clean.ViewState<HomePage, HomeController> {
),
),
),
floatingActionButton: clean.ControlledWidgetBuilder<HomeController>(
floatingActionButton: ControlledWidgetBuilder<HomeController>(
builder: (context, controller) {
return FloatingActionButton(
onPressed: () => controller.buttonPressed(),
Expand Down
4 changes: 2 additions & 2 deletions example/test/src/app/widgets/button_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void main() {
});
}

class TestPage extends clean.View {
class TestPage extends clean.CleanView {
const TestPage({
Key? key,
}) : super(key: key);
Expand All @@ -35,7 +35,7 @@ class TestPage extends clean.View {
TestPageState createState() => TestPageState();
}

class TestPageState extends clean.ViewState<TestPage, HomeController> {
class TestPageState extends clean.CleanViewState<TestPage, HomeController> {
TestPageState() : super(HomeController(DataUsersRepository()));

@override
Expand Down
32 changes: 16 additions & 16 deletions lib/src/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import 'package:meta/meta.dart';
import 'package:provider/provider.dart';

/// A Clean Architecture [Controller]. Should be aggregated within a `ViewState` or
/// a `View`. However, it is preferable to be contained inside the `View` for readability
/// a `CleanView`. However, it is preferable to be contained inside the `CleanView` for readability
/// and maintainability.
///
/// The [Controller] handles the events triggered by the `View`. For example, it handles
/// The [Controller] handles the events triggered by the `CleanView`. For example, it handles
/// the click events of buttons, lifecycle, data-sourcing, etc...
///
/// The [Controller] is also route-aware. However, in order to use it,
Expand Down Expand Up @@ -57,7 +57,7 @@ import 'package:provider/provider.dart';
/// return MaterialApp(
/// title: 'Flutter Demo',
/// home: Scaffold(
/// key: globalKey, // using the built-in global key of the `View` for the scaffold or any other
/// key: globalKey, // using the built-in global key of the `CleanView` for the scaffold or any other
/// // widget provides the controller with a way to access them via getContext(), getState(), getStateKey()
/// body: Column(
/// children: <Widget>[
Expand Down Expand Up @@ -109,15 +109,15 @@ abstract class Controller
}
}

/// _refreshes the [ControlledWidgets] and the [StatefulWidgets] that depends on [FlutterCleanArchitecture.getController] of the [View] associated with the [Controller] if it is still mounted.
/// _refreshes the [ControlledWidgets] and the [StatefulWidgets] that depends on [FlutterCleanArchitecture.getController] of the [CleanView] associated with the [Controller] if it is still mounted.
@protected
void refreshUI() {
if (_isMounted) {
notifyListeners();
}
}

/// Unmounts the [Controller] from the `View`. Called by the `View` automatically.
/// Unmounts the [Controller] from the `CleanView`. Called by the `CleanView` automatically.
/// Any cleaning, disposing should go in here.
///
/// To perform correct actions that depends on latest [BuildContext] used on view before dispose, you must
Expand Down Expand Up @@ -147,7 +147,7 @@ abstract class Controller
super.dispose();
}

/// Retrieves the [State<StatefulWidget>] associated with the [View]
/// Retrieves the [State<StatefulWidget>] associated with the [CleanView]
@protected
State<StatefulWidget> getState() {
assert(_globalKey.currentState != null,
Expand All @@ -160,19 +160,19 @@ abstract class Controller
return _globalKey.currentState!;
}

/// Retrieves the [GlobalKey<State<StatefulWidget>>] associated with the [View]
/// Retrieves the [GlobalKey<State<StatefulWidget>>] associated with the [CleanView]
@protected
GlobalKey<State<StatefulWidget>> getStateKey() {
return _globalKey;
}

/// Initializes optional [Controller] variables that can be used for _refreshing and error displaying.
/// This method is called automatically by the mounted `View`. Do not call.
/// This method is called automatically by the mounted `CleanView`. Do not call.
void initController(GlobalKey<State<StatefulWidget>> key) {
_globalKey = key;
}

/// Retrieves the [BuildContext] associated with the `View`. Will throw an error if initController() was not called prior.
/// Retrieves the [BuildContext] associated with the `CleanView`. Will throw an error if initController() was not called prior.
@protected
BuildContext getContext() {
assert(_globalKey.currentContext != null,
Expand Down Expand Up @@ -320,10 +320,10 @@ abstract class Controller
@visibleForOverriding
void onReassembled() {}
/// Called before [View.didChangeDependencies] is called
/// Called before [CleanView.didChangeDependencies] is called
///
/// Should be used when need to perform some action on [View.didChangeDependencies] life cycle.
/// [View.initViewState] should be called before the actions you need to perform. Like [didChangeDependencies], you can safely perform
/// Should be used when need to perform some action on [CleanView.didChangeDependencies] life cycle.
/// [CleanView.initViewState] should be called before the actions you need to perform. Like [didChangeDependencies], you can safely perform
/// actions that depends on [BuildContext] here.
///
/// ```dart
Expand All @@ -335,9 +335,9 @@ abstract class Controller
@visibleForOverriding
void onDidChangeDependencies() {}
/// Called before [View.initState] is called
/// Called before [CleanView.initState] is called
///
/// Should be used when need to perform some action on [View.initState] life cycle.
/// Should be used when need to perform some action on [CleanView.initState] life cycle.
///
/// ```dart
/// class MyController extends Controller {
Expand All @@ -355,9 +355,9 @@ typedef ControlledBuilder<Con extends Controller> = Widget Function(
/// This is a representation of a widget that is controlled by a [Controller] and needs to be re-rendered when
/// [Controller.refreshUI] is triggered.
///
/// This was created to optimize the render cycle from a [ViewState]'s widget tree.
/// This was created to optimize the render cycle from a [CleanViewState]'s widget tree.
///
/// When [Controller.refreshUI] is called, only the ControlledWidgets inside [ViewState.view] will be re-rendered.
/// When [Controller.refreshUI] is called, only the ControlledWidgets inside [CleanViewState.view] will be re-rendered.
///
/// Example:
///
Expand Down
28 changes: 14 additions & 14 deletions lib/src/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ typedef ViewBuilder = Widget Function(BuildContext context);
/// ```
///
/// You can optionally set globally new default values for breakpoints. To do so, just check on [FlutterCleanArchitecture.setDefaultViewBreakpoints]
abstract class ResponsiveViewState<Page extends View, Con extends Controller>
extends ViewState<Page, Con> {
abstract class ResponsiveViewState<Page extends CleanView,
Con extends Controller> extends CleanViewState<Page, Con> {
ResponsiveViewState(Con controller) : super(controller);

/// To be implemented by the developer which will build on [Watch ViewPort].
Expand Down Expand Up @@ -90,14 +90,14 @@ abstract class ResponsiveViewState<Page extends View, Con extends Controller>
}
}

/// The [ViewState] represents the [State] of a [StatefulWidget], typically of a screen or a
/// page. The [ViewState] requires a [Controller] to handle its events and provide its data.
/// The [CleanViewState] represents the [State] of a [StatefulWidget], typically of a screen or a
/// page. The [CleanViewState] requires a [Controller] to handle its events and provide its data.
///
/// The [ViewState] also has a default [globalKey] that can be used inside its `build()` function
/// The [CleanViewState] also has a default [globalKey] that can be used inside its `build()` function
/// in a widget to grant easy access to the [Controller], which could then use it to display
/// snackbars, dialogs, and so on.
///
/// The [ViewState] lifecycle is also handled by the [Controller].
/// The [CleanViewState] lifecycle is also handled by the [Controller].
/// ```dart
/// class CounterState extends ViewState<CounterPage, CounterController> {
/// CounterState(CounterController controller) : super(controller);
Expand Down Expand Up @@ -126,18 +126,18 @@ abstract class ResponsiveViewState<Page extends View, Con extends Controller>
/// }
///
/// ```
abstract class ViewState<Page extends View, Con extends Controller>
abstract class CleanViewState<Page extends CleanView, Con extends Controller>
extends State<Page> {
final GlobalKey<State<StatefulWidget>> globalKey =
GlobalKey<State<StatefulWidget>>();
final Con _controller;
late Logger _logger;
late ViewBuilder builder;

/// Implement the [Widget] you want to be displayed on [View]
/// Implement the [Widget] you want to be displayed on [CleanView]
Widget get view;

ViewState(this._controller) {
CleanViewState(this._controller) {
_controller.initController(globalKey);
WidgetsBinding?.instance // ignore: invalid_null_aware_operator
.addObserver(_controller); // ignore:unnecessary_non_null_assertion
Expand Down Expand Up @@ -197,11 +197,11 @@ abstract class ViewState<Page extends View, Con extends Controller>
}
}

/// The [View] represents a [StatefulWidget]. The [View] is typically a page or screen in
/// the application. However, a [View] can be any [StatefulWidget]. The [View] must have a
/// The [CleanView] represents a [StatefulWidget]. The [CleanView] is typically a page or screen in
/// the application. However, a [CleanView] can be any [StatefulWidget]. The [CleanView] must have a
/// [State], and that [State] should be of type [ViewState<MyView, MyController>].
///
/// If a [RouteObserver] is given to the [View], it is used to register its [Controller] as
/// If a [RouteObserver] is given to the [CleanView], it is used to register its [Controller] as
/// a subscriber, which provides the ability to listen to push and pop route events.
/// ```dart
/// class CounterPage extends View {
Expand All @@ -213,10 +213,10 @@ abstract class ViewState<Page extends View, Con extends Controller>
///
/// ```
///
abstract class View extends StatefulWidget {
abstract class CleanView extends StatefulWidget {
@override
final Key? key;
final RouteObserver? routeObserver;

const View({this.routeObserver, this.key}) : super(key: key);
const CleanView({this.routeObserver, this.key}) : super(key: key);
}

0 comments on commit 95c287f

Please sign in to comment.