multi_package_sample icon indicating copy to clipboard operation
multi_package_sample copied to clipboard

Can the features be modified to such level that one does not know about another's existence?

Open aap01 opened this issue 3 years ago • 0 comments

import 'package:common_dependencies/common_dependencies.dart';
import 'package:core/core.dart';

import 'package:flutter/material.dart';
import 'package:login/src/analytics/login_analytics_logger.dart';
import 'package:login/src/localization/login_localization.dart';

class LoginScreen extends StatefulWidget {
  @override
  _LoginScreenState createState() => _LoginScreenState();
}

class _LoginScreenState extends State<LoginScreen> {
  final AnalyticsLogger _analyticsLogger = AppInjector.I.get();
  final HomeNavigator _homeNavigator = AppInjector.I.get();

  late LoginLocalization _intl;

  @override
  Widget build(BuildContext context) {
    _intl = LoginLocalization.of(context);

    return Scaffold(
      body: Padding(
        padding: const EdgeInsets.all(16),
        child: Column(children: [
          const Spacer(),
          Text(_intl.tr('login_screen.title')),
          const Spacer(),
          SizedBox(
            width: double.infinity,
            child: ElevatedButton(
              onPressed: () {
                _analyticsLogger.logEvent(LoginEvents.loginButtonClick);
               // The following line is my point of interest
                _homeNavigator.navigateToRoot(context);
              },
              child: Text(_intl.tr('login_screen.action')),
            ),
          ),
          const SizedBox(height: 16),
        ]),
      ),
    );
  }
}

In the code snippet, LoginScreen has to know that there exists a HomeNavigator from Some feature other than Login itself. I could imagine an Independent LoginScreen that only broadcasts or communicates back to a "central observer" notifying that login is successful. That "central observer" could decide whether to navigate to HomeScreen or show a dialogue or do whatever it pleases. I would like to hear your thoughts on this.

I have to mention that I very much appreciate the architecture you have created here. It is insightful in the sense of software architecture and I have learned a lot from it. Thank you for such a good content

aap01 avatar Jan 18 '23 05:01 aap01