mih_package_toolkit 1.1.1 copy "mih_package_toolkit: ^1.1.1" to clipboard
mih_package_toolkit: ^1.1.1 copied to clipboard

A comprehensive UI toolkit and utility library for building consistent MIH Packages within the MIH Project ecosystem.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:mih_package_toolkit/mih_package_toolkit.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(title: 'Flutter Demo', home: const ExampleMihPackage());
  }
}

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

  @override
  State<ExampleMihPackage> createState() => _ExampleMihPackageState();
}

class _ExampleMihPackageState extends State<ExampleMihPackage> {
  @override
  Widget build(BuildContext context) {
    return MihPackage(
      backgroundColor: MihColors.primary(),
      packageActionButton: actionButton(),
      tools: getPackageTools(),
      selectedBodyIndex: selectedbodyIndex,
      onIndexChange: (newIndex) {
        setState(() {
          selectedbodyIndex = newIndex;
        });
      },
    );
  }

  int selectedbodyIndex = 0; // Important for state management of the body

  Widget actionButton() {
    return MihPackageAction(
      iconColor: MihColors.secondary(),
      icon: Icon(MihIcons.mihLogo),
      iconSize: 35,
      onTap: () {
        ScaffoldMessenger.of(context).showSnackBar(
          MihSnackBar(
            child: Text(
              "Action Button Pressed",
              style: TextStyle(color: MihColors.primary()),
            ),
            duration: 2,
            backgroundColor: MihColors.secondary(),
            closeIconColor: MihColors.red(),
          ),
        );
      },
    );
  }

  List<MihPackageTool> getPackageTools() {
    List<MihPackageTool> tools = [];
    tools.add(toolOne(context));
    tools.add(toolTwo());
    return tools;
  }

  MihPackageTool toolOne(BuildContext context) {
    return MihPackageTool(
      title: "Tool 1",
      body: MihPackageToolBody(
        backgroundColor: MihColors.primary(),
        bodyItem: MihSingleChildScroll(
          scrollbarOn: true,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                "Tool Body One",
                style: TextStyle(
                  color: MihColors.secondary(),
                  fontSize: 25,
                  fontWeight: FontWeight.bold,
                ),
              ),
              const SizedBox(height: 10),
              MihPackageTile(
                authenticateUser: true,
                onTap: () {
                  debugPrint("User Authenticated, accessing tile...");
                },
                packageName: "Secure Package",
                packageIcon: Icon(
                  MihIcons.mihAccessControls,
                  color: MihColors.secondary(),
                ),
                iconSize: 150,
                textColor: MihColors.secondary(),
              ),
              const SizedBox(height: 10),
              MihButton(
                width: 300,
                onPressed: () {
                  showDialog(
                    context: context,
                    builder: (context) => MihPackageWindow(
                      fullscreen: false,
                      windowTitle: "Window Test",
                      onWindowTapClose: () {
                        Navigator.pop(context);
                      },
                      windowBody: Placeholder(),
                    ),
                  );
                },
                buttonColor: MihColors.green(),
                child: Text("Open Window"),
              ),
              const SizedBox(height: 10),
              MihButton(
                width: 300,
                onPressed: () {
                  showDialog(
                    context: context,
                    builder: (context) => MihPackageWindow(
                      fullscreen: true,
                      windowTitle: "Full Window Test",
                      onWindowTapClose: () {
                        Navigator.pop(context);
                      },
                      windowBody: Placeholder(),
                    ),
                  );
                },
                buttonColor: MihColors.green(),
                child: Text("Open Window (Full)"),
              ),
              const SizedBox(height: 10),
              MihButton(
                width: 300,
                onPressed: () {
                  ScaffoldMessenger.of(context).showSnackBar(
                    MihSnackBar(
                      child: Text(
                        "This is the MIH Snack",
                        style: TextStyle(color: MihColors.primary()),
                      ),
                      duration: 2,
                      backgroundColor: MihColors.secondary(),
                      closeIconColor: MihColors.red(),
                    ),
                  );
                },
                buttonColor: MihColors.green(),
                child: Text("Snack Test"),
              ),
              const SizedBox(height: 10),
              MihTextFormField(
                width: 300,
                fillColor: MihColors.secondary(),
                inputColor: MihColors.primary(),
                controller: TextEditingController(),
                hintText: "Input Field Text",
                requiredText: true,
              ),
              const SizedBox(height: 10),
              MihRadioOptions(
                width: 300,
                controller: TextEditingController(),
                hintText: "Test Radio",
                fillColor: MihColors.secondary(),
                secondaryFillColor: MihColors.primary(),
                requiredText: true,
                radioOptions: ["One", "Two", "Three"],
              ),
              const SizedBox(height: 10),
              MihToggle(
                width: 300,
                hintText: "Test Toggle",
                initialPostion: false,
                fillColor: MihColors.secondary(),
                secondaryFillColor: MihColors.primary(),
                onChange: (_) {},
              ),
            ],
          ),
        ),
      ),
      icon: const Icon(Icons.calculate),
      onIconSelect: () {
        setState(() {
          selectedbodyIndex = 0;
        });
      },
    );
  }

  MihPackageTool toolTwo() {
    return MihPackageTool(
      title: "Tool 2",
      body: MihPackageToolBody(
        backgroundColor: MihColors.secondary(),
        bodyItem: Center(
          child: Text(
            "Tool Body Two",
            style: TextStyle(
              color: MihColors.primary(),
              fontSize: 25,
              fontWeight: FontWeight.bold,
            ),
          ),
        ),
      ),
      icon: const Icon(Icons.money),
      onIconSelect: () {
        setState(() {
          selectedbodyIndex = 1;
        });
      },
    );
  }
}
2
likes
150
points
276
downloads

Documentation

API reference

Publisher

verified publishermzansi-innovation-hub.co.za

Weekly Downloads

A comprehensive UI toolkit and utility library for building consistent MIH Packages within the MIH Project ecosystem.

Repository
View/report issues

License

GPL-3.0 (license)

Dependencies

app_settings, flutter, flutter_screen_lock, flutter_secure_storage, flutter_speed_dial, local_auth

More

Packages that depend on mih_package_toolkit