senior_authentication 0.4.0 copy "senior_authentication: ^0.4.0" to clipboard
senior_authentication: ^0.4.0 copied to clipboard

discontinuedreplaced by: senior_platform_authentication_ui
PlatformAndroidiOS

Flutter package which manages the authentication domain.

example/example.md

Senior Authentication #

All the snippets are from the example project.

Simple Usage #

void main() {
  runApp(App(
    authenticationRepository: AuthenticationRepository(
        urlBase:
            'https://platform.senior.com.br/t/senior.com.br/bridge/1.0/rest'),
  ));
}
class App extends StatelessWidget {
  const App({Key? key, required this.authenticationRepository})
      : super(key: key);

  final AuthenticationRepository authenticationRepository;

  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(
        SystemUiOverlayStyle(statusBarColor: Colors.white));

    return RepositoryProvider.value(
      value: authenticationRepository,
      child: BlocProvider(
        create: (_) => AuthenticationBloc(
          authenticationRepository: authenticationRepository,
        ),
        child: AppView(),
      ),
    );
  }
}

class AppView extends StatefulWidget {
  AppView({Key? key}) : super(key: key);

  @override
  _AppViewState createState() => _AppViewState();
}

class _AppViewState extends State<AppView> {
  final _navigatorKey = GlobalKey<NavigatorState>();

  NavigatorState get _navigator => _navigatorKey.currentState!;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: _navigatorKey,
      title: 'Example',
      theme: ThemeData(
        primaryColor: Color(0xFF0E866A),
        visualDensity: VisualDensity.adaptivePlatformDensity,
        scaffoldBackgroundColor: Colors.white,
      ),
      debugShowCheckedModeBanner: false,
      initialRoute: 'splash',
      routes: {
        'splash': (ctx) => SplashScreen(),
        'home': (ctx) => HomeScreen(),
      },
      builder: (context, child) {
        return BlocListener<AuthenticationBloc, AuthenticationState>(
          child: child,
          listener: (context, state) {
            switch (state.status) {
              case AuthenticationStatus.authenticated:
                _navigator.pushNamedAndRemoveUntil<void>(
                  "home",
                  (route) => false,
                );
                break;
              case AuthenticationStatus.unauthenticated:
                _navigator.pushAndRemoveUntil<void>(
                  MaterialPageRoute(builder: (ctx) => WelcomeScreen()),
                  (route) => false,
                );
                break;
              default:
                break;
            }
          },
        );
      },
    );
  }
}