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

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(
    enableLoginOffline: false,
    restUrl: 'https://platform.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()),
        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;
            }
          },
          child: child,
        );
      },
      onGenerateRoute: (_) => SplashScreen.route(),
    );
  }
}
4
likes
0
pub points
80%
popularity

Publisher

verified publishersenior.com.br

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