sghi_core 0.3.89 copy "sghi_core: ^0.3.89" to clipboard
sghi_core: ^0.3.89 copied to clipboard

A set of reusable components used in myCareHub and myCareHub Professional

example/main.dart

// ignore_for_file: unreachable_from_main

import 'package:debug_logger/debug_logger.dart';
import 'package:flutter/material.dart';
import 'package:sghi_core/afya_moja_core/src/presentation/text_themes.dart';
import 'package:sghi_core/app_wrapper/app_config.dart';

import 'package:sghi_core/app_wrapper/app_wrapper.dart';
import 'package:sghi_core/app_wrapper/app_wrapper_base.dart';
import 'package:sghi_core/app_wrapper/endpoints_context.dart';
import 'package:sghi_core/dart_fcm/fcm.dart';
import 'package:sghi_core/domain_objects/entities/bio_data.dart';
import 'package:sghi_core/domain_objects/value_objects/name.dart';
import 'package:sghi_core/flutter_graphql_client/flutter_graphql_client.dart';
import 'package:sghi_core/misc_utilities/responsive_widget.dart';
import 'package:sghi_core/shared_themes/colors.dart';
import 'package:sghi_core/shared_themes/spaces.dart';
import 'package:sghi_core/ui_components/src/buttons.dart';
import 'package:sghi_core/user_profile/contacts.dart';

void main() {
  // change this class to see other examples
  runApp(UiComponentsExample());
}

/// [UiComponentsExample]
class UiComponentsExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SizedBox(
        // SILPrimaryButton is one among many other UI components provided to you by this pkg
        // For more arguments or customization options for this and other UI Components, check project source files (`./lib/src/`)
        child: SILPrimaryButton(
          buttonKey: const Key('your_button_key'),
          text: 'Button Text',
          borderColor: Colors.black, // your button's border color
          buttonColor: Colors.black, // your button's fill color
          textColor: Colors.white, // your button's text color
          customChild: const Icon(
            Icons.add,
            size: 30,
            color: Colors.white,
          ), // Used when adding a custom child instead of a text widget
          onPressed: () {},
          onLongPress: () {},
        ),
      ),
    );
  }
}

/// [SharedThemesExample]
class SharedThemesExample extends StatefulWidget {
  /// This widget is the root of your application.
  const SharedThemesExample({super.key});

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

class _SharedThemesExampleState extends State<SharedThemesExample> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Shared themes example'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),

            /// Uses the sizes exported as doubles in `spaces.dart`
            const SizedBox(height: Sizing.size4),

            /// Use the text themes defined `text_themes.dart`
            Text(
              'Counter value',
              style: normalSize20Text(),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {},
        tooltip: 'Increment',

        /// Uses the color constants exported as colors in `colors.dart`
        backgroundColor: red,
        child: const Icon(Icons.add),
      ),
    );
  }
}

/// [AppWrapperExample] marks as the entry point to your application.
///
/// Wraps your app with [AppWrapper] class.
///
/// Takes in an appConfig (e.g `bewellTest`, `myCarehubProd` etc)
/// [appConfig] is the app running environment and variant configuration
/// This can be different app `variants` and their respective environments (`prod`, `test`, `demo`, `e2e`)
class AppWrapperExample extends StatelessWidget {
  const AppWrapperExample({super.key, required this.appConfig});

  final AppConfig appConfig;

  @override
  Widget build(BuildContext context) {
    return AppWrapper(
      appName: 'appName',
      graphQLClient: GraphQlClient(
        'id_token',
        EndpointContext.getGraphQLEndpoint(appConfig),
      ),
      communitiesClient: GraphQlClient(
        'id_token',
        EndpointContext.getGraphQLEndpoint(appConfig),
      ),
      appConfig: appConfig,
      child: Builder(
        builder: (BuildContext context) {
          return const MaterialApp(

              /// Entry point to your application
              );
        },
      ),
    );
  }
}

