senior_platform_authentication_ui 3.1.0 copy "senior_platform_authentication_ui: ^3.1.0" to clipboard
senior_platform_authentication_ui: ^3.1.0 copied to clipboard

outdated

A package that make it easy to implement the Senior X authentication for Flutter. Built to be used with the bloc state management package.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:senior_authentication_ui_example/login_screen.dart';
import 'package:senior_design_system/senior_design_system.dart';
import 'package:senior_platform_authentication_ui/senior_platform_authentication_ui.dart';

import 'home_screen.dart';
import 'splash_screen.dart';

void main() {
  SeniorAuthentication.initialize(
    automaticLogon: true,
    enableLoginOffline: true,
    restUrl: 'https://cloud-leaf.senior.com.br/t/senior.com.br/bridge/1.0/rest',
  );
  runApp(const ExampleApp());
}

class ExampleApp extends StatelessWidget {
  const ExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return SeniorDesignSystem(
      child: BlocProvider(
        create: (context) => AuthenticationBloc()
          ..add(
            CheckAuthenticationRequested(
              username: AuthenticationBloc().state.username,
            ),
          ),
        child: const AppView(),
      ),
    );
  }
}

class AppView extends StatefulWidget {
  const AppView({super.key});

  @override
  State<AppView> 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,
      builder: (context, child) {
        return BlocListener<AuthenticationBloc, AuthenticationState>(
          listener: (context, state) {
            switch (state.status) {
              case AuthenticationStatus.authenticated:
                _navigator.pushAndRemoveUntil<void>(
                  MaterialPageRoute<void>(builder: (_) => const HomeScreen()),
                  (route) => false,
                );
                break;
              case AuthenticationStatus.unauthenticated:
                _navigator.pushAndRemoveUntil<void>(
                  MaterialPageRoute<void>(
                    builder: (_) => const LoginScreen(),
                  ),
                  (route) => false,
                );
                break;
              case AuthenticationStatus.unknown:
                break;
              case AuthenticationStatus.offline:
                _navigator.pushAndRemoveUntil<void>(
                  MaterialPageRoute<void>(builder: (_) => const HomeScreen()),
                  (route) => false,
                );
                break;
            }
          },
          child: child,
        );
      },
      onGenerateRoute: (_) => SplashScreen.route(),
    );
  }
}
4
likes
0
points
1.06k
downloads

Publisher

verified publishersenior.com.br

Weekly Downloads

A package that make it easy to implement the Senior X authentication for Flutter. Built to be used with the bloc state management package.

Homepage

License

unknown (license)

Dependencies

equatable, flutter, flutter_bloc, flutter_localizations, flutter_secure_storage, font_awesome_flutter, intl, provider, senior_design_system, senior_design_tokens, senior_platform_authentication, url_launcher, webview_flutter

More

Packages that depend on senior_platform_authentication_ui