sghi_core 0.3.133 copy "sghi_core: ^0.3.133" to clipboard
sghi_core: ^0.3.133 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:flutter/material.dart';
import 'package:sghi_core/afya_moja_core/afya_moja_core.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/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/flutter_graphql_client/flutter_graphql_client.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: CustomRawMaterialButton(
          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: defaultTextTheme.titleLarge!
                    .copyWith(fontWeight: fontWeightRegular)),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {},
        tooltip: 'Increment',
        backgroundColor: Colors.blue,
        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),
        'BewellApp',
      ),
      communitiesClient: GraphQlClient(
        'id_token',
        EndpointContext.getGraphQLEndpoint(appConfig),
        'BewellApp',
      ),
      appConfig: appConfig,
      child: Builder(
        builder: (BuildContext context) {
          return const MaterialApp(

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

/// [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('first_name'));

  @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 Center(
      child:
          Text('Large Screen Content', style: defaultTextTheme.headlineMedium),
    );
  }
}

class MediumScreenContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text('Medium Screen Content',
          style: defaultTextTheme.titleLarge!
              .copyWith(fontWeight: fontWeightRegular)),
    );
  }
}

class SmallScreenContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text(
        'Small Screen Content',
        style: defaultTextTheme.bodyMedium,
      ),
    );
  }
}

/// [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();
  }
}