/// [FlutterGrapgqlClientExample]
/// Use this class for making API calls
class FlutterGrapgqlClientExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SizedBox(
        child: SILPrimaryButton(
          buttonKey: const Key('your_button_key'),
          text: 'Button Text',
          borderColor: Colors.black,
          buttonColor: Colors.black,
          textColor: Colors.white,
          customChild: const Icon(
            Icons.add,
            size: 30,
            color: Colors.white,
          ),
          onPressed: () async {
            // Making GraphQL calls
            final dynamic data = await SimpleCall.callAPI(
              queryString: 'your query string',
              variables: <String, dynamic>{'payload': 'payload'},
              // pass in your graphql client here
              graphClient: AppWrapperBase.of(context)!.graphQLClient,
            );
            DebugLogger.info(data);

            /// Making REST calls
            /// used for making [GET]
            final dynamic getCall = await SimpleCall.callRestAPI(
              endpoint: 'http://example.com/test',
              method: 'GET',
              graphClient: AppWrapperBase.of(context)!.graphQLClient,
            );
            DebugLogger.info(getCall);

            /// used for making [POST]
            final dynamic postCall = await SimpleCall.callRestAPI(
              endpoint: 'http://example.com/test',
              method: 'POST',
              variables: <String, dynamic>{'pay': 'load'},
              graphClient: AppWrapperBase.of(context)!.graphQLClient,
            );
            DebugLogger.info(postCall);
          },
          onLongPress: () {},
        ),
      ),
    );
  }
}

/// [DomainObjectsExample]
class DomainObjectsExample extends StatelessWidget {
  DomainObjectsExample({super.key});

  /// Use this package to define custom concrete types
  /// The example below uses this package's `BioData` type.
  final BioData? userBio = BioData(firstName: Name.fromJson('firstname'));

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

/// [MiscUtilitiesExample]
/// Use this package to define custom functions.
/// The example below uses this package's `ResponsiveWidget` class.
class MiscUtilitiesExample extends StatelessWidget {
  const MiscUtilitiesExample({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Responsive Widget Example'),
        ),
        body: ResponsiveWidget(
          largeScreen: LargeScreenContent(),
          mediumScreen: MediumScreenContent(),
          smallScreen: SmallScreenContent(),
        ),
      ),
    );
  }
}

class LargeScreenContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return const Center(
      child: Text(
        'Large Screen Content',
        style: TextStyle(fontSize: 24),
      ),
    );
  }
}

class MediumScreenContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return const Center(
      child: Text(
        'Medium Screen Content',
        style: TextStyle(fontSize: 20),
      ),
    );
  }
}

class SmallScreenContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return const Center(
      child: Text(
        'Small Screen Content',
        style: TextStyle(fontSize: 16),
      ),
    );
  }
}

/// [DartFCMExample]
/// Use this package to define fcm functions
class DartFCMExample extends StatefulWidget {
  const DartFCMExample({super.key});

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

class _DartFCMExampleState extends State<DartFCMExample> {
  bool hasFinishedLaunching = false;

  @override
  void didChangeDependencies() {
    if (!hasFinishedLaunching) {
      /// [configure] is responsible for correctly setting
      /// up local notifications ( and asking for permission if needed) and wiring-up
      /// firebase messaging [onMessage] callback to show fcm messages
      SILFCM().configure(context: context);
      hasFinishedLaunching = true;
    }

    super.didChangeDependencies();
  }

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(
          // Your application
          ),
    );
  }
}

/// [UserProfileExample]
/// This class renders [ContactDetails] which is the root page for this package
///
/// It renders [ContactItemsCard]s with details including:
/// - User's Contact Info (Primary Phone Number, Primary Email Address, Secondary Contact Details (phone Number and email))
class UserProfileExample extends StatelessWidget {
  const UserProfileExample({super.key});

  @override
  Widget build(BuildContext context) {
    return const ContactDetails();
  }
}