Compare commits
188 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 971623af77 | |||
| 84cb6b2e83 | |||
| 6e07a55885 | |||
| 8fb31695a8 | |||
| 4fafa35888 | |||
| 0cf9634c5d | |||
| 787a8057b2 | |||
| 5f911d51f9 | |||
| 8da29792b4 | |||
| fd4c34c59d | |||
| 5e003a4d71 | |||
| dca595bf60 | |||
| fcf1bbbb15 | |||
| 8a0c0d7dba | |||
| ff7f363983 | |||
| a54f1c61ae | |||
| 843997e58c | |||
| cbe70e2e44 | |||
| 3778ebb261 | |||
| c911e88453 | |||
| b1487839a7 | |||
| 518dd1300e | |||
| 221030eff3 | |||
| 707b49c088 | |||
| 5135629b33 | |||
| bb64be077f | |||
| 281ea863e8 | |||
| 64af64f28b | |||
| 1c0dd6d328 | |||
| 07d4ba4afa | |||
| 6ad6b6ccbd | |||
| ce2575035f | |||
| baea2c9fdb | |||
| 27639cb964 | |||
| 1143d11054 | |||
| 213f3d418d | |||
| e33a62b909 | |||
| ebab9bae52 | |||
| 82c25c5406 | |||
| 3f0fc08a5c | |||
| f137ea41ac | |||
| a7effa3576 | |||
| 74341a9cc6 | |||
| c5267c0540 | |||
| d4ba3aaa03 | |||
| 103ccdc022 | |||
| f8a722eb50 | |||
| fdb28080e3 | |||
| 8a384921c5 | |||
| 4b47bf5288 | |||
| 141611b84d | |||
| a29d0afeb8 | |||
| eb93714022 | |||
| 071612a521 | |||
| 726a60ad25 | |||
| b897986c1f | |||
| 7d4d7fc713 | |||
| 91075255f4 | |||
| 5c2f19dcc4 | |||
| 58aebbeabe | |||
| 670480910b | |||
| 45c1b247d3 | |||
|
|
ecd24670e9 | ||
|
|
ab99518ff2 | ||
|
|
6ac6aff59e | ||
| 33ca7b613e | |||
|
|
e83b0b50ae | ||
|
|
bcd19de256 | ||
|
|
ae36879ec5 | ||
|
|
eda609cf7e | ||
|
|
e1744b09e3 | ||
| a3845df8bd | |||
| d7eebe152b | |||
| d8a807b43e | |||
| 5172017a54 | |||
| 535924691e | |||
| ca8e0f56ac | |||
| 63071325cb | |||
| 800cd635c2 | |||
| f46ce36861 | |||
| b69fd92b19 | |||
| 9e19dc0fa4 | |||
| 38c40e2dfe | |||
| 02bbc32d23 | |||
| 5b052a1fa9 | |||
| d5349d981c | |||
| d6c28b631a | |||
| 74c5276c94 | |||
| d5e349d218 | |||
| 44527c8f10 | |||
| fbb9d8573c | |||
| 010fc0bc74 | |||
| 45ac3f03e6 | |||
| eea3248525 | |||
| b945a34ad4 | |||
| e3ac1be71c | |||
| 3a955e67ef | |||
| 777043e2ca | |||
| 6a8b9c6902 | |||
| 07360dd308 | |||
| 7c59e2a5c8 | |||
| 0b57e10532 | |||
| 5681c6d73b | |||
| f44ff6443c | |||
| fe5b61f6bc | |||
| e7729a8ce8 | |||
| 227a2f7ae7 | |||
| f26c1eb01a | |||
| ca0f13a6df | |||
| 021a25f50c | |||
| 0a9f0c000e | |||
| 3ff670886c | |||
| a6d5e4ad35 | |||
| 456dff6402 | |||
| d3fdc83373 | |||
| 8704d4dd64 | |||
| 37920466ac | |||
| 56d54a3711 | |||
| aef501cd25 | |||
| 4f5761271c | |||
| 252e120b99 | |||
| b5c26c3e43 | |||
| 74be2fc559 | |||
| b519b99a91 | |||
| 72261af7b9 | |||
| ad96725478 | |||
| ef4c3102a9 | |||
| 9a75bcc810 | |||
| 586e67b369 | |||
| e8cae1a894 | |||
| cd8115c597 | |||
| 730c5d2bdf | |||
| cea8ccab5a | |||
| 4f168c5b0e | |||
| 99f8b1a3f9 | |||
| 30c06261c8 | |||
| c843c0a55d | |||
| 94ac83db9e | |||
| a3b8da5357 | |||
| 47bc23c029 | |||
| c16d8b6e91 | |||
| a6fe4499d0 | |||
| 004c2397c5 | |||
| d64193d1f8 | |||
| e330875c6f | |||
| 3d2addf1d6 | |||
| 3b6e1d22ec | |||
| ff913c0c54 | |||
| c45c933277 | |||
| 89d6999abf | |||
| 969ecf8fdc | |||
| ee7d3881e6 | |||
| cc3f18f7e2 | |||
| 08bfe1d417 | |||
| 3593011d6d | |||
| 5ae11f6625 | |||
| a61bca7d81 | |||
| fb3b033f45 | |||
| 91a2d0dd1e | |||
| 04c643561b | |||
| 526bd40255 | |||
| 1889f6cada | |||
| c1dd9a60f2 | |||
| ec869c54c3 | |||
| b440c0a42b | |||
| baa826c52c | |||
| 6b530529e3 | |||
| a633b52949 | |||
| c103d1979c | |||
| 82c01cb7bf | |||
| 43bc552698 | |||
| bb6a8e3090 | |||
| 565e9199d4 | |||
| c5de46040d | |||
| 934b1b2301 | |||
| 302152449f | |||
| 0f591bd111 | |||
|
|
ea04c000cf | ||
| b0825fe7cb | |||
| 8a2debcaa8 | |||
| 609c8d46db | |||
| 1387fb1af5 | |||
| 1f73aa3b87 | |||
| 47ca6d7311 | |||
| 64443a5076 | |||
| 20d5bc4004 | |||
| 9257786191 | |||
|
|
963a708ab8 |
16
.gitignore
vendored
@@ -1,16 +1,14 @@
|
||||
# *database/auto.cnf
|
||||
# *database/binlog.index
|
||||
# *database/mysql.sock
|
||||
File_Storage
|
||||
database/
|
||||
mih_minio/
|
||||
mih_db/
|
||||
mih_git/
|
||||
mih_nginx/
|
||||
mih_monitor/
|
||||
mih_wp/
|
||||
certbot/
|
||||
Firebase-emulator/
|
||||
Mzansi_Mail/
|
||||
# database/ibdata1
|
||||
# database/mysql.ibd
|
||||
# database/undo*
|
||||
# database/#innodb_redo/#ib_redo*
|
||||
.venv
|
||||
google-chrome-stable_current_amd64.deb
|
||||
.env
|
||||
Frontend/android/app/.cxx/
|
||||
.DS_Store
|
||||
17
.vscode/launch.json
vendored
@@ -6,14 +6,25 @@
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Debug",
|
||||
"cwd": "Frontend",
|
||||
"cwd": "mih_ui",
|
||||
"request": "launch",
|
||||
"type": "dart",
|
||||
"program": "lib/main_dev.dart"
|
||||
},
|
||||
{
|
||||
"name": "Debug (web)",
|
||||
"cwd": "mih_ui",
|
||||
"request": "launch",
|
||||
"type": "dart",
|
||||
"program": "lib/main_dev.dart",
|
||||
"args": [
|
||||
"--web-port",
|
||||
"1995"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Profile",
|
||||
"cwd": "Frontend",
|
||||
"cwd": "mih_ui",
|
||||
"request": "launch",
|
||||
"type": "dart",
|
||||
"flutterMode": "profile",
|
||||
@@ -21,7 +32,7 @@
|
||||
},
|
||||
{
|
||||
"name": "Release",
|
||||
"cwd": "Frontend",
|
||||
"cwd": "mih_ui",
|
||||
"request": "launch",
|
||||
"type": "dart",
|
||||
"flutterMode": "release",
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
# This file tracks properties of this Flutter project.
|
||||
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
||||
#
|
||||
# This file should be version controlled and should not be manually edited.
|
||||
|
||||
version:
|
||||
revision: "8defaa71a77c16e8547abdbfad2053ce3a6e2d5b"
|
||||
channel: "stable"
|
||||
|
||||
project_type: app
|
||||
|
||||
# Tracks metadata for the flutter migrate command
|
||||
migration:
|
||||
platforms:
|
||||
- platform: root
|
||||
create_revision: 8defaa71a77c16e8547abdbfad2053ce3a6e2d5b
|
||||
base_revision: 8defaa71a77c16e8547abdbfad2053ce3a6e2d5b
|
||||
- platform: android
|
||||
create_revision: 8defaa71a77c16e8547abdbfad2053ce3a6e2d5b
|
||||
base_revision: 8defaa71a77c16e8547abdbfad2053ce3a6e2d5b
|
||||
- platform: ios
|
||||
create_revision: 8defaa71a77c16e8547abdbfad2053ce3a6e2d5b
|
||||
base_revision: 8defaa71a77c16e8547abdbfad2053ce3a6e2d5b
|
||||
- platform: linux
|
||||
create_revision: 8defaa71a77c16e8547abdbfad2053ce3a6e2d5b
|
||||
base_revision: 8defaa71a77c16e8547abdbfad2053ce3a6e2d5b
|
||||
- platform: macos
|
||||
create_revision: 8defaa71a77c16e8547abdbfad2053ce3a6e2d5b
|
||||
base_revision: 8defaa71a77c16e8547abdbfad2053ce3a6e2d5b
|
||||
- platform: web
|
||||
create_revision: 8defaa71a77c16e8547abdbfad2053ce3a6e2d5b
|
||||
base_revision: 8defaa71a77c16e8547abdbfad2053ce3a6e2d5b
|
||||
- platform: windows
|
||||
create_revision: 8defaa71a77c16e8547abdbfad2053ce3a6e2d5b
|
||||
base_revision: 8defaa71a77c16e8547abdbfad2053ce3a6e2d5b
|
||||
|
||||
# User provided section
|
||||
|
||||
# List of Local paths (relative to this file) that should be
|
||||
# ignored by the migrate tool.
|
||||
#
|
||||
# Files that are not part of the templates will be ignored by default.
|
||||
unmanaged_files:
|
||||
- 'lib/main.dart'
|
||||
- 'ios/Runner.xcodeproj/project.pbxproj'
|
||||
@@ -1,48 +0,0 @@
|
||||
# Install Operating system and dependencies
|
||||
#FROM ubuntu:22.04
|
||||
FROM debian:latest AS build-env
|
||||
|
||||
#ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
RUN apt-get update --fix-missing
|
||||
|
||||
RUN apt-get install -y curl git wget unzip gdb libstdc++6 libglu1-mesa fonts-droid-fallback
|
||||
# RUN apt-get install -y curl git wget unzip libgconf-2-4 gdb libstdc++6 libglu1-mesa fonts-droid-fallback
|
||||
RUN apt-get install python3 -y
|
||||
|
||||
# download Flutter SDK from Flutter Github repo
|
||||
RUN git clone -b flutter-3.32-candidate.0 https://github.com/flutter/flutter.git /usr/local/flutter
|
||||
# RUN git clone -b stable https://github.com/flutter/flutter.git /usr/local/flutter
|
||||
|
||||
# Set flutter environment path
|
||||
ENV PATH="/usr/local/flutter/bin:/usr/local/flutter/bin/cache/dart-sdk/bin:${PATH}"
|
||||
#ENV PATH "$PATH:/home/developer/flutter/bin"
|
||||
|
||||
RUN flutter doctor -v
|
||||
|
||||
# Enable flutter web
|
||||
RUN flutter channel flutter-3.32-candidate.0
|
||||
# RUN flutter channel stable
|
||||
RUN flutter config --enable-web
|
||||
|
||||
# Copy files to container and build
|
||||
RUN mkdir /app/
|
||||
COPY . /app/
|
||||
|
||||
WORKDIR /app
|
||||
# RUN flutter upgrade
|
||||
RUN flutter build web --release -t ./lib/main_prod.dart
|
||||
# RUN flutter build web --release --web-renderer canvaskit -t ./lib/main_prod.dart
|
||||
|
||||
|
||||
# RUN cd ..
|
||||
|
||||
# WORKDIR /app/build/web/
|
||||
|
||||
EXPOSE 83
|
||||
|
||||
RUN ["chmod", "+x", "/app/server/server.sh"]
|
||||
|
||||
ENTRYPOINT [ "/app/server/server.sh"]
|
||||
|
||||
# RUN ["python3", "-u", "/app/server/MIH_web_server.py"]
|
||||
|
Before Width: | Height: | Size: 8.6 KiB |
|
Before Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 7.6 KiB |
|
Before Width: | Height: | Size: 11 KiB |
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="ic_launcher_background">#6641b2</color>
|
||||
<!-- Women For Change -->
|
||||
<color name="mih_icon_background">#6641b2</color>
|
||||
<color name="mih_icon_foreground">#E0D1FF</color>
|
||||
<!-- Original -->
|
||||
<!-- <color name="mih_icon_background">#3A4454</color>
|
||||
<color name="mih_icon_foreground">#bedcfe</color> -->
|
||||
</resources>
|
||||
|
Before Width: | Height: | Size: 70 KiB |
|
Before Width: | Height: | Size: 654 B |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 9.8 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 7.6 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 8.0 KiB |
|
Before Width: | Height: | Size: 8.9 KiB |
@@ -1,321 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
import "package:universal_html/html.dart" as html;
|
||||
|
||||
class MihTheme {
|
||||
// late int _mainColor;
|
||||
// late int _secondColor;
|
||||
//late int _errColor;
|
||||
//late int _succColor;
|
||||
// late int _mesColor;
|
||||
late String mode;
|
||||
late String screenType;
|
||||
late AssetImage loading;
|
||||
late String loadingAssetText;
|
||||
late TargetPlatform platform;
|
||||
bool kIsWeb = const bool.fromEnvironment('dart.library.js_util');
|
||||
String latestVersion = "1.2.4";
|
||||
// Options:-
|
||||
// f3f9d2 = Cream
|
||||
// f0f0c9 = cream2
|
||||
// caffd0 = light green
|
||||
// B0F2B4 = light grean 2 *
|
||||
// 85bda6 = light green 3
|
||||
// 70f8ba = green
|
||||
// F7F3EA = white
|
||||
// a63446 = red
|
||||
//747474
|
||||
|
||||
MihTheme() {
|
||||
mode = "Dark";
|
||||
//_errColor = 0xffD87E8B;
|
||||
//_succColor = 0xffB0F2B4;
|
||||
//_mesColor = 0xffc8c8c8d9;
|
||||
}
|
||||
|
||||
ThemeData getData(bool bool) {
|
||||
return ThemeData(
|
||||
fontFamily: 'Segoe UI',
|
||||
scaffoldBackgroundColor: MihColors.getPrimaryColor(mode == "Dark"),
|
||||
// pageTransitionsTheme: PageTransitionsTheme(
|
||||
// builders: Map<TargetPlatform, PageTransitionsBuilder>.fromIterable(
|
||||
// TargetPlatform.values,
|
||||
// value: (dynamic _) => const FadeUpwardsPageTransitionsBuilder(),
|
||||
// ),
|
||||
// ),
|
||||
colorScheme: ColorScheme(
|
||||
brightness: getBritness(),
|
||||
primary: MihColors.getSecondaryColor(mode == "Dark"),
|
||||
onPrimary: MihColors.getPrimaryColor(mode == "Dark"),
|
||||
secondary: MihColors.getPrimaryColor(mode == "Dark"),
|
||||
onSecondary: MihColors.getSecondaryColor(mode == "Dark"),
|
||||
error: MihColors.getRedColor(mode == "Dark"),
|
||||
onError: MihColors.getPrimaryColor(mode == "Dark"),
|
||||
surface: MihColors.getPrimaryColor(mode == "Dark"),
|
||||
onSurface: MihColors.getSecondaryColor(mode == "Dark"),
|
||||
),
|
||||
datePickerTheme: DatePickerThemeData(
|
||||
backgroundColor: MihColors.getPrimaryColor(mode == "Dark"),
|
||||
headerBackgroundColor: MihColors.getSecondaryColor(mode == "Dark"),
|
||||
headerForegroundColor: MihColors.getPrimaryColor(mode == "Dark"),
|
||||
),
|
||||
appBarTheme: AppBarTheme(
|
||||
color: MihColors.getSecondaryColor(mode == "Dark"),
|
||||
foregroundColor: MihColors.getPrimaryColor(mode == "Dark"),
|
||||
titleTextStyle: TextStyle(
|
||||
color: MihColors.getPrimaryColor(mode == "Dark"),
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
floatingActionButtonTheme: FloatingActionButtonThemeData(
|
||||
backgroundColor: MihColors.getSecondaryColor(mode == "Dark"),
|
||||
foregroundColor: MihColors.getPrimaryColor(mode == "Dark"),
|
||||
extendedTextStyle:
|
||||
TextStyle(color: MihColors.getPrimaryColor(mode == "Dark")),
|
||||
),
|
||||
drawerTheme: DrawerThemeData(
|
||||
backgroundColor: MihColors.getPrimaryColor(mode == "Dark"),
|
||||
),
|
||||
// Text selection / cursor color
|
||||
textSelectionTheme: TextSelectionThemeData(
|
||||
cursorColor: MihColors.getPrimaryColor(mode == "Dark"),
|
||||
selectionColor:
|
||||
MihColors.getPrimaryColor(mode == "Dark").withOpacity(0.25),
|
||||
selectionHandleColor: MihColors.getPrimaryColor(mode == "Dark"),
|
||||
),
|
||||
tooltipTheme: TooltipThemeData(
|
||||
decoration: BoxDecoration(
|
||||
color: MihColors.getSecondaryColor(mode == "Dark"),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
border: Border.all(
|
||||
width: 1.0,
|
||||
color: MihColors.getPrimaryColor(mode == "Dark"),
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color:
|
||||
MihColors.getPrimaryColor(mode == "Dark").withOpacity(0.18),
|
||||
blurRadius: 6,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
textStyle: TextStyle(
|
||||
color: MihColors.getPrimaryColor(mode == "Dark"),
|
||||
fontSize: 13,
|
||||
height: 1.2,
|
||||
),
|
||||
waitDuration: const Duration(milliseconds: 500),
|
||||
showDuration: const Duration(seconds: 3),
|
||||
preferBelow: true,
|
||||
verticalOffset: 24,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
triggerMode: TooltipTriggerMode.longPress,
|
||||
),
|
||||
// // Input decoration (text fields) theme
|
||||
// inputDecorationTheme: InputDecorationTheme(
|
||||
// filled: true,
|
||||
// fillColor: mode == "Dark"
|
||||
// ? MihColors.getPrimaryColor(true).withOpacity(0.06)
|
||||
// : MihColors.getPrimaryColor(false).withOpacity(0.03),
|
||||
// contentPadding:
|
||||
// const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
// border: OutlineInputBorder(
|
||||
// borderRadius: BorderRadius.circular(8),
|
||||
// borderSide:
|
||||
// BorderSide(color: MihColors.getSecondaryColor(mode == "Dark")),
|
||||
// ),
|
||||
// enabledBorder: OutlineInputBorder(
|
||||
// borderRadius: BorderRadius.circular(8),
|
||||
// borderSide: BorderSide(
|
||||
// color:
|
||||
// MihColors.getSecondaryColor(mode == "Dark").withOpacity(0.6)),
|
||||
// ),
|
||||
// focusedBorder: OutlineInputBorder(
|
||||
// borderRadius: BorderRadius.circular(8),
|
||||
// borderSide: BorderSide(
|
||||
// color: MihColors.getSecondaryColor(mode == "Dark"), width: 2),
|
||||
// ),
|
||||
// hintStyle: TextStyle(
|
||||
// color:
|
||||
// MihColors.getSecondaryColor(mode == "Dark").withOpacity(0.7)),
|
||||
// labelStyle:
|
||||
// TextStyle(color: MihColors.getSecondaryColor(mode == "Dark")),
|
||||
// errorStyle: TextStyle(color: MihColors.getRedColor(mode == "Dark")),
|
||||
// ),
|
||||
);
|
||||
}
|
||||
|
||||
String getPlatform() {
|
||||
// if (isPwa()) {
|
||||
// if (platform == TargetPlatform.android) {
|
||||
// return "Android";
|
||||
// } else if (platform == TargetPlatform.iOS) {
|
||||
// return "iOS";
|
||||
// }
|
||||
// } else
|
||||
if (kIsWeb) {
|
||||
return "Web";
|
||||
} else if (!kIsWeb) {
|
||||
if (platform == TargetPlatform.android) {
|
||||
return "Android";
|
||||
} else if (platform == TargetPlatform.iOS) {
|
||||
return "iOS";
|
||||
}
|
||||
}
|
||||
return "Other";
|
||||
}
|
||||
|
||||
bool isPwa() {
|
||||
return html.window.matchMedia('(display-mode: standalone)').matches;
|
||||
}
|
||||
|
||||
void setMode(String m) {
|
||||
mode;
|
||||
}
|
||||
|
||||
String getLatestVersion() {
|
||||
return latestVersion;
|
||||
}
|
||||
|
||||
ThemeData getThemeData() {
|
||||
return getData(mode == "Dark");
|
||||
}
|
||||
|
||||
ThemeData darkMode() {
|
||||
return getData(mode == "Dark");
|
||||
}
|
||||
|
||||
ThemeData lightMode() {
|
||||
return getData(mode == "Dark");
|
||||
}
|
||||
|
||||
Brightness getBritness() {
|
||||
if (mode == "Dark") {
|
||||
return Brightness.dark;
|
||||
} else {
|
||||
return Brightness.light;
|
||||
}
|
||||
}
|
||||
|
||||
// Color messageTextColor() {
|
||||
// if (mode == "Dark") {
|
||||
// _mesColor = 0XFFc8c8c8;
|
||||
// } else {
|
||||
// _mesColor = 0XFF747474;
|
||||
// }
|
||||
// return Color(_mesColor);
|
||||
// }
|
||||
|
||||
// Color errorColor() {
|
||||
// if (mode == "Dark") {
|
||||
// return const Color(0xffD87E8B);
|
||||
// } else {
|
||||
// return const Color(0xffbb3d4f);
|
||||
// }
|
||||
// //return Color(_errColor);
|
||||
// }
|
||||
|
||||
// Color highlightColor() {
|
||||
// if (mode == "Dark") {
|
||||
// return const Color(0XFF9bc7fa);
|
||||
// } else {
|
||||
// return const Color(0XFF354866);
|
||||
// }
|
||||
// }
|
||||
|
||||
// Color successColor() {
|
||||
// if (mode == "Dark") {
|
||||
// return const Color(0xffB0F2B4);
|
||||
// } else {
|
||||
// return const Color(0xff56a95b);
|
||||
// }
|
||||
// }
|
||||
|
||||
// AssetImage loadingImage() {
|
||||
// if (mode == "Dark") {
|
||||
// loading = const AssetImage(
|
||||
// 'lib/mih_package_components/assets/images/loading_light.gif',
|
||||
// );
|
||||
// } else {
|
||||
// loading = const AssetImage(
|
||||
// 'lib/mih_package_components/assets/images/loading_dark.gif',
|
||||
// );
|
||||
// }
|
||||
// return loading;
|
||||
// }
|
||||
|
||||
// AssetImage altLoadingImage() {
|
||||
// if (mode == "Dark") {
|
||||
// loading = const AssetImage(
|
||||
// 'lib/mih_package_components/assets/images/loading_dark.gif',
|
||||
// );
|
||||
// } else {
|
||||
// loading = const AssetImage(
|
||||
// 'lib/mih_package_components/assets/images/loading_light.gif',
|
||||
// );
|
||||
// }
|
||||
// return loading;
|
||||
// }
|
||||
|
||||
// String loadingImageLocation() {
|
||||
// if (mode == "Dark") {
|
||||
// loadingAssetText =
|
||||
// 'lib/mih_package_components/assets/images/loading_light.gif';
|
||||
// } else {
|
||||
// loadingAssetText =
|
||||
// 'lib/mih_package_components/assets/images/loading_dark.gif';
|
||||
// }
|
||||
// return loadingAssetText;
|
||||
// }
|
||||
|
||||
// String altLoadingImageLocation() {
|
||||
// if (mode == "Dark") {
|
||||
// loadingAssetText =
|
||||
// 'lib/mih_package_components/assets/images/loading_dark.gif';
|
||||
// } else {
|
||||
// loadingAssetText =
|
||||
// 'lib/mih_package_components/assets/images/loading_light.gif';
|
||||
// }
|
||||
// return loadingAssetText;
|
||||
// }
|
||||
|
||||
// AssetImage aiLogoImage() {
|
||||
// if (mode == "Dark") {
|
||||
// return const AssetImage(
|
||||
// 'lib/mih_package_components/assets/images/mzansi_ai-dark.png',
|
||||
// );
|
||||
// } else {
|
||||
// return const AssetImage(
|
||||
// 'lib/mih_package_components/assets/images/mzansi_ai-light.png',
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
void setScreenType(double width) {
|
||||
if (width <= 800) {
|
||||
screenType = "mobile";
|
||||
} else {
|
||||
screenType = "desktop";
|
||||
}
|
||||
}
|
||||
|
||||
// Color MihColors.getPrimaryColor(mode == "Dark") {
|
||||
// if (mode == "Dark") {
|
||||
// _mainColor = 0XFF3A4454;
|
||||
// } else {
|
||||
// _mainColor = 0XFFbedcfe;
|
||||
// }
|
||||
// return Color(_mainColor);
|
||||
// }
|
||||
|
||||
// Color MihColors.getSecondaryColor(mode == "Dark") {
|
||||
// if (mode == "Dark") {
|
||||
// _secondColor = 0XFFbedcfe;
|
||||
// } else {
|
||||
// _secondColor = 0XFF3A4454;
|
||||
// }
|
||||
// return Color(_secondColor);
|
||||
// }
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_icons.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
|
||||
class MihCircleAvatar extends StatefulWidget {
|
||||
final ImageProvider<Object>? imageFile;
|
||||
final double width;
|
||||
final bool editable;
|
||||
final TextEditingController? fileNameController;
|
||||
final onChange;
|
||||
final PlatformFile? userSelectedfile;
|
||||
final Color frameColor;
|
||||
final Color? backgroundColor;
|
||||
const MihCircleAvatar({
|
||||
super.key,
|
||||
required this.imageFile,
|
||||
required this.width,
|
||||
required this.editable,
|
||||
required this.fileNameController,
|
||||
required this.userSelectedfile,
|
||||
required this.frameColor,
|
||||
required this.backgroundColor,
|
||||
required this.onChange,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MihCircleAvatar> createState() => _MihCircleAvatarState();
|
||||
}
|
||||
|
||||
class _MihCircleAvatarState extends State<MihCircleAvatar> {
|
||||
late ImageProvider<Object>? imagePreview;
|
||||
|
||||
ImageProvider<Object>? getAvatar() {
|
||||
// Color dark = const Color(0XFF3A4454);
|
||||
if (widget.imageFile == null) {
|
||||
return null;
|
||||
// if (widget.backgroundColor == dark) {
|
||||
// print("here in light icon");
|
||||
// return const AssetImage(
|
||||
// 'lib/mih_package_components/assets/images/i-dont-know-light.png');
|
||||
// } else {
|
||||
// print("here in dark icon");
|
||||
// return const AssetImage(
|
||||
// 'lib/mih_package_components/assets/images/i-dont-know-dark.png');
|
||||
// }
|
||||
} else {
|
||||
return widget.imageFile;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
setState(() {
|
||||
imagePreview = getAvatar();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
// color: Colors.white,
|
||||
alignment: Alignment.center,
|
||||
width: widget.width,
|
||||
height: widget.width,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Visibility(
|
||||
visible: imagePreview != null,
|
||||
child: Positioned(
|
||||
right: widget.width * 0.03,
|
||||
child: CircleAvatar(
|
||||
radius: widget.width / 2.2,
|
||||
backgroundColor: widget.backgroundColor,
|
||||
backgroundImage: imagePreview,
|
||||
),
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: imagePreview != null,
|
||||
child: Icon(
|
||||
size: widget.width,
|
||||
MihIcons.mihRing,
|
||||
color: widget.frameColor,
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: imagePreview == null,
|
||||
child: Icon(
|
||||
MihIcons.iDontKnow,
|
||||
size: widget.width,
|
||||
color: widget.frameColor,
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: widget.editable,
|
||||
child: Positioned(
|
||||
bottom: 0,
|
||||
right: 0,
|
||||
child: IconButton.filled(
|
||||
style: ButtonStyle(
|
||||
backgroundColor: WidgetStateProperty.all<Color>(
|
||||
MihColors.getGreenColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
),
|
||||
onPressed: () async {
|
||||
try {
|
||||
FilePickerResult? result =
|
||||
await FilePicker.platform.pickFiles(
|
||||
type: FileType.image,
|
||||
);
|
||||
// print("Here 1");
|
||||
if (MzansiInnovationHub.of(context)!.theme.getPlatform() ==
|
||||
"Web") {
|
||||
// print("Here 2");
|
||||
if (result == null) return;
|
||||
// print("Here 3");
|
||||
PlatformFile? selectedFile = result.files.first;
|
||||
setState(() {
|
||||
// print("Here 4");
|
||||
widget.onChange(selectedFile);
|
||||
// print("Here 5");
|
||||
imagePreview = MemoryImage(selectedFile.bytes!);
|
||||
});
|
||||
|
||||
setState(() {
|
||||
widget.fileNameController!.text = selectedFile.name;
|
||||
});
|
||||
} else {
|
||||
if (result != null) {
|
||||
File file = File(result.files.single.path!);
|
||||
PlatformFile? androidFile = PlatformFile(
|
||||
path: file.path,
|
||||
name: file.path.split('/').last,
|
||||
size: file.lengthSync(),
|
||||
bytes: await file.readAsBytes(), // Read file bytes
|
||||
//extension: fileExtension,
|
||||
);
|
||||
setState(() {
|
||||
widget.onChange(androidFile);
|
||||
imagePreview = FileImage(file);
|
||||
});
|
||||
|
||||
setState(() {
|
||||
widget.fileNameController!.text =
|
||||
file.path.split('/').last;
|
||||
});
|
||||
} else {
|
||||
print("here in else");
|
||||
// User canceled the picker
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print("Here Error: $e");
|
||||
}
|
||||
},
|
||||
icon: Icon(
|
||||
Icons.edit,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,248 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
|
||||
class MihDropdownField extends StatefulWidget {
|
||||
final TextEditingController controller;
|
||||
final String hintText;
|
||||
final bool requiredText;
|
||||
final List<String> dropdownOptions;
|
||||
final bool editable;
|
||||
final bool enableSearch;
|
||||
final FormFieldValidator<String>? validator;
|
||||
final Function(String?)? onSelected;
|
||||
|
||||
const MihDropdownField({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.hintText,
|
||||
required this.dropdownOptions,
|
||||
required this.requiredText,
|
||||
required this.editable,
|
||||
required this.enableSearch,
|
||||
this.validator,
|
||||
this.onSelected,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MihDropdownField> createState() => _MihDropdownFieldState();
|
||||
}
|
||||
|
||||
class _MihDropdownFieldState extends State<MihDropdownField> {
|
||||
late List<DropdownMenuEntry<String>> menu;
|
||||
|
||||
List<DropdownMenuEntry<String>> buildMenuOptions(List<String> options) {
|
||||
List<DropdownMenuEntry<String>> menuList = [];
|
||||
for (final i in options) {
|
||||
menuList.add(DropdownMenuEntry(
|
||||
value: i,
|
||||
label: i,
|
||||
style: ButtonStyle(
|
||||
foregroundColor: WidgetStatePropertyAll(MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark")),
|
||||
),
|
||||
));
|
||||
}
|
||||
return menuList;
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
menu = buildMenuOptions(widget.dropdownOptions);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
menu = widget.dropdownOptions
|
||||
.map((e) => DropdownMenuEntry(value: e, label: e))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
widget.hintText,
|
||||
style: TextStyle(
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
if (!widget.requiredText)
|
||||
Text(
|
||||
"(Optional)",
|
||||
style: TextStyle(
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
FormField<String>(
|
||||
validator: widget.validator,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
initialValue: widget.controller.text,
|
||||
builder: (field) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Theme(
|
||||
data: Theme.of(context).copyWith(
|
||||
textSelectionTheme: TextSelectionThemeData(
|
||||
cursorColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
selectionColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark")
|
||||
.withValues(alpha: 0.3),
|
||||
selectionHandleColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
),
|
||||
child: DropdownMenu(
|
||||
controller: widget.controller,
|
||||
dropdownMenuEntries: menu,
|
||||
enableSearch: widget.enableSearch,
|
||||
enableFilter: widget.enableSearch,
|
||||
enabled: widget.editable,
|
||||
textInputAction: widget.enableSearch
|
||||
? TextInputAction.search
|
||||
: TextInputAction.none,
|
||||
requestFocusOnTap: widget.enableSearch,
|
||||
menuHeight: 400,
|
||||
expandedInsets: EdgeInsets.zero,
|
||||
textStyle: TextStyle(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
trailingIcon: Icon(
|
||||
Icons.arrow_drop_down,
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
selectedTrailingIcon: Icon(
|
||||
Icons.arrow_drop_up,
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
leadingIcon: IconButton(
|
||||
onPressed: () {
|
||||
widget.controller.clear();
|
||||
field.didChange('');
|
||||
},
|
||||
icon: Icon(
|
||||
Icons.delete_outline_rounded,
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
),
|
||||
onSelected: (String? selectedValue) {
|
||||
field.didChange(selectedValue);
|
||||
widget.onSelected?.call(selectedValue);
|
||||
},
|
||||
menuStyle: MenuStyle(
|
||||
backgroundColor: WidgetStatePropertyAll(
|
||||
MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark")),
|
||||
side: WidgetStatePropertyAll(
|
||||
BorderSide(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
width: 1.0),
|
||||
),
|
||||
shape: WidgetStatePropertyAll(
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(
|
||||
10), // Increase for more roundness
|
||||
),
|
||||
),
|
||||
),
|
||||
inputDecorationTheme: InputDecorationTheme(
|
||||
errorStyle: const TextStyle(height: 0, fontSize: 0),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 10.0, vertical: 8.0),
|
||||
filled: true,
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
borderSide: BorderSide(
|
||||
color: field.hasError
|
||||
? MihColors.getRedColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark")
|
||||
: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
width: 3.0,
|
||||
),
|
||||
),
|
||||
errorBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
borderSide: BorderSide(
|
||||
color: MihColors.getRedColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
width: 3.0,
|
||||
),
|
||||
),
|
||||
focusedErrorBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
borderSide: BorderSide(
|
||||
color: MihColors.getRedColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
width: 3.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (field.hasError)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0, top: 4.0),
|
||||
child: Text(
|
||||
field.errorText ?? '',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: MihColors.getRedColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,287 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_single_child_scroll.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_button.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_tool_body.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_icons.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class MihAttributes extends StatefulWidget {
|
||||
const MihAttributes({super.key});
|
||||
|
||||
@override
|
||||
State<MihAttributes> createState() => _MihAttributesState();
|
||||
}
|
||||
|
||||
class _MihAttributesState extends State<MihAttributes> {
|
||||
Future<void> launchUrlLink(Uri linkUrl) async {
|
||||
if (!await launchUrl(linkUrl)) {
|
||||
throw Exception('Could not launch $linkUrl');
|
||||
}
|
||||
}
|
||||
|
||||
TableRow displayIcon(IconData icon, String creator, String link) {
|
||||
return TableRow(
|
||||
children: [
|
||||
TableCell(
|
||||
verticalAlignment: TableCellVerticalAlignment.middle,
|
||||
child: SizedBox(
|
||||
height: 150,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 15.0),
|
||||
child: FittedBox(
|
||||
child: Center(
|
||||
child: Icon(
|
||||
icon,
|
||||
// size: 125,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
TableCell(
|
||||
verticalAlignment: TableCellVerticalAlignment.middle,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(15.0),
|
||||
child: Center(
|
||||
child: Text(
|
||||
creator,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
TableCell(
|
||||
verticalAlignment: TableCellVerticalAlignment.middle,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 15.0),
|
||||
child: MihButton(
|
||||
onPressed: () {
|
||||
launchUrlLink(
|
||||
Uri.parse(
|
||||
link,
|
||||
),
|
||||
);
|
||||
},
|
||||
buttonColor: MihColors.getGreenColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
width: 100,
|
||||
child: Text(
|
||||
"Visit",
|
||||
style: TextStyle(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MihPackageToolBody(
|
||||
borderOn: false,
|
||||
innerHorizontalPadding: 10,
|
||||
bodyItem: getBody(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget getBody() {
|
||||
String message =
|
||||
"Some APIs, Icons and Assets used in MIH were sourced from third party providers.\n";
|
||||
message +=
|
||||
"We are grateful to the talented creators for providing these resources.\n";
|
||||
message +=
|
||||
"As per the terms for free use for these third party providers, the following assets require attribution";
|
||||
|
||||
return MihSingleChildScroll(
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(
|
||||
MihIcons.mihLogo,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
size: 165,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
SelectableText(
|
||||
message,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
SizedBox(
|
||||
width: 700,
|
||||
child: Table(
|
||||
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
|
||||
columnWidths: const {
|
||||
0: FlexColumnWidth(1),
|
||||
1: FlexColumnWidth(1),
|
||||
2: FlexColumnWidth(1),
|
||||
},
|
||||
children: [
|
||||
const TableRow(
|
||||
children: [
|
||||
TableCell(
|
||||
verticalAlignment: TableCellVerticalAlignment.middle,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 15.0),
|
||||
child: Center(
|
||||
child: Text(
|
||||
"Resources",
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
TableCell(
|
||||
verticalAlignment: TableCellVerticalAlignment.middle,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 15.0),
|
||||
child: Center(
|
||||
child: Text(
|
||||
"Creator",
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
TableCell(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 15.0),
|
||||
child: Center(
|
||||
child: Text(
|
||||
"Link",
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
displayIcon(MihIcons.mihRing, "Tarah Meth",
|
||||
"https://www.linkedin.com/in/tarah-meth-3b6309254/"),
|
||||
displayIcon(MihIcons.mihLogo, "Tarah Meth",
|
||||
"https://www.linkedin.com/in/tarah-meth-3b6309254/"),
|
||||
displayIcon(MihIcons.mzansiAi, "Ollama", "https://ollama.com/"),
|
||||
displayIcon(MihIcons.mzansiWallet, "Freepik",
|
||||
"https://www.flaticon.com/free-icon/wallet-passes-app_3884407?term=wallet&page=1&position=21&origin=search&related_id=3884407"),
|
||||
displayIcon(MihIcons.patientProfile, "RaftelDesign",
|
||||
"https://www.flaticon.com/free-icon/patient_2376100?term=medication&page=1&position=6&origin=search&related_id=2376100"),
|
||||
displayIcon(MihIcons.patientProfile, "Srip",
|
||||
"https://www.flaticon.com/free-icon/hospital_1233930?term=medical+snake&page=1&position=7&origin=search&related_id=1233930"),
|
||||
displayIcon(MihIcons.calendar, "Freepik",
|
||||
"https://www.flaticon.com/free-icon/calendar_2278049?term=calendar&page=1&position=5&origin=search&related_id=2278049"),
|
||||
displayIcon(MihIcons.calculator, "Freepik",
|
||||
"https://www.flaticon.com/free-icon/calculator_2374409?term=calculator&page=1&position=20&origin=search&related_id=2374409"),
|
||||
displayIcon(MihIcons.aboutMih, "Chanut",
|
||||
"https://www.flaticon.com/free-icon/info_151776?term=about&page=1&position=8&origin=search&related_id=151776"),
|
||||
displayIcon(MihIcons.personalProfile, "Freepik",
|
||||
"https://www.flaticon.com/free-icon/user_1077063?term=profile&page=1&position=6&origin=search&related_id=1077063"),
|
||||
displayIcon(MihIcons.businessProfile, "Gravisio",
|
||||
"https://www.flaticon.com/free-icon/contractor_11813336?term=company+profile&page=1&position=2&origin=search&related_id=11813336"),
|
||||
displayIcon(MihIcons.patientManager, "Vector Tank",
|
||||
"https://www.flaticon.com/free-icon/doctor_10215061?term=doctor&page=1&position=73&origin=search&related_id=10215061"),
|
||||
displayIcon(MihIcons.profileSetup, "Freepik",
|
||||
"https://www.flaticon.com/free-icon/add-user_748137?term=profile+add&page=1&position=1&origin=search&related_id=748137"),
|
||||
displayIcon(MihIcons.businessSetup, "kerismaker",
|
||||
"https://www.flaticon.com/free-icon/business_13569850?term=company+add&page=1&position=25&origin=search&related_id=13569850"),
|
||||
displayIcon(MihIcons.calculator, "fawazahmed0",
|
||||
"https://github.com/fawazahmed0/exchange-api"),
|
||||
displayIcon(MihIcons.iDontKnow, "Freepik",
|
||||
"https://www.flaticon.com/free-icon/i-dont-know_5359909?term=i+dont+know&page=1&position=7&origin=search&related_id=5359909"),
|
||||
],
|
||||
),
|
||||
),
|
||||
// SizedBox(
|
||||
// width: 500,
|
||||
// child: Column(
|
||||
// children: [
|
||||
// const SizedBox(
|
||||
// width: double.infinity,
|
||||
// child: Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
// mainAxisSize: MainAxisSize.max,
|
||||
// children: [
|
||||
// Flexible(
|
||||
// child: Text(
|
||||
// "Icon",
|
||||
// style: TextStyle(
|
||||
// fontSize: 25,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// Flexible(
|
||||
// child: Text(
|
||||
// "Creator",
|
||||
// style: TextStyle(
|
||||
// fontSize: 25,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// Flexible(
|
||||
// child: Text(
|
||||
// "Link",
|
||||
// style: TextStyle(
|
||||
// fontSize: 25,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// const Padding(
|
||||
// padding: EdgeInsets.symmetric(vertical: 10.0),
|
||||
// child: Divider(),
|
||||
// ),
|
||||
// displayIcon(MihIcons.mihLogo, "Tarah Meth",
|
||||
// "https://app.mzansi-innovation-hub.co.za/"),
|
||||
// const SizedBox(height: 10),
|
||||
// displayIcon(MihIcons.mihLogo, "Test",
|
||||
// "https://www.flaticon.com/free-icons/mih"),
|
||||
// const SizedBox(height: 10),
|
||||
// displayIcon(MihIcons.mihLogo, "Test",
|
||||
// "https://www.flaticon.com/free-icons/mih"),
|
||||
// const SizedBox(height: 10),
|
||||
// displayIcon(MihIcons.mihLogo, "Test",
|
||||
// "https://www.flaticon.com/free-icons/mih"),
|
||||
// const SizedBox(height: 10),
|
||||
// ],
|
||||
// ),
|
||||
// )
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_circle_avatar.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mih_mine_sweeper_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class BuildMinesweeperLeaderboardList extends StatefulWidget {
|
||||
const BuildMinesweeperLeaderboardList({super.key});
|
||||
|
||||
@override
|
||||
State<BuildMinesweeperLeaderboardList> createState() =>
|
||||
_BuildMinesweeperLeaderboardListState();
|
||||
}
|
||||
|
||||
class _BuildMinesweeperLeaderboardListState
|
||||
extends State<BuildMinesweeperLeaderboardList> {
|
||||
Color getMedalColor(int index) {
|
||||
switch (index) {
|
||||
case (0):
|
||||
return MihColors.getGoldColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
|
||||
case (1):
|
||||
return MihColors.getSilverColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
|
||||
case (2):
|
||||
return MihColors.getBronze(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
|
||||
default:
|
||||
return MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double width = MediaQuery.sizeOf(context).width;
|
||||
return Consumer2<MzansiProfileProvider, MihMineSweeperProvider>(
|
||||
builder: (BuildContext context, MzansiProfileProvider profileProvider,
|
||||
MihMineSweeperProvider mineSweeperProvider, Widget? child) {
|
||||
return ListView.separated(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
separatorBuilder: (BuildContext context, index) {
|
||||
return Divider(
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
);
|
||||
},
|
||||
itemCount: mineSweeperProvider.leaderboard!.length,
|
||||
itemBuilder: (context, index) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: width / 20),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
"#${index + 1}",
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
color: getMedalColor(index),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
MihCircleAvatar(
|
||||
key: UniqueKey(),
|
||||
imageFile:
|
||||
mineSweeperProvider.leaderboardUserPictures.isNotEmpty
|
||||
? mineSweeperProvider.leaderboardUserPictures[index]
|
||||
: null,
|
||||
width: 80,
|
||||
editable: false,
|
||||
fileNameController: null,
|
||||
userSelectedfile: null,
|
||||
frameColor: getMedalColor(index),
|
||||
backgroundColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
onChange: () {},
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"${mineSweeperProvider.leaderboard![index].username}${profileProvider.user!.username == mineSweeperProvider.leaderboard![index].username ? " (You)" : ""}",
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: getMedalColor(index),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
"Score: ${mineSweeperProvider.leaderboard![index].game_score}\nTime: ${mineSweeperProvider.leaderboard![index].game_time}",
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
// fontWeight: FontWeight.bold,
|
||||
color: getMedalColor(index),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,204 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_dropdwn_field.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_icons.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_tool_body.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_loading_circle.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mih_mine_sweeper_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mine_sweeper/builders/build_minesweeper_leaderboard_list.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_minesweeper_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class MihMineSweeperLeaderBoard extends StatefulWidget {
|
||||
const MihMineSweeperLeaderBoard({super.key});
|
||||
|
||||
@override
|
||||
State<MihMineSweeperLeaderBoard> createState() =>
|
||||
_MihMineSweeperLeaderBoardState();
|
||||
}
|
||||
|
||||
class _MihMineSweeperLeaderBoardState extends State<MihMineSweeperLeaderBoard> {
|
||||
TextEditingController filterController = TextEditingController();
|
||||
bool isLoading = true;
|
||||
Future<void> initialiseLeaderboard() async {
|
||||
MihMineSweeperProvider mineSweeperProvider =
|
||||
context.read<MihMineSweeperProvider>();
|
||||
filterController.text = mineSweeperProvider.difficulty;
|
||||
KenLogger.success("getting data");
|
||||
await MihMinesweeperServices().getTop20Leaderboard(mineSweeperProvider);
|
||||
List<ImageProvider<Object>?> userPictures = [];
|
||||
String userPicUrl = "";
|
||||
for (final ranking in mineSweeperProvider.leaderboard!) {
|
||||
userPicUrl = await MihFileApi.getMinioFileUrl(ranking.proPicUrl);
|
||||
userPictures.add(NetworkImage(userPicUrl));
|
||||
}
|
||||
mineSweeperProvider.setLeaderboardUserPictures(
|
||||
leaderboardUserPictures: userPictures);
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
|
||||
void refreshLeaderBoard(
|
||||
MihMineSweeperProvider mineSweeperProvider, String difficulty) {
|
||||
setState(() {
|
||||
isLoading = true;
|
||||
});
|
||||
mineSweeperProvider.setDifficulty(difficulty);
|
||||
mineSweeperProvider.setLeaderboard(leaderboard: null);
|
||||
mineSweeperProvider.setMyScoreboard(myScoreboard: null);
|
||||
initialiseLeaderboard();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
await initialiseLeaderboard();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double width = MediaQuery.sizeOf(context).width;
|
||||
return Consumer<MihMineSweeperProvider>(
|
||||
builder: (BuildContext context,
|
||||
MihMineSweeperProvider mineSweeperProvider, Widget? child) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
refreshLeaderBoard(mineSweeperProvider, filterController.text);
|
||||
},
|
||||
child: MihPackageToolBody(
|
||||
borderOn: false,
|
||||
bodyItem: getBody(width),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget getBody(double width) {
|
||||
return Consumer<MihMineSweeperProvider>(
|
||||
builder: (BuildContext context,
|
||||
MihMineSweeperProvider mineSweeperProvider, Widget? child) {
|
||||
if (isLoading) {
|
||||
return Center(
|
||||
child: Mihloadingcircle(),
|
||||
);
|
||||
} else {
|
||||
return SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: width / 20),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Flexible(
|
||||
child: MihDropdownField(
|
||||
controller: filterController,
|
||||
hintText: "Leaderboards",
|
||||
dropdownOptions: const [
|
||||
"Very Easy",
|
||||
"Easy",
|
||||
"Intermediate",
|
||||
"Hard",
|
||||
],
|
||||
requiredText: true,
|
||||
editable: true,
|
||||
enableSearch: false,
|
||||
validator: (value) {
|
||||
return MihValidationServices().isEmpty(value);
|
||||
},
|
||||
onSelected: (selection) {
|
||||
refreshLeaderBoard(mineSweeperProvider, selection!);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
!isLoading && mineSweeperProvider.leaderboard!.isEmpty
|
||||
? Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(height: 50),
|
||||
Icon(
|
||||
MihIcons.mineSweeper,
|
||||
size: 165,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
"Be the first on the leaderboard.",
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.visible,
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!
|
||||
.theme
|
||||
.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
Center(
|
||||
child: RichText(
|
||||
textAlign: TextAlign.center,
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.normal,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!
|
||||
.theme
|
||||
.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
children: [
|
||||
TextSpan(text: "Press "),
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: Icon(
|
||||
FontAwesomeIcons.bomb,
|
||||
size: 20,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!
|
||||
.theme
|
||||
.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
),
|
||||
TextSpan(text: " and start a new game"),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: BuildMinesweeperLeaderboardList(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,209 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_circle_avatar.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_dropdwn_field.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_icons.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_tool_body.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_loading_circle.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mih_mine_sweeper_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mine_sweeper/builders/build_my_scoreboard_list.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_minesweeper_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class MyScoreBoard extends StatefulWidget {
|
||||
const MyScoreBoard({super.key});
|
||||
|
||||
@override
|
||||
State<MyScoreBoard> createState() => _MihMineSweeperLeaderBoardState();
|
||||
}
|
||||
|
||||
class _MihMineSweeperLeaderBoardState extends State<MyScoreBoard> {
|
||||
TextEditingController filterController = TextEditingController();
|
||||
|
||||
Future<void> initialiseLeaderboard() async {
|
||||
MzansiProfileProvider profileProvider =
|
||||
context.read<MzansiProfileProvider>();
|
||||
MihMineSweeperProvider mineSweeperProvider =
|
||||
context.read<MihMineSweeperProvider>();
|
||||
filterController.text = mineSweeperProvider.difficulty;
|
||||
KenLogger.success("getting data");
|
||||
await MihMinesweeperServices()
|
||||
.getMyScoreboard(profileProvider, mineSweeperProvider);
|
||||
KenLogger.success("${mineSweeperProvider.myScoreboard}");
|
||||
}
|
||||
|
||||
void refreshLeaderBoard(
|
||||
MihMineSweeperProvider mineSweeperProvider, String difficulty) {
|
||||
mineSweeperProvider.setDifficulty(difficulty);
|
||||
mineSweeperProvider.setLeaderboard(leaderboard: null);
|
||||
mineSweeperProvider.setMyScoreboard(myScoreboard: null);
|
||||
initialiseLeaderboard();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
await initialiseLeaderboard();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double width = MediaQuery.sizeOf(context).width;
|
||||
return Consumer<MihMineSweeperProvider>(
|
||||
builder: (BuildContext context,
|
||||
MihMineSweeperProvider mineSweeperProvider, Widget? child) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
refreshLeaderBoard(mineSweeperProvider, filterController.text);
|
||||
},
|
||||
child: MihPackageToolBody(
|
||||
borderOn: false,
|
||||
bodyItem: getBody(width),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget getBody(double width) {
|
||||
return Consumer2<MzansiProfileProvider, MihMineSweeperProvider>(
|
||||
builder: (BuildContext context, MzansiProfileProvider profileProvider,
|
||||
MihMineSweeperProvider mineSweeperProvider, Widget? child) {
|
||||
if (mineSweeperProvider.myScoreboard == null) {
|
||||
return Center(
|
||||
child: Mihloadingcircle(),
|
||||
);
|
||||
} else {
|
||||
return SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
child: Column(
|
||||
children: [
|
||||
Center(
|
||||
child: MihCircleAvatar(
|
||||
imageFile: profileProvider.userProfilePicture,
|
||||
width: 150,
|
||||
editable: false,
|
||||
fileNameController: null,
|
||||
userSelectedfile: null,
|
||||
frameColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
backgroundColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
onChange: (selectedImage) {},
|
||||
key: ValueKey(profileProvider.userProfilePicUrl),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: width / 20),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Flexible(
|
||||
child: MihDropdownField(
|
||||
controller: filterController,
|
||||
hintText: "Scoreboards",
|
||||
dropdownOptions: const [
|
||||
"Very Easy",
|
||||
"Easy",
|
||||
"Intermediate",
|
||||
"Hard",
|
||||
],
|
||||
requiredText: true,
|
||||
editable: true,
|
||||
enableSearch: false,
|
||||
validator: (value) {
|
||||
return MihValidationServices().isEmpty(value);
|
||||
},
|
||||
onSelected: (selection) {
|
||||
refreshLeaderBoard(mineSweeperProvider, selection!);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
mineSweeperProvider.myScoreboard!.isEmpty
|
||||
? Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(height: 50),
|
||||
Icon(
|
||||
MihIcons.mineSweeper,
|
||||
size: 165,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
"You have played and ${mineSweeperProvider.difficulty} yet.",
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.visible,
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!
|
||||
.theme
|
||||
.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
Center(
|
||||
child: RichText(
|
||||
textAlign: TextAlign.center,
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.normal,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!
|
||||
.theme
|
||||
.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
children: [
|
||||
TextSpan(text: "Press "),
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: Icon(
|
||||
FontAwesomeIcons.bomb,
|
||||
size: 20,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!
|
||||
.theme
|
||||
.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
),
|
||||
TextSpan(text: " and start a new game"),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: BuildMyScoreBoardList(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,556 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_button.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_dropdwn_field.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_icons.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_tool_body.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_search_bar.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_single_child_scroll.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_loading_circle.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_directory_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mzansi_directory/builders/build_business_search_resultsList.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mzansi_directory/builders/build_user_search_results_list.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_business_details_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_user_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class MihSearchMzansi extends StatefulWidget {
|
||||
const MihSearchMzansi({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MihSearchMzansi> createState() => _MihSearchMzansiState();
|
||||
}
|
||||
|
||||
class _MihSearchMzansiState extends State<MihSearchMzansi> {
|
||||
final TextEditingController mzansiSearchController = TextEditingController();
|
||||
final TextEditingController businessTypeController = TextEditingController();
|
||||
final FocusNode searchFocusNode = FocusNode();
|
||||
// late bool userSearch;
|
||||
// Future<List<AppUser>?> futureUserSearchResults = Future.value();
|
||||
List<AppUser> userSearchResults = [];
|
||||
List<Business> businessSearchResults = [];
|
||||
late Future<List<String>> availableBusinessTypes;
|
||||
bool filterOn = false;
|
||||
bool loadingSearchResults = false;
|
||||
|
||||
Future<void> swapPressed(MzansiProfileProvider profileProvider,
|
||||
MzansiDirectoryProvider directoryProvider) async {
|
||||
directoryProvider.setPersonalSearch(!directoryProvider.personalSearch);
|
||||
setState(() {
|
||||
if (filterOn) {
|
||||
filterOn = !filterOn;
|
||||
}
|
||||
});
|
||||
if (businessTypeController.text.isNotEmpty) {
|
||||
setState(() {
|
||||
businessTypeController.clear();
|
||||
});
|
||||
}
|
||||
await searchPressed(profileProvider, directoryProvider);
|
||||
}
|
||||
|
||||
void clearAll(MzansiDirectoryProvider directoryProvider) {
|
||||
directoryProvider.setSearchedBusinesses(searchedBusinesses: []);
|
||||
directoryProvider.setSearchedUsers(searchedUsers: []);
|
||||
directoryProvider.setSearchTerm(searchTerm: "");
|
||||
setState(() {
|
||||
mzansiSearchController.clear();
|
||||
businessTypeController.clear();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> searchPressed(MzansiProfileProvider profileProvider,
|
||||
MzansiDirectoryProvider directoryProvider) async {
|
||||
setState(() {
|
||||
loadingSearchResults = true;
|
||||
});
|
||||
directoryProvider.setSearchTerm(searchTerm: mzansiSearchController.text);
|
||||
directoryProvider.setBusinessTypeFilter(
|
||||
businessTypeFilter: businessTypeController.text);
|
||||
if (directoryProvider.personalSearch &&
|
||||
directoryProvider.searchTerm.isNotEmpty) {
|
||||
final userResults = await MihUserServices()
|
||||
.searchUsers(profileProvider, directoryProvider.searchTerm, context);
|
||||
directoryProvider.setSearchedUsers(searchedUsers: userResults);
|
||||
} else {
|
||||
List<Business>? businessSearchResults = [];
|
||||
if (directoryProvider.businessTypeFilter.isNotEmpty) {
|
||||
businessSearchResults = await MihBusinessDetailsServices()
|
||||
.searchBusinesses(directoryProvider.searchTerm,
|
||||
directoryProvider.businessTypeFilter, context);
|
||||
} else if (directoryProvider.searchTerm.isNotEmpty) {
|
||||
businessSearchResults = await MihBusinessDetailsServices()
|
||||
.searchBusinesses(directoryProvider.searchTerm,
|
||||
directoryProvider.businessTypeFilter, context);
|
||||
}
|
||||
directoryProvider.setSearchedBusinesses(
|
||||
searchedBusinesses: businessSearchResults);
|
||||
}
|
||||
setState(() {
|
||||
loadingSearchResults = false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
businessTypeController.dispose();
|
||||
mzansiSearchController.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
MzansiDirectoryProvider directoryProvider =
|
||||
context.read<MzansiDirectoryProvider>();
|
||||
availableBusinessTypes =
|
||||
MihBusinessDetailsServices().fetchAllBusinessTypes();
|
||||
mzansiSearchController.text = "";
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
directoryProvider.setSearchedUsers(searchedUsers: []);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Size size = MediaQuery.sizeOf(context);
|
||||
final double width = size.width;
|
||||
return MihPackageToolBody(
|
||||
borderOn: false,
|
||||
bodyItem: getBody(width),
|
||||
);
|
||||
}
|
||||
|
||||
Widget getBody(double width) {
|
||||
return Consumer2<MzansiProfileProvider, MzansiDirectoryProvider>(
|
||||
builder: (BuildContext context, MzansiProfileProvider profileProvider,
|
||||
MzansiDirectoryProvider directoryProvider, Widget? child) {
|
||||
return MihSingleChildScroll(
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: width / 20),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: MihSearchBar(
|
||||
controller: mzansiSearchController,
|
||||
hintText: "Search Mzansi",
|
||||
prefixIcon: Icons.search,
|
||||
prefixAltIcon: directoryProvider.personalSearch
|
||||
? Icons.person
|
||||
: Icons.business,
|
||||
suffixTools: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
swapPressed(profileProvider, directoryProvider);
|
||||
},
|
||||
icon: Icon(
|
||||
Icons.swap_horiz_rounded,
|
||||
size: 35,
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
),
|
||||
],
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
hintColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
onPrefixIconTap: () {
|
||||
searchPressed(profileProvider, directoryProvider);
|
||||
},
|
||||
onClearIconTap: () {
|
||||
clearAll(directoryProvider);
|
||||
},
|
||||
searchFocusNode: searchFocusNode,
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: !directoryProvider.personalSearch,
|
||||
child: const SizedBox(width: 10),
|
||||
),
|
||||
Visibility(
|
||||
visible: !directoryProvider.personalSearch,
|
||||
child: IconButton(
|
||||
onPressed: () {
|
||||
if (filterOn) {
|
||||
clearAll(directoryProvider);
|
||||
}
|
||||
setState(() {
|
||||
filterOn = !filterOn;
|
||||
});
|
||||
},
|
||||
icon: Icon(
|
||||
!filterOn
|
||||
? Icons.filter_list_rounded
|
||||
: Icons.filter_list_off_rounded,
|
||||
size: 35,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
FutureBuilder(
|
||||
future: availableBusinessTypes,
|
||||
builder: (context, asyncSnapshot) {
|
||||
List<String> options = [];
|
||||
if (asyncSnapshot.connectionState == ConnectionState.done) {
|
||||
options.addAll(asyncSnapshot.data!);
|
||||
}
|
||||
return Visibility(
|
||||
visible: filterOn,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: width / 20),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Expanded(
|
||||
child: MihDropdownField(
|
||||
controller: businessTypeController,
|
||||
hintText: "Business Type",
|
||||
dropdownOptions: options,
|
||||
requiredText: true,
|
||||
editable: true,
|
||||
enableSearch: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
MihButton(
|
||||
onPressed: () {
|
||||
if (businessTypeController.text.isNotEmpty) {
|
||||
searchPressed(
|
||||
profileProvider, directoryProvider);
|
||||
} else {
|
||||
MihAlertServices().errorBasicAlert(
|
||||
"Business Type Not Selected",
|
||||
"Please ensure you have selected a Business Type before seareching for Businesses of Mzansi",
|
||||
context,
|
||||
);
|
||||
}
|
||||
},
|
||||
buttonColor: MihColors.getGreenColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
elevation: 10,
|
||||
child: Text(
|
||||
"Search",
|
||||
style: TextStyle(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!
|
||||
.theme
|
||||
.mode ==
|
||||
"Dark"),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
const SizedBox(height: 10),
|
||||
displaySearchResults(directoryProvider),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget displayBusinessSearchResults(
|
||||
MzansiDirectoryProvider directoryProvider) {
|
||||
KenLogger.success(
|
||||
"Searched Businesses: ${directoryProvider.searchedBusinesses}");
|
||||
if (directoryProvider.searchedBusinesses == null || loadingSearchResults) {
|
||||
return Center(
|
||||
child: const Mihloadingcircle(),
|
||||
);
|
||||
} else if (directoryProvider.searchedBusinesses!.isNotEmpty) {
|
||||
// return Text("Pulled Data successfully");
|
||||
directoryProvider.searchedBusinesses!
|
||||
.sort((a, b) => a.Name.compareTo(b.Name));
|
||||
return Column(
|
||||
children: [
|
||||
Text(
|
||||
"Businesses of Mzansi",
|
||||
style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
BuildBusinessSearchResultsList(
|
||||
businessList: directoryProvider.searchedBusinesses!,
|
||||
),
|
||||
],
|
||||
);
|
||||
} else if (directoryProvider.searchedBusinesses!.isEmpty &&
|
||||
directoryProvider.searchTerm.isNotEmpty) {
|
||||
// return Text("Pulled Data successfully");
|
||||
return Column(
|
||||
children: [
|
||||
const SizedBox(height: 50),
|
||||
Icon(
|
||||
MihIcons.iDontKnow,
|
||||
size: 165,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
Text(
|
||||
"Let's try refining your search",
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.visible,
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else if (directoryProvider.searchedBusinesses!.isEmpty &&
|
||||
directoryProvider.searchTerm.isEmpty) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(height: 50),
|
||||
Icon(
|
||||
MihIcons.businessProfile,
|
||||
size: 165,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
"Search for businesses of Mzansi!",
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.visible,
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
Center(
|
||||
child: RichText(
|
||||
textAlign: TextAlign.center,
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.normal,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
children: [
|
||||
TextSpan(text: "Press "),
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: Icon(
|
||||
Icons.swap_horiz_rounded,
|
||||
size: 20,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
),
|
||||
TextSpan(text: " to search for people of Mzansi"),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Center(
|
||||
child: RichText(
|
||||
textAlign: TextAlign.center,
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.normal,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
children: [
|
||||
TextSpan(text: "Press "),
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: Icon(
|
||||
Icons.filter_list_rounded,
|
||||
size: 20,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
),
|
||||
TextSpan(text: " to filter business types"),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Center(
|
||||
child: Text(
|
||||
"Error pulling Patients Data\n/users/search/${directoryProvider.searchTerm}",
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
color: MihColors.getRedColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark")),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget displayPersonalSearchResults(
|
||||
MzansiDirectoryProvider directoryProvider) {
|
||||
if (directoryProvider.searchedUsers == null || loadingSearchResults) {
|
||||
return Center(
|
||||
child: const Mihloadingcircle(),
|
||||
);
|
||||
} else if (directoryProvider.searchedUsers!.isNotEmpty) {
|
||||
// return Text("Pulled Data successfully");
|
||||
directoryProvider.searchedUsers!
|
||||
.sort((a, b) => a.username.compareTo(b.username));
|
||||
return Column(
|
||||
children: [
|
||||
Text(
|
||||
"People of Mzansi",
|
||||
style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
BuildUserSearchResultsList(
|
||||
userList: directoryProvider.searchedUsers!),
|
||||
],
|
||||
);
|
||||
} else if (directoryProvider.searchedUsers!.isEmpty &&
|
||||
directoryProvider.searchTerm.isEmpty) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(height: 50),
|
||||
Icon(
|
||||
MihIcons.personalProfile,
|
||||
size: 165,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
"Search for people of Mzansi!",
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.visible,
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
Center(
|
||||
child: RichText(
|
||||
textAlign: TextAlign.center,
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.normal,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
children: [
|
||||
TextSpan(text: "Press "),
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: Icon(
|
||||
Icons.swap_horiz_rounded,
|
||||
size: 20,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
),
|
||||
TextSpan(text: " to search for businesses of Mzansi"),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else if (directoryProvider.searchedUsers!.isEmpty &&
|
||||
directoryProvider.searchTerm.isNotEmpty) {
|
||||
return Column(
|
||||
children: [
|
||||
const SizedBox(height: 50),
|
||||
Icon(
|
||||
MihIcons.iDontKnow,
|
||||
size: 165,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
"Let's try refining your search",
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.visible,
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return Center(
|
||||
child: Text(
|
||||
"Error pulling Patients Data\n/users/search/${directoryProvider.searchTerm}",
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
color: MihColors.getRedColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark")),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget displaySearchResults(MzansiDirectoryProvider directoryProvider) {
|
||||
if (directoryProvider.personalSearch) {
|
||||
return displayPersonalSearchResults(directoryProvider);
|
||||
} else {
|
||||
return displayBusinessSearchResults(directoryProvider);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,620 +0,0 @@
|
||||
import 'package:country_code_picker/country_code_picker.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_button.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_circle_avatar.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_form.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_window.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_single_child_scroll.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_text_form_field.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_loading_circle.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_business_details_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_location_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class MihUpdateBusinessDetailsWindow extends StatefulWidget {
|
||||
final double width;
|
||||
const MihUpdateBusinessDetailsWindow({
|
||||
super.key,
|
||||
required this.width,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MihUpdateBusinessDetailsWindow> createState() =>
|
||||
_MihUpdateBusinessDetailsWindowState();
|
||||
}
|
||||
|
||||
class _MihUpdateBusinessDetailsWindowState
|
||||
extends State<MihUpdateBusinessDetailsWindow> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
PlatformFile? newSelectedLogoPic;
|
||||
final fileNameController = TextEditingController();
|
||||
final regController = TextEditingController();
|
||||
final nameController = TextEditingController();
|
||||
final typeController = TextEditingController();
|
||||
final practiceNoController = TextEditingController();
|
||||
final vatNoController = TextEditingController();
|
||||
final countryCodeController = TextEditingController();
|
||||
final contactController = TextEditingController();
|
||||
final emailController = TextEditingController();
|
||||
final locationController = TextEditingController();
|
||||
final websiteController = TextEditingController();
|
||||
final ratingController = TextEditingController();
|
||||
final missionVisionController = TextEditingController();
|
||||
final ValueNotifier<int> _counter = ValueNotifier<int>(0);
|
||||
late String env;
|
||||
|
||||
void setContactNumberControllers(
|
||||
MzansiProfileProvider mzansiProfileProvider) {
|
||||
if (mzansiProfileProvider.business!.contact_no[0] == "+") {
|
||||
List<String> contactDetails =
|
||||
mzansiProfileProvider.business!.contact_no.split("-");
|
||||
setState(() {
|
||||
countryCodeController.text = contactDetails[0];
|
||||
contactController.text = contactDetails[1];
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
countryCodeController.text = "+27";
|
||||
contactController.text = mzansiProfileProvider.business!.contact_no;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void setControllers() {
|
||||
MzansiProfileProvider mzansiProfileProvider =
|
||||
context.read<MzansiProfileProvider>();
|
||||
setState(() {
|
||||
fileNameController.text =
|
||||
mzansiProfileProvider.business!.logo_path.split("/").last;
|
||||
regController.text = mzansiProfileProvider.business!.registration_no;
|
||||
nameController.text = mzansiProfileProvider.business!.Name;
|
||||
typeController.text = mzansiProfileProvider.business!.type;
|
||||
practiceNoController.text = mzansiProfileProvider.business!.practice_no;
|
||||
vatNoController.text = mzansiProfileProvider.business!.vat_no;
|
||||
emailController.text = mzansiProfileProvider.business!.bus_email;
|
||||
locationController.text = mzansiProfileProvider.business!.gps_location;
|
||||
websiteController.text = mzansiProfileProvider.business!.website;
|
||||
ratingController.text = mzansiProfileProvider.business!.rating;
|
||||
missionVisionController.text =
|
||||
mzansiProfileProvider.business!.mission_vision;
|
||||
});
|
||||
setContactNumberControllers(mzansiProfileProvider);
|
||||
if (AppEnviroment.getEnv() == "Prod") {
|
||||
env = "Prod";
|
||||
} else {
|
||||
env = "Dev";
|
||||
}
|
||||
}
|
||||
|
||||
Color getMissionVisionLimitColor(int limit) {
|
||||
if (_counter.value <= limit) {
|
||||
return MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
|
||||
} else {
|
||||
return MihColors.getRedColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
|
||||
}
|
||||
}
|
||||
|
||||
void _updateMissionVisionCounter() {
|
||||
// New function name
|
||||
// No need for setState since you are using a ValueNotifier for _counter
|
||||
_counter.value = missionVisionController.text.characters.length;
|
||||
}
|
||||
|
||||
String getNumberWithCountryCode() {
|
||||
String numberWithoutBeginingZero = "";
|
||||
if (contactController.text[0] == "0") {
|
||||
numberWithoutBeginingZero = contactController.text
|
||||
.replaceAll(" ", "")
|
||||
.substring(1, contactController.text.length);
|
||||
} else {
|
||||
numberWithoutBeginingZero = contactController.text.replaceAll("-", " ");
|
||||
}
|
||||
return "${countryCodeController.text}-$numberWithoutBeginingZero";
|
||||
}
|
||||
|
||||
bool isFormFilled() {
|
||||
if (typeController.text.isEmpty) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void successPopUp(String message, bool stayOnPersonalSide) {
|
||||
MihAlertServices().successBasicAlert(
|
||||
"Success!",
|
||||
message,
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> uploadFile(MzansiProfileProvider mzansiProfileProvider) async {
|
||||
if (newSelectedLogoPic != null) {
|
||||
int uploadStatusCode = 0;
|
||||
uploadStatusCode = await MihFileApi.uploadFile(
|
||||
mzansiProfileProvider.business!.business_id,
|
||||
env,
|
||||
"business_files",
|
||||
newSelectedLogoPic!,
|
||||
context,
|
||||
);
|
||||
if (uploadStatusCode == 200) {
|
||||
int deleteStatusCode = 0;
|
||||
deleteStatusCode = await MihFileApi.deleteFile(
|
||||
mzansiProfileProvider.business!.logo_path.split("/").first,
|
||||
env,
|
||||
"business_files",
|
||||
mzansiProfileProvider.business!.logo_path.split("/").last,
|
||||
context,
|
||||
);
|
||||
if (deleteStatusCode == 200) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return true; // No file selected, so no upload needed
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> submitForm(MzansiProfileProvider mzansiProfileProvider) async {
|
||||
KenLogger.success("Start Submit Form");
|
||||
if (isFormFilled()) {
|
||||
KenLogger.success("Form Filled");
|
||||
KenLogger.success("Start File Upload");
|
||||
bool successfullyUploadedFile = await uploadFile(mzansiProfileProvider);
|
||||
KenLogger.success(
|
||||
"File Upload Complete: outcome $successfullyUploadedFile");
|
||||
if (!mounted) return;
|
||||
KenLogger.success("is mounted");
|
||||
if (successfullyUploadedFile) {
|
||||
KenLogger.success("Start Details Update");
|
||||
int statusCode = 0;
|
||||
statusCode = await MihBusinessDetailsServices().updateBusinessDetailsV2(
|
||||
mzansiProfileProvider.business!.business_id,
|
||||
nameController.text,
|
||||
typeController.text,
|
||||
regController.text,
|
||||
practiceNoController.text,
|
||||
vatNoController.text,
|
||||
emailController.text,
|
||||
getNumberWithCountryCode(),
|
||||
// contactController.text,
|
||||
locationController.text,
|
||||
fileNameController.text,
|
||||
websiteController.text,
|
||||
ratingController.text.isEmpty ? "0" : ratingController.text,
|
||||
missionVisionController.text,
|
||||
mzansiProfileProvider,
|
||||
context,
|
||||
);
|
||||
KenLogger.success("Details Update Complete: status code $statusCode");
|
||||
if (!mounted) return;
|
||||
KenLogger.success("is mounted");
|
||||
if (statusCode == 200) {
|
||||
KenLogger.success("Start Success Message");
|
||||
//You left of here
|
||||
String message = "Your information has been updated successfully!";
|
||||
context.pop();
|
||||
successPopUp(message, false);
|
||||
// File uploaded successfully
|
||||
} else {
|
||||
context.pop();
|
||||
// File upload failed
|
||||
MihAlertServices().errorBasicAlert(
|
||||
"Error Updating Business Details",
|
||||
"An error occurred while updating the business details. Please try again.",
|
||||
context,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
context.pop();
|
||||
if (!mounted) return;
|
||||
MihAlertServices().internetConnectionAlert(context);
|
||||
}
|
||||
} else {
|
||||
MihAlertServices().inputErrorAlert(context);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
setControllers();
|
||||
missionVisionController.addListener(_updateMissionVisionCounter);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<MzansiProfileProvider>(
|
||||
builder: (BuildContext context,
|
||||
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
|
||||
return MihPackageWindow(
|
||||
fullscreen: false,
|
||||
windowTitle: 'Edit Profile',
|
||||
onWindowTapClose: () {
|
||||
context.pop();
|
||||
},
|
||||
windowBody: MihSingleChildScroll(
|
||||
child: Padding(
|
||||
padding:
|
||||
MzansiInnovationHub.of(context)!.theme.screenType == "desktop"
|
||||
? EdgeInsets.symmetric(horizontal: widget.width * 0.05)
|
||||
: EdgeInsets.symmetric(horizontal: widget.width * 0),
|
||||
child: Column(
|
||||
children: [
|
||||
MihForm(
|
||||
formKey: _formKey,
|
||||
formFields: [
|
||||
Center(
|
||||
child: MihCircleAvatar(
|
||||
imageFile: newSelectedLogoPic != null
|
||||
? MemoryImage(newSelectedLogoPic!.bytes!)
|
||||
: mzansiProfileProvider.businessProfilePicture,
|
||||
width: 150,
|
||||
editable: true,
|
||||
fileNameController: fileNameController,
|
||||
userSelectedfile: newSelectedLogoPic,
|
||||
frameColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
backgroundColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
onChange: (selectedfile) {
|
||||
setState(() {
|
||||
newSelectedLogoPic = selectedfile;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: false,
|
||||
child: MihTextFormField(
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
inputColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
controller: fileNameController,
|
||||
multiLineInput: false,
|
||||
requiredText: true,
|
||||
readOnly: true,
|
||||
hintText: "Selected File Name",
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
MihTextFormField(
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
inputColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
controller: nameController,
|
||||
multiLineInput: false,
|
||||
requiredText: true,
|
||||
hintText: "Business Name",
|
||||
validator: (value) {
|
||||
return MihValidationServices().isEmpty(value);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
MihTextFormField(
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
inputColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
controller: typeController,
|
||||
multiLineInput: false,
|
||||
requiredText: true,
|
||||
hintText: "Business Type",
|
||||
validator: (value) {
|
||||
return MihValidationServices()
|
||||
.validateNoSpecialChars(value);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
MihTextFormField(
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
inputColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
controller: emailController,
|
||||
multiLineInput: false,
|
||||
requiredText: true,
|
||||
hintText: "Business Email",
|
||||
validator: (value) {
|
||||
return MihValidationServices().validateEmail(value);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Container(
|
||||
width: 300,
|
||||
alignment: Alignment.topLeft,
|
||||
child: const Text(
|
||||
"Contact Number:",
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
CountryCodePicker(
|
||||
padding: EdgeInsetsGeometry.all(0),
|
||||
onChanged: (selectedCode) {
|
||||
setState(() {
|
||||
countryCodeController.text =
|
||||
selectedCode.toString();
|
||||
});
|
||||
debugPrint(
|
||||
"Selected Country Code: ${countryCodeController.text}");
|
||||
},
|
||||
initialSelection: countryCodeController.text,
|
||||
showDropDownButton: false,
|
||||
pickerStyle: PickerStyle.bottomSheet,
|
||||
dialogBackgroundColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
barrierColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
Expanded(
|
||||
child: MihTextFormField(
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
inputColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
controller: contactController,
|
||||
numberMode: true,
|
||||
multiLineInput: false,
|
||||
requiredText: true,
|
||||
hintText: null,
|
||||
validator: (value) {
|
||||
return MihValidationServices().isEmpty(value);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
MihTextFormField(
|
||||
height: 250,
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
inputColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
controller: missionVisionController,
|
||||
multiLineInput: true,
|
||||
requiredText: true,
|
||||
hintText: "Business Mission & Vision",
|
||||
validator: (value) {
|
||||
return MihValidationServices().validateLength(
|
||||
missionVisionController.text, 256);
|
||||
},
|
||||
),
|
||||
SizedBox(
|
||||
height: 15,
|
||||
child: ValueListenableBuilder(
|
||||
valueListenable: _counter,
|
||||
builder:
|
||||
(BuildContext context, int value, Widget? child) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
"$value",
|
||||
style: TextStyle(
|
||||
color: getMissionVisionLimitColor(256),
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
Text(
|
||||
"/256",
|
||||
style: TextStyle(
|
||||
color: getMissionVisionLimitColor(256),
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10.0),
|
||||
MihTextFormField(
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
inputColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
controller: websiteController,
|
||||
multiLineInput: false,
|
||||
requiredText: false,
|
||||
hintText: "Business Website",
|
||||
validator: (value) {
|
||||
return MihValidationServices()
|
||||
.validateWebsite(value, false);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
MihTextFormField(
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
inputColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
controller: regController,
|
||||
multiLineInput: false,
|
||||
requiredText: false,
|
||||
hintText: "Registration No.",
|
||||
validator: (value) {
|
||||
// return MihValidationServices().isEmpty(value);
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
MihTextFormField(
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
inputColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
controller: practiceNoController,
|
||||
multiLineInput: false,
|
||||
requiredText: false,
|
||||
hintText: "Practice Number",
|
||||
validator: (validateValue) {
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
MihTextFormField(
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
inputColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
controller: vatNoController,
|
||||
multiLineInput: false,
|
||||
requiredText: false,
|
||||
hintText: "VAT Number",
|
||||
validator: (value) {
|
||||
// return MihValidationServices().isEmpty(value);
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Flexible(
|
||||
child: MihTextFormField(
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
inputColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
controller: locationController,
|
||||
multiLineInput: false,
|
||||
requiredText: true,
|
||||
readOnly: true,
|
||||
hintText: "GPS Location",
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10.0),
|
||||
MihButton(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return const Mihloadingcircle(
|
||||
message: "Getting your location",
|
||||
);
|
||||
},
|
||||
);
|
||||
MIHLocationAPI()
|
||||
.getGPSPosition(context)
|
||||
.then((position) {
|
||||
if (position != null) {
|
||||
setState(() {
|
||||
locationController.text =
|
||||
"${position.latitude}, ${position.longitude}";
|
||||
});
|
||||
}
|
||||
//Dismiss loading indicator
|
||||
context.pop();
|
||||
});
|
||||
},
|
||||
buttonColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
width: 100,
|
||||
child: Text(
|
||||
"Set",
|
||||
style: TextStyle(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!
|
||||
.theme
|
||||
.mode ==
|
||||
"Dark"),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
Center(
|
||||
child: MihButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
submitForm(mzansiProfileProvider);
|
||||
} else {
|
||||
MihAlertServices().inputErrorAlert(context);
|
||||
}
|
||||
},
|
||||
buttonColor: MihColors.getGreenColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
width: 300,
|
||||
child: Text(
|
||||
"Update",
|
||||
style: TextStyle(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,372 +0,0 @@
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_button.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_circle_avatar.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_form.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_image_display.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_window.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_single_child_scroll.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_text_form_field.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_my_business_user_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class MihUpdateMyBusinessUserDetails extends StatefulWidget {
|
||||
const MihUpdateMyBusinessUserDetails({super.key});
|
||||
|
||||
@override
|
||||
State<MihUpdateMyBusinessUserDetails> createState() =>
|
||||
_MihUpdateMyBusinessUserDetailsState();
|
||||
}
|
||||
|
||||
class _MihUpdateMyBusinessUserDetailsState
|
||||
extends State<MihUpdateMyBusinessUserDetails> {
|
||||
final fileNameController = TextEditingController();
|
||||
final titleTextController = TextEditingController();
|
||||
final fnameController = TextEditingController();
|
||||
final lnameController = TextEditingController();
|
||||
final accessController = TextEditingController();
|
||||
final signtureController = TextEditingController();
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
PlatformFile? userPicFile;
|
||||
PlatformFile? newSelectedSignaturePic;
|
||||
late String env;
|
||||
|
||||
bool isFormFilled() {
|
||||
if (titleTextController.text.isEmpty) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> uploadFile(MzansiProfileProvider mzansiProfileProvider) async {
|
||||
if (newSelectedSignaturePic != null) {
|
||||
int uploadStatusCode = 0;
|
||||
uploadStatusCode = await MihFileApi.uploadFile(
|
||||
mzansiProfileProvider.user!.app_id,
|
||||
env,
|
||||
"business_files",
|
||||
newSelectedSignaturePic!,
|
||||
context,
|
||||
);
|
||||
if (uploadStatusCode == 200) {
|
||||
signtureController.text = newSelectedSignaturePic!.name;
|
||||
int deleteStatusCode = 0;
|
||||
deleteStatusCode = await MihFileApi.deleteFile(
|
||||
mzansiProfileProvider.user!.app_id,
|
||||
env,
|
||||
"business_files",
|
||||
mzansiProfileProvider.businessUser!.sig_path.split("/").last,
|
||||
context,
|
||||
);
|
||||
if (deleteStatusCode == 200) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return true; // No file selected, so no upload needed
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> submitForm(MzansiProfileProvider mzansiProfileProvider) async {
|
||||
if (isFormFilled()) {
|
||||
bool successfullyUploadedFile = await uploadFile(mzansiProfileProvider);
|
||||
if (!mounted) return;
|
||||
if (successfullyUploadedFile) {
|
||||
int statusCode = await MihMyBusinessUserServices().updateBusinessUser(
|
||||
mzansiProfileProvider.user!.app_id,
|
||||
mzansiProfileProvider.businessUser!.business_id,
|
||||
titleTextController.text,
|
||||
accessController.text,
|
||||
signtureController.text,
|
||||
mzansiProfileProvider,
|
||||
context,
|
||||
);
|
||||
if (!mounted) return;
|
||||
if (statusCode == 200) {
|
||||
String message = "Business details updated successfully";
|
||||
context.pop();
|
||||
successPopUp(message, false);
|
||||
} else {
|
||||
MihAlertServices().errorBasicAlert(
|
||||
"Error Updating Business User Details",
|
||||
"An error occurred while updating the business User details. Please check internet connection and try again.",
|
||||
context,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
MihAlertServices().internetConnectionAlert(context);
|
||||
}
|
||||
} else {
|
||||
MihAlertServices().inputErrorAlert(context);
|
||||
}
|
||||
}
|
||||
|
||||
void successPopUp(String message, bool stayOnPersonalSide) {
|
||||
MihAlertServices().successBasicAlert(
|
||||
"Success!",
|
||||
message,
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
||||
Widget getWindowBody(double width) {
|
||||
return Consumer<MzansiProfileProvider>(
|
||||
builder: (BuildContext context,
|
||||
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
|
||||
return MihSingleChildScroll(
|
||||
child: Padding(
|
||||
padding:
|
||||
MzansiInnovationHub.of(context)!.theme.screenType == "desktop"
|
||||
? EdgeInsets.symmetric(horizontal: width * 0.2)
|
||||
: EdgeInsets.symmetric(horizontal: width * 0.075),
|
||||
child: Column(
|
||||
children: [
|
||||
MihForm(
|
||||
formKey: _formKey,
|
||||
formFields: [
|
||||
Center(
|
||||
child: MihCircleAvatar(
|
||||
imageFile: mzansiProfileProvider.userProfilePicture,
|
||||
width: 150,
|
||||
editable: false,
|
||||
fileNameController: fileNameController,
|
||||
userSelectedfile: userPicFile,
|
||||
frameColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
backgroundColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
onChange: (_) {},
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: false,
|
||||
child: MihTextFormField(
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
inputColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
controller: fileNameController,
|
||||
multiLineInput: false,
|
||||
requiredText: true,
|
||||
readOnly: true,
|
||||
hintText: "Selected File Name",
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
MihTextFormField(
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
inputColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
controller: titleTextController,
|
||||
multiLineInput: false,
|
||||
requiredText: true,
|
||||
readOnly: false,
|
||||
hintText: "Title",
|
||||
validator: (value) {
|
||||
return MihValidationServices().isEmpty(value);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
MihTextFormField(
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
inputColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
controller: fnameController,
|
||||
multiLineInput: false,
|
||||
requiredText: true,
|
||||
readOnly: true,
|
||||
hintText: "First Name",
|
||||
validator: (value) {
|
||||
return MihValidationServices().isEmpty(value);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
MihTextFormField(
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
inputColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
controller: lnameController,
|
||||
multiLineInput: false,
|
||||
requiredText: true,
|
||||
readOnly: true,
|
||||
hintText: "Surname",
|
||||
validator: (value) {
|
||||
return MihValidationServices().isEmpty(value);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
MihTextFormField(
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
inputColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
controller: accessController,
|
||||
multiLineInput: false,
|
||||
requiredText: true,
|
||||
hintText: "Access Level",
|
||||
readOnly: true,
|
||||
validator: (value) {
|
||||
return MihValidationServices().isEmpty(value);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Container(
|
||||
width: 300,
|
||||
alignment: Alignment.topLeft,
|
||||
child: const Text(
|
||||
"Signature:",
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
Center(
|
||||
child: MihImageDisplay(
|
||||
imageFile: newSelectedSignaturePic != null
|
||||
? MemoryImage(newSelectedSignaturePic!.bytes!)
|
||||
: mzansiProfileProvider.businessUserSignature,
|
||||
width: 300,
|
||||
height: 200,
|
||||
editable: true,
|
||||
fileNameController: signtureController,
|
||||
userSelectedfile: newSelectedSignaturePic,
|
||||
onChange: (selectedFile) {
|
||||
setState(() {
|
||||
newSelectedSignaturePic = selectedFile;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Visibility(
|
||||
visible: false,
|
||||
child: MihTextFormField(
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
inputColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
controller: fileNameController,
|
||||
multiLineInput: false,
|
||||
requiredText: true,
|
||||
readOnly: true,
|
||||
hintText: "Selected Signature File",
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
Center(
|
||||
child: MihButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
submitForm(mzansiProfileProvider);
|
||||
} else {
|
||||
MihAlertServices().inputErrorAlert(context);
|
||||
}
|
||||
},
|
||||
buttonColor: MihColors.getGreenColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
width: 300,
|
||||
child: Text(
|
||||
"Update",
|
||||
style: TextStyle(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void setControllers() {
|
||||
MzansiProfileProvider mzansiProfileProvider =
|
||||
context.read<MzansiProfileProvider>();
|
||||
fileNameController.text =
|
||||
mzansiProfileProvider.user!.pro_pic_path.split("/").last;
|
||||
signtureController.text =
|
||||
mzansiProfileProvider.businessUser!.sig_path.split("/").last;
|
||||
titleTextController.text = mzansiProfileProvider.businessUser!.title;
|
||||
fnameController.text = mzansiProfileProvider.user!.fname;
|
||||
lnameController.text = mzansiProfileProvider.user!.lname;
|
||||
accessController.text = mzansiProfileProvider.businessUser!.access;
|
||||
if (AppEnviroment.getEnv() == "Prod") {
|
||||
env = "Prod";
|
||||
} else {
|
||||
env = "Dev";
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
fileNameController.dispose();
|
||||
titleTextController.dispose();
|
||||
fnameController.dispose();
|
||||
lnameController.dispose();
|
||||
accessController.dispose();
|
||||
signtureController.dispose();
|
||||
userPicFile = null;
|
||||
newSelectedSignaturePic = null;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
setControllers();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
double screenWidth = MediaQuery.of(context).size.width;
|
||||
return MihPackageWindow(
|
||||
fullscreen: false,
|
||||
windowTitle: "Edit Profile",
|
||||
onWindowTapClose: () {
|
||||
context.pop();
|
||||
},
|
||||
windowBody: getWindowBody(screenWidth),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,182 +0,0 @@
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_button.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_circle_avatar.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_tool_body.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_single_child_scroll.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_loading_circle.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/personal_profile/components/mih_edit_personal_profile_window.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class MihPersonalProfile extends StatefulWidget {
|
||||
const MihPersonalProfile({super.key});
|
||||
|
||||
@override
|
||||
State<MihPersonalProfile> createState() => _MihPersonalProfileState();
|
||||
}
|
||||
|
||||
class _MihPersonalProfileState extends State<MihPersonalProfile> {
|
||||
TextEditingController proPicController = TextEditingController();
|
||||
PlatformFile? newSelectedProPic;
|
||||
|
||||
void editProfileWindow(double width) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => Consumer<MzansiProfileProvider>(
|
||||
builder: (BuildContext context,
|
||||
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
|
||||
return MihEditPersonalProfileWindow();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
double screenWidth = MediaQuery.of(context).size.width;
|
||||
return MihPackageToolBody(
|
||||
borderOn: false,
|
||||
innerHorizontalPadding: 10,
|
||||
bodyItem: getBody(screenWidth),
|
||||
);
|
||||
}
|
||||
|
||||
Widget getBody(double width) {
|
||||
return Consumer<MzansiProfileProvider>(
|
||||
builder: (BuildContext context,
|
||||
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
|
||||
if (mzansiProfileProvider.user == null) {
|
||||
//Change to new user flow
|
||||
return Center(
|
||||
child: Mihloadingcircle(),
|
||||
);
|
||||
} else {
|
||||
return MihSingleChildScroll(
|
||||
child: Padding(
|
||||
padding:
|
||||
MzansiInnovationHub.of(context)!.theme.screenType == "desktop"
|
||||
? EdgeInsets.symmetric(horizontal: width * 0.2)
|
||||
: EdgeInsets.symmetric(horizontal: width * 0.075),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Center(
|
||||
child: MihCircleAvatar(
|
||||
imageFile: mzansiProfileProvider.userProfilePicture,
|
||||
width: 150,
|
||||
editable: false,
|
||||
fileNameController: proPicController,
|
||||
userSelectedfile: newSelectedProPic,
|
||||
frameColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
backgroundColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
onChange: (selectedImage) {
|
||||
setState(() {
|
||||
newSelectedProPic = selectedImage;
|
||||
});
|
||||
},
|
||||
key: ValueKey(mzansiProfileProvider.userProfilePicUrl),
|
||||
),
|
||||
),
|
||||
FittedBox(
|
||||
child: Text(
|
||||
mzansiProfileProvider.user!.username.isNotEmpty
|
||||
? mzansiProfileProvider.user!.username
|
||||
: "username",
|
||||
style: TextStyle(
|
||||
fontSize: 35,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
),
|
||||
),
|
||||
FittedBox(
|
||||
child: Text(
|
||||
mzansiProfileProvider.user!.fname.isNotEmpty
|
||||
? "${mzansiProfileProvider.user!.fname} ${mzansiProfileProvider.user!.lname}"
|
||||
: "Name Surname",
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
),
|
||||
),
|
||||
FittedBox(
|
||||
child: Text(
|
||||
mzansiProfileProvider.user!.type == "business"
|
||||
? "Business".toUpperCase()
|
||||
: "Personal".toUpperCase(),
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10.0),
|
||||
Center(
|
||||
child: SizedBox(
|
||||
width: 700,
|
||||
child: Text(
|
||||
mzansiProfileProvider.user!.purpose.isNotEmpty
|
||||
? mzansiProfileProvider.user!.purpose
|
||||
: "No Personal Mission added yet",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 30.0),
|
||||
Center(
|
||||
child: MihButton(
|
||||
onPressed: () {
|
||||
// Connect with the user
|
||||
editProfileWindow(width);
|
||||
},
|
||||
buttonColor: MihColors.getGreenColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
width: 300,
|
||||
child: Text(
|
||||
mzansiProfileProvider.user!.username.isEmpty
|
||||
? "Set Up Profile"
|
||||
: "Edit Profile",
|
||||
style: TextStyle(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:google_mobile_ads/google_mobile_ads.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
|
||||
|
||||
class MihBannerAdProvider extends ChangeNotifier {
|
||||
BannerAd? bannerAd;
|
||||
final adUnitId = AppEnviroment.bannerAdUnitId;
|
||||
bool isBannerAdLoaded = false;
|
||||
String errorMessage = '';
|
||||
|
||||
MihBannerAdProvider({
|
||||
this.bannerAd,
|
||||
this.isBannerAdLoaded = false,
|
||||
this.errorMessage = '',
|
||||
});
|
||||
|
||||
void reset() {
|
||||
bannerAd = null;
|
||||
isBannerAdLoaded = false;
|
||||
errorMessage = "";
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
bannerAd?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void loadBannerAd() {
|
||||
if (bannerAd != null) {
|
||||
bannerAd!.dispose();
|
||||
bannerAd = null;
|
||||
isBannerAdLoaded = false;
|
||||
}
|
||||
bannerAd = BannerAd(
|
||||
adUnitId: adUnitId,
|
||||
request: const AdRequest(),
|
||||
size: AdSize.banner,
|
||||
listener: BannerAdListener(
|
||||
onAdLoaded: (ad) {
|
||||
debugPrint('$ad loaded.');
|
||||
isBannerAdLoaded = true;
|
||||
notifyListeners();
|
||||
},
|
||||
onAdFailedToLoad: (ad, err) {
|
||||
debugPrint('BannerAd failed to load: $err');
|
||||
errorMessage =
|
||||
'Failed to load ad- Message: ${err.message} Code :${err.code}';
|
||||
ad.dispose(); // Dispose the ad to free resources
|
||||
isBannerAdLoaded = false; // ⬅️ Explicitly set to false
|
||||
bannerAd = null; // ⬅️ Explicitly set to null
|
||||
notifyListeners();
|
||||
},
|
||||
onAdOpened: (Ad ad) => debugPrint('$ad opened.'),
|
||||
onAdClosed: (Ad ad) => debugPrint('$ad closed.'),
|
||||
onAdImpression: (Ad ad) => debugPrint('$ad impression.'),
|
||||
),
|
||||
);
|
||||
bannerAd!.load();
|
||||
}
|
||||
}
|
||||
@@ -1,328 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart';
|
||||
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_icons.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/ollama_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
|
||||
|
||||
class MzansiAiProvider extends ChangeNotifier {
|
||||
bool ttsOn;
|
||||
int toolIndex;
|
||||
String? startUpQuestion;
|
||||
late OllamaProvider ollamaProvider;
|
||||
|
||||
MzansiAiProvider({
|
||||
this.toolIndex = 0,
|
||||
this.ttsOn = false,
|
||||
}) {
|
||||
ollamaProvider = OllamaProvider(
|
||||
baseUrl: "${AppEnviroment.baseAiUrl}/api",
|
||||
model: AppEnviroment.getEnv() == "Prod" ? 'gemma3n:e4b' : "gemma3:1b",
|
||||
systemPrompt: "You are Mzansi AI, a helpful and friendly AI assistant running on the 'MIH App'.\n" +
|
||||
"The MIH App was created by 'Mzansi Innovation Hub', a South African-based startup company." +
|
||||
"Your primary purpose is to assist users by answering general questions and helping with creative writing tasks or any other task a user might have for you.\n" +
|
||||
"Maintain a casual and friendly tone, but always remain professional.\n" +
|
||||
"Strive for a balance between being empathetic and delivering factual information accurately.\n" +
|
||||
"You may use lighthearted or playful language if the context is appropriate and enhances the user experience.\n" +
|
||||
"You operate within the knowledge domain of the 'MIH App'.\n" +
|
||||
"Here is a description of the MIH App and its features:\n" +
|
||||
"MIH App Description: MIH is the first super app of Mzansi, designed to streamline both personal and business life. It's an all-in-one platform for managing professional profiles, teams, appointments, and quick calculations. \n" +
|
||||
"Key Features:\n" +
|
||||
"- Mzansi Profile: Central hub for managing personal and business information, including business team details." +
|
||||
"- Mzansi Wallet: Digitally store loyalty cards.\n" +
|
||||
"- Patient Manager (For Medical Practices): Seamless patient appointment scheduling and data management.\n" +
|
||||
"- Mzansi AI: Your friendly AI assistant for quick answers and support (that's you!).\n" +
|
||||
"- Mzansi Directory: A place to search and find out more about the people and businesses across Mzansi.\n" +
|
||||
"- Calendar: Integrated calendar for managing personal and business appointments.\n" +
|
||||
"- Calculator: Simple calculator with tip and forex calculation functionality.\n" +
|
||||
"- MIH Minesweeper: The first game from MIH! It's the classic brain-teaser ready to entertain you no matter where you are.\n" +
|
||||
"- MIH Access: Manage and view profile access security.\n" +
|
||||
"**Core Rules and Guidelines:**\n" +
|
||||
"- **Accuracy First:** Always prioritize providing correct information.\n" +
|
||||
"- **Uncertainty Handling:** If you are unsure about an answer, politely respond with: 'Please bear with us as we are still learning and do not have all the answers.'\n" +
|
||||
"- **Response Length:** Aim to keep responses under 250 words. If a more comprehensive answer is required, exceed this limit but offer to elaborate further (e.g., 'Would you like me to elaborate on this topic?').\n" +
|
||||
"- **Language & Safety:** Never use offensive language or generate harmful content. If a user presses for information that is inappropriate or out of bounds, clearly state why you cannot provide it (e.g., 'I cannot assist with that request as it goes against my safety guidelines.').\n" +
|
||||
"- **Out-of-Scope Questions:** - If a question is unclear, ask the user to rephrase or clarify it. - If a question is entirely out of your scope and you cannot provide a useful answer, admit you don't know. - If a user is unhappy with your response or needs further assistance beyond your capabilities, suggest they visit the 'Mzansi Innovation Hub Social Media Pages' for more direct support. Do not provide specific links, just refer to the pages generally.\n" +
|
||||
"- **Target Audience:** Adapt your explanations to beginners and intermediate users, but be prepared for more complex questions from expert users. Ensure your language is clear and easy to understand.\n",
|
||||
)..addListener(() {
|
||||
notifyListeners(); // Forward OllamaProvider notifications
|
||||
});
|
||||
}
|
||||
|
||||
void reset() {
|
||||
toolIndex = 0;
|
||||
startUpQuestion = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setToolIndex(int index) {
|
||||
toolIndex = index;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setTTSstate(bool ttsOn) {
|
||||
this.ttsOn = ttsOn;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setStartUpQuestion(String? question) {
|
||||
startUpQuestion = question;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void clearStartUpQuestion() {
|
||||
startUpQuestion = null;
|
||||
}
|
||||
|
||||
MarkdownStyleSheet getLlmChatMarkdownStyle(BuildContext context) {
|
||||
TextStyle body = TextStyle(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w400,
|
||||
);
|
||||
TextStyle heading1 = TextStyle(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w400,
|
||||
);
|
||||
TextStyle heading2 = TextStyle(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w400,
|
||||
);
|
||||
TextStyle code = TextStyle(
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w400,
|
||||
);
|
||||
BoxDecoration codeBlock = BoxDecoration(
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(10),
|
||||
topRight: Radius.circular(10),
|
||||
bottomLeft: Radius.circular(10),
|
||||
bottomRight: Radius.circular(10),
|
||||
),
|
||||
color: MihColors.getHighlightColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode != "Dark"),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withAlpha(76),
|
||||
blurRadius: 8,
|
||||
offset: Offset(2, 2),
|
||||
),
|
||||
],
|
||||
);
|
||||
return MarkdownStyleSheet(
|
||||
a: body,
|
||||
blockquote: body,
|
||||
checkbox: body,
|
||||
del: body,
|
||||
em: body.copyWith(fontStyle: FontStyle.italic),
|
||||
h1: heading1,
|
||||
h2: heading2,
|
||||
h3: body.copyWith(fontWeight: FontWeight.bold),
|
||||
h4: body,
|
||||
h5: body,
|
||||
h6: body,
|
||||
listBullet: body,
|
||||
img: body,
|
||||
strong: body.copyWith(fontWeight: FontWeight.bold),
|
||||
p: body,
|
||||
tableBody: body,
|
||||
tableHead: body,
|
||||
code: code,
|
||||
codeblockDecoration: codeBlock,
|
||||
);
|
||||
}
|
||||
|
||||
LlmChatViewStyle? getChatStyle(BuildContext context) {
|
||||
return LlmChatViewStyle(
|
||||
backgroundColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
progressIndicatorColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
menuColor: Colors.black,
|
||||
// MihColors.getGreenColor(
|
||||
// MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
disabledButtonStyle: ActionButtonStyle(
|
||||
icon: MihIcons.mzansiAi,
|
||||
iconColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
iconDecoration: BoxDecoration(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
),
|
||||
),
|
||||
recordButtonStyle: ActionButtonStyle(
|
||||
iconColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
iconDecoration: BoxDecoration(
|
||||
color: MihColors.getGreenColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
),
|
||||
textStyle: TextStyle(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
),
|
||||
submitButtonStyle: ActionButtonStyle(
|
||||
icon: Icons.send,
|
||||
iconColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
iconDecoration: BoxDecoration(
|
||||
color: MihColors.getGreenColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
),
|
||||
textStyle: TextStyle(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
),
|
||||
stopButtonStyle: ActionButtonStyle(
|
||||
iconColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
iconDecoration: BoxDecoration(
|
||||
color: MihColors.getRedColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
),
|
||||
textStyle: TextStyle(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
),
|
||||
actionButtonBarDecoration: BoxDecoration(
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
),
|
||||
// Mzansi AI Chat Style
|
||||
llmMessageStyle: LlmMessageStyle(
|
||||
icon: MihIcons.mzansiAi,
|
||||
iconColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
iconDecoration: BoxDecoration(
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.only(
|
||||
topRight: Radius.circular(25),
|
||||
bottomLeft: Radius.circular(25),
|
||||
bottomRight: Radius.circular(25),
|
||||
),
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withAlpha(76),
|
||||
blurRadius: 8,
|
||||
offset: Offset(2, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
markdownStyle: getLlmChatMarkdownStyle(context),
|
||||
),
|
||||
// User Chat Style
|
||||
userMessageStyle: UserMessageStyle(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(25),
|
||||
bottomLeft: Radius.circular(25),
|
||||
bottomRight: Radius.circular(25),
|
||||
),
|
||||
color: MihColors.getGreenColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withAlpha(76),
|
||||
blurRadius: 8,
|
||||
offset: Offset(2, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
textStyle: TextStyle(
|
||||
fontSize: 16,
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
),
|
||||
// User Input Style
|
||||
chatInputStyle: ChatInputStyle(
|
||||
backgroundColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
decoration: BoxDecoration(
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withAlpha(76),
|
||||
blurRadius: 8,
|
||||
offset: Offset(2, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
hintStyle: TextStyle(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
hintText: "Ask Mzansi AI...",
|
||||
),
|
||||
// Suggestions Style
|
||||
suggestionStyle: SuggestionStyle(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(25),
|
||||
bottomLeft: Radius.circular(25),
|
||||
bottomRight: Radius.circular(25),
|
||||
),
|
||||
color: MihColors.getGreenColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withAlpha(76),
|
||||
blurRadius: 8,
|
||||
offset: Offset(2, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
textStyle: TextStyle(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
),
|
||||
copyButtonStyle: ActionButtonStyle(
|
||||
iconColor: MihColors.getSecondaryInvertedColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
editButtonStyle: ActionButtonStyle(
|
||||
iconColor: MihColors.getSecondaryInvertedColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
cancelButtonStyle: ActionButtonStyle(
|
||||
iconDecoration: BoxDecoration(
|
||||
color: MihColors.getRedColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
),
|
||||
iconColor: MihColors.getSecondaryInvertedColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
textStyle: TextStyle(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Inspired by https://gist.github.com/jtangelder/e445e9a7f5e31c220be6
|
||||
# Python3 http.server for Single Page Application
|
||||
|
||||
import urllib.parse
|
||||
import http.server
|
||||
import socketserver
|
||||
import re
|
||||
from pathlib import Path
|
||||
port = 83
|
||||
HOST = ('', port)
|
||||
pattern = re.compile('.png|.jpg|.jpeg|.js|.css|.ico|.gif|.svg|.ico', re.IGNORECASE)
|
||||
|
||||
|
||||
class Handler(http.server.SimpleHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
url_parts = urllib.parse.urlparse(self.path)
|
||||
request_file_path = Path(url_parts.path.strip("/"))
|
||||
|
||||
ext = request_file_path.suffix
|
||||
if not request_file_path.is_file() and not pattern.match(ext):
|
||||
self.path = 'index.html'
|
||||
|
||||
return http.server.SimpleHTTPRequestHandler.do_GET(self)
|
||||
|
||||
|
||||
httpd = socketserver.TCPServer(HOST, Handler)
|
||||
print(f"Starting Web App Server on pot: {port}")
|
||||
httpd.serve_forever()
|
||||
@@ -1,18 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Define the port
|
||||
PORT=83
|
||||
|
||||
# Check if the port is in use and release it if necessary.
|
||||
# echo "Checking if port $PORT is in use..."
|
||||
# if [ "$(lsof -t -i :$PORT)" ]; then
|
||||
# echo "Port $PORT is in use. Stopping the process on that port..."
|
||||
# fuser -k -n tcp $PORT
|
||||
# fi
|
||||
|
||||
# Switch to the web construction directory
|
||||
cd /app/build/web/
|
||||
|
||||
# Start the web server on the specified port
|
||||
#python3 -m http.server 83
|
||||
python3 -u ../../server/MIH_web_server.py
|
||||
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 41 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 41 KiB |
674
LICENSE
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
The MIH Project is the first open-source super app of Mzansi.
|
||||
Copyright (C) 2026 MZANSI INNOVATION HUB (PTY) LTD
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) 2026 MZANSI INNOVATION HUB (PTY) LTD
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
30
README.md
@@ -1,4 +1,5 @@
|
||||
<h1>How to create your flavour of the MIH Server</h1>
|
||||
<h1>The MIH Project</h1>
|
||||
learn how to create your own flavour of the MIH Server.
|
||||
<h2>Prerequisite:-</h2>
|
||||
<ol>
|
||||
<li>Ubuntu Server OS installed (24.04 tested)</li>
|
||||
@@ -9,7 +10,7 @@
|
||||
<h2>Get Started:-</h2>
|
||||
<ol>
|
||||
<li>Clone Git Repo.</li>
|
||||
<li>Navigate to Mzansi-Innovation-Hub directory. <pre><code>cd Mzansi-Innovation-Hub</code></pre></li>
|
||||
<li>Navigate to mih-project directory. <pre><code>cd mih-project</code></pre></li>
|
||||
<li>Create .env file in the same location as docker-compose.yml<pre><code>
|
||||
SQL_ROOT_PW=*PASSWORD*
|
||||
SQL_USER=*USER*
|
||||
@@ -26,18 +27,25 @@ CERTBOT_APP_DOMAIN=*APP_DOMAIN*
|
||||
CERTBOT_API_DOMAIN=*API_DOMAIN*
|
||||
CERTBOT_STORAGE_DOMAIN=*STORAGE_DOMAIN*
|
||||
CERTBOT_MONITOR_DOMAIN=*MONITOR_DOMAIN*
|
||||
CERTBOT_AI_DOMAIN=*AI_DOMAIN*</code></pre></li>
|
||||
CERTBOT_AI_DOMAIN=*AI_DOMAIN*
|
||||
|
||||
GITEA_SQL_ROOT_PW=*GITEA_SQL_ROOT_PW*
|
||||
GITEA_SQL_USER=*GITEA_SQL_USER*
|
||||
GITEA_SQL_PW=*GITEA_SQL_PW*
|
||||
GITEA_SQL_DB=*GITEA_SQL_DB*
|
||||
|
||||
WP_SQL_DB=*WP_SQL_DB*
|
||||
WP_SQL_ROOT_PW=*WP_SQL_ROOT_PW*
|
||||
WP_SQL_USER=*WP_SQL_USER*
|
||||
WP_SQL_USER_PW=*WP_SQL_USER_PW*
|
||||
</code></pre></li>
|
||||
<li>Configure MIH-AI.</li>
|
||||
<ol>
|
||||
<li>If your server hardware has an Nvidia GPU, follow the instructions below "How to enable MIH-AI GPU usage"</li>
|
||||
<li>If your server hardware does not use an Nvidia GPU, continue with the next step.</li>
|
||||
</ol>
|
||||
<li>Start MIH Server.</li>
|
||||
<ol>
|
||||
<li>Non-Prod: <pre><code>sudo docker compose up -d --build</code></pre></li>
|
||||
<li>Prod: <pre><code>sudo docker compose --profile prod up -d --build</code></pre></li>
|
||||
<li>Prod with Letsincrypt certificate Generation: <pre><code>sudo docker compose --profile prod --profile withCert up -d --build</code></pre></li>
|
||||
</ol>
|
||||
<pre><code>sudo docker compose up -d --build</code></pre>
|
||||
<li>Check the status of the new MIH server using Portainer. <code>https://localhost:9443/</code> (Change Local Host to IP if necessary).</li>
|
||||
<ol>
|
||||
<li>If all containers are running without errors, proceed to step 5<br>(<b>NOTE:</b> certbot container will stop after running successfully).</li>
|
||||
@@ -55,11 +63,7 @@ CERTBOT_AI_DOMAIN=*AI_DOMAIN*</code></pre></li>
|
||||
</ol>
|
||||
|
||||
<h2>How to Stop MIH Server:-</h2>
|
||||
<ol>
|
||||
<li>Non-Prod: disables Nginx & CertBot container creation.<pre><code>sudo docker compose down</code></pre></li>
|
||||
<li>Prod: <pre><code>sudo docker compose --profile prod down</code></pre></li>
|
||||
<li>Prod with Letsincrypt certificate Generation: <pre><code>sudo docker compose --profile prod --profile withCert down</code></pre></li>
|
||||
</ol>
|
||||
<pre><code>sudo docker compose down</code></pre>
|
||||
|
||||
<h2>How to enable MIH-AI GPU:-</h2>
|
||||
<ol>
|
||||
|
||||
3
backend/.gitignore
vendored
@@ -1,3 +0,0 @@
|
||||
.env
|
||||
__pycache__/
|
||||
temp*.pdf
|
||||
@@ -1,28 +0,0 @@
|
||||
# from supertokens_python import init, InputAppInfo, SupertokensConfig
|
||||
# from supertokens_python.recipe import emailpassword, session, dashboard
|
||||
|
||||
# init(
|
||||
# app_info=InputAppInfo(
|
||||
# app_name="MIH_API_HUB",
|
||||
# api_domain="http://localhost:8080/",
|
||||
# website_domain="http://mzansi-innovation-hub.co.za",
|
||||
# api_base_path="/auth",
|
||||
# website_base_path="/auth"
|
||||
# ),
|
||||
# supertokens_config=SupertokensConfig(
|
||||
# # https://try.supertokens.com is for demo purposes. Replace this with the address of your core instance (sign up on supertokens.com), or self host a core.
|
||||
# connection_uri="supertokens:3567/",
|
||||
# api_key="leatucczyixqwkqqdrhayiwzeofkltds"
|
||||
# ),
|
||||
# framework='fastapi',
|
||||
# recipe_list=[
|
||||
# # SuperTokens.init(),
|
||||
# session.init(), # initializes session features
|
||||
# emailpassword.init(),
|
||||
# dashboard.init(admins=[
|
||||
# "yasienmeth@gmail.com",
|
||||
# ],
|
||||
# )
|
||||
# ],
|
||||
# mode='wsgi' # use wsgi instead of asgi if you are running using gunicorn
|
||||
# )
|
||||
@@ -1,62 +1,86 @@
|
||||
#============== MIH Network ====================================================================
|
||||
networks:
|
||||
mih-network:
|
||||
driver: bridge
|
||||
#============== MIH Containers ====================================================================
|
||||
services:
|
||||
#============== API Hub ====================================================================
|
||||
api:
|
||||
build:
|
||||
context: ./backend
|
||||
target: builder
|
||||
container_name: MIH-API-Hub
|
||||
#command: sh -c "sleep 10s; uvicorn backend.main:app --reload --port=8080 --host=0.0.0.0"
|
||||
#============Dev=================
|
||||
# command: sh -c "sleep 10s; fastapi dev main.py --port 8080"
|
||||
#============prod=================
|
||||
#command: sh -c "sleep 10s; fastapi run backend/main.py --proxy-headers --port 8080"
|
||||
#============== Nginx Proxy Manager ====================================================================
|
||||
mih-nginx:
|
||||
container_name: mih-nginx
|
||||
image: 'jc21/nginx-proxy-manager:latest'
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- 8080:80
|
||||
- '80:80' # Public HTTP
|
||||
- '443:443' # Public HTTPS
|
||||
- '127.0.0.1:81:81' # Admin Web Port
|
||||
volumes:
|
||||
- ./backend:/app
|
||||
- ./mih_nginx/data:/data
|
||||
- ./mih_nginx/letsencrypt:/etc/letsencrypt
|
||||
networks:
|
||||
- MIH-network
|
||||
- mih-network
|
||||
#============== GITEA ====================================================================
|
||||
mih-gitea:
|
||||
image: gitea/gitea:latest
|
||||
container_name: mih-gitea
|
||||
environment:
|
||||
- USER_UID=1000
|
||||
- USER_GID=1000
|
||||
- GITEA__database__DB_TYPE=mysql
|
||||
- GITEA__database__HOST=mih-gitea-db:3306
|
||||
- GITEA__database__NAME=${GITEA_SQL_DB}
|
||||
- GITEA__database__USER=${GITEA_SQL_USER}
|
||||
- GITEA__database__PASSWD=${GITEA_SQL_PW}
|
||||
restart: always
|
||||
networks:
|
||||
- mih-network
|
||||
volumes:
|
||||
- ./mih_git/gitea:/data
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
ports:
|
||||
- "127.0.0.1:3000:3000"
|
||||
- "127.0.0.1:222:22"
|
||||
depends_on:
|
||||
- mysqldb
|
||||
#============== My SQL DB ====================================================================
|
||||
mysqldb:
|
||||
#build: ./database/
|
||||
platform: linux/amd64
|
||||
image: mysql:5.7
|
||||
container_name: MIH-Database
|
||||
mih-gitea-db:
|
||||
condition: service_healthy
|
||||
mih-gitea-db:
|
||||
image: mysql:8.0
|
||||
container_name: mih-gitea-db
|
||||
restart: always
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: ${SQL_ROOT_PW}
|
||||
MYSQL_USER: ${SQL_USER}
|
||||
MYSQL_PASSWORD: ${SQL_USER_PW}
|
||||
MYSQL_DATABASE: ${SUPERTOKENS_DB}
|
||||
- MYSQL_ROOT_PASSWORD=${GITEA_SQL_ROOT_PW}
|
||||
- MYSQL_USER=${GITEA_SQL_USER}
|
||||
- MYSQL_PASSWORD=${GITEA_SQL_PW}
|
||||
- MYSQL_DATABASE=${GITEA_SQL_DB}
|
||||
networks:
|
||||
- MIH-network
|
||||
ports:
|
||||
- '3306:3306'
|
||||
- mih-network
|
||||
volumes:
|
||||
- ./database:/var/lib/mysql
|
||||
- ./mih_git/mysql:/var/lib/mysql
|
||||
healthcheck:
|
||||
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
#============== Super Token Auth ====================================================================
|
||||
supertokens:
|
||||
container_name: MIH-SuperTokens
|
||||
mih-supertokens:
|
||||
container_name: mih-supertokens
|
||||
image: supertokens/supertokens-mysql:latest
|
||||
# image: registry.supertokens.io/supertokens/supertokens-mysql
|
||||
depends_on:
|
||||
- mysqldb
|
||||
- mih-db
|
||||
ports:
|
||||
- 3567:3567
|
||||
- '127.0.0.1:3567:3567'
|
||||
environment:
|
||||
REFRESH_TOKEN_VALIDITY: '604800'
|
||||
ACCESS_TOKEN_VALIDITY: '86400'
|
||||
PASSWORD_RESET_TOKEN_LIFETIME: '7200000'
|
||||
MYSQL_USER: ${SQL_USER}
|
||||
MYSQL_PASSWORD: ${SQL_USER_PW}
|
||||
MYSQL_HOST: mysqldb
|
||||
MYSQL_HOST: mih-db
|
||||
MYSQL_PORT: 3306
|
||||
MYSQL_DATABASE_NAME: ${SUPERTOKENS_DB}
|
||||
API_KEYS: ${SUPERTOKENS_API_KEY}
|
||||
networks:
|
||||
- MIH-network
|
||||
- mih-network
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: >
|
||||
@@ -64,103 +88,130 @@ services:
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
#============== MIH WordPress ====================================================================
|
||||
mih-wordpress:
|
||||
container_name: mih-wordpress
|
||||
image: wordpress
|
||||
restart: always
|
||||
ports:
|
||||
- '127.0.0.1:8081:80'
|
||||
environment:
|
||||
WORDPRESS_DB_HOST: mih-wp-db
|
||||
WORDPRESS_DB_USER: ${WP_SQL_USER}
|
||||
WORDPRESS_DB_PASSWORD: ${WP_SQL_USER_PW}
|
||||
WORDPRESS_DB_NAME: ${WP_SQL_DB}
|
||||
volumes:
|
||||
- ./mih_wp/ui:/var/www/html
|
||||
networks:
|
||||
- mih-network
|
||||
mih-wp-db:
|
||||
container_name: mih-wp-db
|
||||
image: mariadb:10.11
|
||||
restart: always
|
||||
environment:
|
||||
MARIADB_DATABASE: ${WP_SQL_DB}
|
||||
MARIADB_USER: ${WP_SQL_USER}
|
||||
MARIADB_PASSWORD: ${WP_SQL_USER_PW}
|
||||
MARIADB_RANDOM_ROOT_PASSWORD: '1'
|
||||
volumes:
|
||||
- ./mih_wp/database:/var/lib/mysql
|
||||
networks:
|
||||
- mih-network
|
||||
#============== MIH-UX Flutter ====================================================================
|
||||
mih-ux:
|
||||
container_name: mih-ux
|
||||
build:
|
||||
context: ./mih_ui
|
||||
ports:
|
||||
- "127.0.0.1:83:83"
|
||||
networks:
|
||||
- mih-network
|
||||
depends_on:
|
||||
- mih-api-hub
|
||||
#============== API Hub ====================================================================
|
||||
mih-api-hub:
|
||||
build:
|
||||
context: ./mih_api_hub
|
||||
target: builder
|
||||
container_name: mih-api-hub
|
||||
ports:
|
||||
- "127.0.0.1:8080:80"
|
||||
volumes:
|
||||
- ./mih_api_hub:/app
|
||||
networks:
|
||||
- mih-network
|
||||
depends_on:
|
||||
- mih-db
|
||||
#============== My SQL DB ====================================================================
|
||||
mih-db:
|
||||
platform: linux/amd64
|
||||
image: mysql:5.7
|
||||
container_name: mih-db
|
||||
restart: always
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: ${SQL_ROOT_PW}
|
||||
MYSQL_USER: ${SQL_USER}
|
||||
MYSQL_PASSWORD: ${SQL_USER_PW}
|
||||
MYSQL_DATABASE: ${SUPERTOKENS_DB}
|
||||
networks:
|
||||
- mih-network
|
||||
ports:
|
||||
- '127.0.0.1:3306:3306'
|
||||
volumes:
|
||||
- ./mih_db:/var/lib/mysql
|
||||
#============== PHP My Admin ====================================================================
|
||||
# phpmyadmin:
|
||||
# platform: linux/amd64
|
||||
# image: phpmyadmin/phpmyadmin
|
||||
# container_name: MIH-phpmyadmin
|
||||
# environment:
|
||||
# PMA_HOST: mysqlDB
|
||||
# PMA_HOST: mih-db
|
||||
# PMA_PORT: 3306
|
||||
# PMA_ARBITRARY:
|
||||
# networks:
|
||||
# - MIH-network
|
||||
# - mih-network
|
||||
# restart: always
|
||||
# ports:
|
||||
# - 8081:80
|
||||
# depends_on:
|
||||
# - mysqldb
|
||||
#============== Nginx Proxy Server ====================================================================
|
||||
nginx:
|
||||
container_name: nginx
|
||||
restart: unless-stopped
|
||||
image: nginx
|
||||
ports:
|
||||
- 80:80
|
||||
- 443:443
|
||||
volumes:
|
||||
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
|
||||
- certbotConf:/etc/letsencrypt
|
||||
- certbotChall:/var/www/certbot
|
||||
depends_on:
|
||||
- user-interface
|
||||
networks:
|
||||
- MIH-network
|
||||
profiles: [ 'prod' ]
|
||||
#============== MIH-UX Flutter ====================================================================
|
||||
user-interface:
|
||||
container_name: MIH-UX
|
||||
build:
|
||||
context: ./Frontend
|
||||
ports:
|
||||
- "83:83"
|
||||
networks:
|
||||
- MIH-network
|
||||
depends_on:
|
||||
- api
|
||||
#============== Cert Bot ====================================================================
|
||||
certbot:
|
||||
image: certbot/certbot
|
||||
container_name: certbot
|
||||
volumes:
|
||||
- certbotConf:/etc/letsencrypt
|
||||
- certbotChall:/var/www/certbot
|
||||
#command: certonly --test-cert --webroot -w /var/www/certbot --force-renewal --email yasienmeth@gmail.com -d mzansi-innovation-hub.co.za -d www.mzansi-innovation-hub.co.za --agree-tos
|
||||
command: certonly --webroot -w /var/www/certbot --force-renewal --email ${CERTBOT_EMAIL} -d ${CERTBOT_APP_DOMAIN} -d ${CERTBOT_API_DOMAIN} -d ${CERTBOT_STORAGE_DOMAIN} -d ${CERTBOT_MONITOR_DOMAIN} -d ${CERTBOT_AI_DOMAIN} --agree-tos
|
||||
networks:
|
||||
- MIH-network
|
||||
depends_on:
|
||||
- nginx
|
||||
profiles: [ 'withCert' ]
|
||||
# - mih-db
|
||||
#============== Minio File Storage ====================================================================
|
||||
minio:
|
||||
mih-minio:
|
||||
platform: linux/amd64
|
||||
container_name: MIH-Minio
|
||||
hostname: minio
|
||||
# image: docker.io/bitnami/minio:2022
|
||||
container_name: mih-minio
|
||||
hostname: mih-minio
|
||||
image: minio/minio
|
||||
ports:
|
||||
- '9000:9000'
|
||||
- '9001:9001'
|
||||
- '127.0.0.1:9000:9000'
|
||||
- '127.0.0.1:9001:9001'
|
||||
volumes:
|
||||
- './File_Storage:/data'
|
||||
- './mih_minio:/data'
|
||||
environment:
|
||||
MINIO_ROOT_USER: ${MINIO_ROOT_USER}
|
||||
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PW}
|
||||
networks:
|
||||
- MIH-network
|
||||
- mih-network
|
||||
command: ["server", "/data", "--console-address", ":9001"]
|
||||
#============== MIH-Monitor Portainer ====================================================================
|
||||
portainer:
|
||||
container_name: MIH-Monitor
|
||||
mih-monitor:
|
||||
container_name: mih-monitor
|
||||
image: portainer/portainer-ce:2.20.3
|
||||
ports:
|
||||
- 9444:9443
|
||||
- '127.0.0.1:9444:9443'
|
||||
volumes:
|
||||
- data:/data
|
||||
- ./mih_monitor/data:/data
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- MIH-network
|
||||
- mih-network
|
||||
#============== MIH-AI Ollama ====================================================================
|
||||
ollama:
|
||||
container_name: MIH-AI
|
||||
mih-ai:
|
||||
container_name: mih-ai
|
||||
image: ollama/ollama:latest
|
||||
ports:
|
||||
- 11434:11434
|
||||
- '127.0.0.1:11434:11434'
|
||||
volumes:
|
||||
# - ./Mzansi_AI:/code
|
||||
- ./Mzansi_AI/ollama/ollama:/root/.ollama
|
||||
- ./mih_ai/ollama/ollama:/root/.ollama
|
||||
pull_policy: always
|
||||
tty: true
|
||||
restart: always
|
||||
@@ -169,16 +220,16 @@ services:
|
||||
- OLLAMA_KEEP_ALIVE=24h
|
||||
- OLLAMA_HOST=0.0.0.0
|
||||
networks:
|
||||
- MIH-network
|
||||
- mih-network
|
||||
# === Added section for NVIDIA GPU acceleration ===
|
||||
runtime: nvidia
|
||||
deploy:
|
||||
resources:
|
||||
reservations:
|
||||
devices:
|
||||
- driver: nvidia
|
||||
count: all # or specify a number of GPUs
|
||||
capabilities: [ gpu ]
|
||||
# runtime: nvidia
|
||||
# deploy:
|
||||
# resources:
|
||||
# reservations:
|
||||
# devices:
|
||||
# - driver: nvidia
|
||||
# count: all # or specify a number of GPUs
|
||||
# capabilities: [ gpu ]
|
||||
#============== Firebaase ====================================================================
|
||||
# firebase:
|
||||
# container_name: MIH-firebase-emulator
|
||||
@@ -198,11 +249,3 @@ services:
|
||||
# # - ./cache:/root/.cache/:rw
|
||||
# # - ~/.config/:/root/.config
|
||||
# - ./Firebase-emulator/firebase/data:/srv/firebase/data:rw
|
||||
#============== Named Volumes ====================================================================
|
||||
volumes:
|
||||
certbotConf:
|
||||
certbotChall:
|
||||
data: #============== MIH Network ====================================================================
|
||||
networks:
|
||||
MIH-network:
|
||||
driver: bridge
|
||||
|
||||
BIN
backend/.DS_Store → mih_api_hub/.DS_Store
vendored
4
mih_api_hub/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
.env
|
||||
__pycache__/
|
||||
temp*.pdf
|
||||
.DS_Store
|
||||
@@ -9,7 +9,7 @@ minioSecret = os.getenv("MINIO_SECRET_KEY")
|
||||
def minioConnect(env):
|
||||
if(env == "Dev"):
|
||||
return Minio(
|
||||
"minio:9000",
|
||||
endpoint="mih-minio:9000",
|
||||
# "minio.mzansi-innovation-hub.co.za",
|
||||
access_key=minioAccess,
|
||||
secret_key=minioSecret,
|
||||
@@ -17,8 +17,8 @@ def minioConnect(env):
|
||||
)
|
||||
else:
|
||||
return Minio(
|
||||
#"minio:9000",
|
||||
"minio.mzansi-innovation-hub.co.za",
|
||||
# endpoint="mih-minio:9000",
|
||||
endpoint="minio.mzansi-innovation-hub.co.za",
|
||||
access_key=minioAccess,
|
||||
secret_key=minioSecret,
|
||||
secure=True
|
||||
@@ -34,28 +34,36 @@ from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.emailverification import EmailVerificationClaim
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
st_api_key = os.getenv("SUPERTOKENS_API_KEY")
|
||||
origins = [
|
||||
"http://localhost",
|
||||
"http://localhost:80",
|
||||
"http://localhost:1995",
|
||||
"http://localhost:8080",
|
||||
"http://MIH-API-Hub:80",
|
||||
"http://MIH-API-Hub",
|
||||
"http://api.mzansi-innovation-hub.co.za",
|
||||
"*",
|
||||
"http://app.mzansi-innovation-hub.co.za",
|
||||
"https://api.mzansi-innovation-hub.co.za",
|
||||
"https://app.mzansi-innovation-hub.co.za",
|
||||
]
|
||||
|
||||
init(
|
||||
app_info=InputAppInfo(
|
||||
app_name="Mzansi Innovation Hub",
|
||||
api_domain="http://localhost:8080/",
|
||||
website_domain="http://app.mzansi-innovation-hub.co.za",
|
||||
website_domain="https://app.mzansi-innovation-hub.co.za",
|
||||
api_base_path="/auth",
|
||||
website_base_path="/auth"
|
||||
),
|
||||
supertokens_config=SupertokensConfig(
|
||||
# https://try.supertokens.com is for demo purposes. Replace this with the address of your core instance (sign up on supertokens.com), or self host a core.
|
||||
connection_uri="http://MIH-SuperTokens:3567/",
|
||||
api_key="leatucczyixqwkqqdrhayiwzeofkltds"
|
||||
connection_uri="http://mih-supertokens:3567/",
|
||||
api_key=st_api_key
|
||||
),
|
||||
framework='fastapi',
|
||||
recipe_list=[
|
||||
@@ -8,7 +8,7 @@ dbPass = os.getenv("DB_PASSWD")
|
||||
|
||||
def dbPatientManagerConnect():
|
||||
return mysql.connector.connect(
|
||||
host="mysqldb",
|
||||
host="mih-db",
|
||||
user=dbUser,
|
||||
passwd=dbPass,
|
||||
database="patient_manager"
|
||||
@@ -16,7 +16,7 @@ def dbPatientManagerConnect():
|
||||
|
||||
def dbAppDataConnect():
|
||||
return mysql.connector.connect(
|
||||
host="mysqldb",
|
||||
host="mih-db",
|
||||
user=dbUser,
|
||||
passwd=dbPass,
|
||||
database="app_data"
|
||||
@@ -24,7 +24,7 @@ def dbAppDataConnect():
|
||||
|
||||
def dbDataAccessConnect():
|
||||
return mysql.connector.connect(
|
||||
host="mysqldb",
|
||||
host="mih-db",
|
||||
user=dbUser,
|
||||
passwd=dbPass,
|
||||
database="data_access"
|
||||
@@ -32,7 +32,7 @@ def dbDataAccessConnect():
|
||||
|
||||
def dbMzansiWalletConnect():
|
||||
return mysql.connector.connect(
|
||||
host="mysqldb",
|
||||
host="mih-db",
|
||||
user=dbUser,
|
||||
passwd=dbPass,
|
||||
database="mzansi_wallet"
|
||||
@@ -40,7 +40,7 @@ def dbMzansiWalletConnect():
|
||||
|
||||
def dbMzansiDirectoryConnect():
|
||||
return mysql.connector.connect(
|
||||
host="mysqldb",
|
||||
host="mih-db",
|
||||
user=dbUser,
|
||||
passwd=dbPass,
|
||||
database="mzansi_directory"
|
||||
@@ -48,7 +48,7 @@ def dbMzansiDirectoryConnect():
|
||||
|
||||
def dbMzansiCalendarConnect():
|
||||
return mysql.connector.connect(
|
||||
host="mysqldb",
|
||||
host="mih-db",
|
||||
user=dbUser,
|
||||
passwd=dbPass,
|
||||
database="mzansi_calendar"
|
||||
@@ -56,7 +56,7 @@ def dbMzansiCalendarConnect():
|
||||
|
||||
def dbAllConnect():
|
||||
return mysql.connector.connect(
|
||||
host="mysqldb",
|
||||
host="mih-db",
|
||||
user=dbUser,
|
||||
passwd=dbPass,
|
||||
)
|
||||
@@ -7,7 +7,7 @@ from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
dbUser = os.getenv("DB_USER")
|
||||
dbPass = os.getenv("DB_PASSWD")
|
||||
dbHost = "mysqldb"
|
||||
dbHost = "mih-db"
|
||||
dbPort = 3306
|
||||
encoded_dbPass = quote_plus(dbPass)
|
||||
base_connect_url = f"mysql+mysqlconnector://{dbUser}:{encoded_dbPass}@{dbHost}:{dbPort}/"
|
||||
@@ -15,7 +15,7 @@ base_connect_url = f"mysql+mysqlconnector://{dbUser}:{encoded_dbPass}@{dbHost}:{
|
||||
def dbPatientManagerConnect():
|
||||
return create_engine(base_connect_url+"patient_manager", echo=False, pool_recycle=3600)
|
||||
# return mysql.connector.connect(
|
||||
# host="mysqldb",
|
||||
# host="mih-db",
|
||||
# user=dbUser,
|
||||
# passwd=dbPass,
|
||||
# database="patient_manager"
|
||||
@@ -24,7 +24,7 @@ def dbPatientManagerConnect():
|
||||
def dbAppDataConnect():
|
||||
return create_engine(base_connect_url+"app_data", echo=False, pool_recycle=3600)
|
||||
# return mysql.connector.connect(
|
||||
# host="mysqldb",
|
||||
# host="mih-db",
|
||||
# user=dbUser,
|
||||
# passwd=dbPass,
|
||||
# database="app_data"
|
||||
@@ -33,7 +33,7 @@ def dbAppDataConnect():
|
||||
def dbDataAccessConnect():
|
||||
return create_engine(base_connect_url+"data_access", echo=False, pool_recycle=3600)
|
||||
# return mysql.connector.connect(
|
||||
# host="mysqldb",
|
||||
# host="mih-db",
|
||||
# user=dbUser,
|
||||
# passwd=dbPass,
|
||||
# database="data_access"
|
||||
@@ -42,7 +42,7 @@ def dbDataAccessConnect():
|
||||
def dbMzansiWalletConnect():
|
||||
return create_engine(base_connect_url+"mzansi_wallet", echo=False, pool_recycle=3600)
|
||||
# return mysql.connector.connect(
|
||||
# host="mysqldb",
|
||||
# host="mih-db",
|
||||
# user=dbUser,
|
||||
# passwd=dbPass,
|
||||
# database="mzansi_wallet"
|
||||
@@ -51,7 +51,7 @@ def dbMzansiWalletConnect():
|
||||
def dbMzansiDirectoryConnect():
|
||||
return create_engine(base_connect_url+"mzansi_directory", echo=False, pool_recycle=3600)
|
||||
# return mysql.connector.connect(
|
||||
# host="mysqldb",
|
||||
# host="mih-db",
|
||||
# user=dbUser,
|
||||
# passwd=dbPass,
|
||||
# database="mzansi_directory"
|
||||
@@ -60,7 +60,7 @@ def dbMzansiDirectoryConnect():
|
||||
def dbMzansiCalendarConnect():
|
||||
return create_engine(base_connect_url+"mzansi_calendar", echo=False, pool_recycle=3600)
|
||||
# return mysql.connector.connect(
|
||||
# host="mysqldb",
|
||||
# host="mih-db",
|
||||
# user=dbUser,
|
||||
# passwd=dbPass,
|
||||
# database="mzansi_calendar"
|
||||
@@ -69,7 +69,7 @@ def dbMzansiCalendarConnect():
|
||||
def dbAllConnect():
|
||||
return create_engine(base_connect_url, echo=False, pool_recycle=3600)
|
||||
# return mysql.connector.connect(
|
||||
# host="mysqldb",
|
||||
# host="mih-db",
|
||||
# user=dbUser,
|
||||
# passwd=dbPass,
|
||||
# )
|
||||
@@ -9,4 +9,5 @@ watchfiles
|
||||
python-multipart
|
||||
python-dotenv
|
||||
xlrd
|
||||
supertokens-python==0.29.2
|
||||
supertokens-python==0.24.0
|
||||
sniffio
|
||||
0
mih_api_hub/routers/__init__.py
Normal file
@@ -22,6 +22,7 @@ from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
|
||||
import Minio_Storage.minioConnection
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
@@ -110,13 +111,21 @@ class claimStatementUploud(BaseModel):
|
||||
@router.get("/minio/pull/file/{env}/{app_id}/{folder}/{file_name}", tags=["Minio"])
|
||||
async def pull_File_from_user(app_id: str, folder: str, file_name: str, env: str): #, session: SessionContainer = Depends(verify_session())
|
||||
path = app_id + "/" + folder + "/" + file_name
|
||||
print(path)
|
||||
try:
|
||||
# print(f"env: {env}")
|
||||
# uploudFile(app_id, file.filename, extension[1], content)
|
||||
|
||||
client = Minio_Storage.minioConnection.minioConnect(env)
|
||||
|
||||
miniourl = client.presigned_get_object("mih", path)
|
||||
# buckets = client.list_buckets()
|
||||
# print("Connected to MinIO successfully!")
|
||||
# print("Available buckets:", [bucket.name for bucket in buckets])
|
||||
miniourl = client.presigned_get_object(
|
||||
bucket_name="mih",
|
||||
object_name=path,
|
||||
expires=timedelta(minutes=60)
|
||||
)
|
||||
print("Generated presigned URL:", miniourl)
|
||||
# if(env == "Dev"):
|
||||
# miniourl.replace("minio", "localhost")
|
||||
# temp = minioResponse.data#.encode('utf-8').strip()
|
||||
@@ -125,7 +134,7 @@ async def pull_File_from_user(app_id: str, folder: str, file_name: str, env: str
|
||||
# temp = temp.decode('utf-8')
|
||||
#print(miniourl)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail=miniourl)
|
||||
raise HTTPException(status_code=404, detail=f"MinIO connection failed: {str(error)}")
|
||||
# return {"message": error}
|
||||
if(env == "Dev"):
|
||||
return {
|
||||
@@ -144,7 +153,7 @@ async def upload_File_to_user(file: UploadFile = File(...), app_id: str= Form(..
|
||||
try:
|
||||
uploudFile(app_id, env, folder, file.filename.replace(" ", "-"), extension[1], content)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail="Failed to Uploud Record")
|
||||
raise HTTPException(status_code=404, detail=str(error))
|
||||
return {"message": f"Successfully Uploaded {file.filename}"}
|
||||
|
||||
# return {
|
||||
@@ -161,7 +170,10 @@ async def delete_File_of_user(requestItem: minioDeleteRequest, session: SessionC
|
||||
# uploudFile(app_id, file.filename, extension[1], content)
|
||||
client = Minio_Storage.minioConnection.minioConnect(requestItem.env)
|
||||
|
||||
minioError = client.remove_object("mih", path)
|
||||
minioError = client.remove_object(
|
||||
bucket_name="mih",
|
||||
object_name=path
|
||||
)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail=minioError)
|
||||
# return {"message": error}
|
||||
@@ -191,15 +203,16 @@ async def upload_perscription_to_user(requestItem: claimStatementUploud, session
|
||||
|
||||
def uploudFile(app_id, env, folder, fileName, extension, content):
|
||||
client = Minio_Storage.minioConnection.minioConnect(env)
|
||||
found = client.bucket_exists("mih")
|
||||
found = client.bucket_exists(bucket_name="mih")
|
||||
if not found:
|
||||
client.make_bucket("mih")
|
||||
client.make_bucket(bucket_name="mih")
|
||||
else:
|
||||
print("Bucket already exists")
|
||||
fname = app_id + "/" + folder + "/" + fileName
|
||||
client.put_object("mih",
|
||||
fname,
|
||||
content,
|
||||
client.put_object(
|
||||
bucket_name="mih",
|
||||
object_name=fname,
|
||||
data=content,
|
||||
length=-1,
|
||||
part_size=10*1024*1024,
|
||||
content_type=f"application/{extension}")
|
||||
@@ -208,9 +221,9 @@ def uploudMedCert(requestItem: medCertUploud):
|
||||
client = Minio_Storage.minioConnection.minioConnect(requestItem.env)
|
||||
generateMedCertPDF(requestItem)
|
||||
today = datetime.today().strftime('%Y-%m-%d')
|
||||
found = client.bucket_exists("mih")
|
||||
found = client.bucket_exists(bucket_name="mih")
|
||||
if not found:
|
||||
client.make_bucket("mih")
|
||||
client.make_bucket(bucket_name="mih")
|
||||
else:
|
||||
print("Bucket already exists")
|
||||
fileName = f"{requestItem.app_id}/patient_files/{requestItem.fileName}"
|
||||
@@ -285,9 +298,9 @@ def uploudPerscription(requestItem: perscriptionList):
|
||||
client = Minio_Storage.minioConnection.minioConnect(requestItem.env)
|
||||
generatePerscriptionPDF(requestItem)
|
||||
today = datetime.today().strftime('%Y-%m-%d')
|
||||
found = client.bucket_exists("mih")
|
||||
found = client.bucket_exists(bucket_name="mih")
|
||||
if not found:
|
||||
client.make_bucket("mih")
|
||||
client.make_bucket(bucket_name="mih")
|
||||
else:
|
||||
print("Bucket already exists")
|
||||
fileName = f"{requestItem.app_id}/patient_files/{requestItem.fileName}"
|
||||
@@ -391,9 +404,9 @@ def uploudClaimStatement(requestItem: claimStatementUploud):
|
||||
|
||||
generateClaimStatementPDF(requestItem)
|
||||
today = datetime.today().strftime('%Y-%m-%d')
|
||||
found = client.bucket_exists("mih")
|
||||
found = client.bucket_exists(bucket_name="mih")
|
||||
if not found:
|
||||
client.make_bucket("mih")
|
||||
client.make_bucket(bucket_name="mih")
|
||||
else:
|
||||
print("Bucket already exists")
|
||||
fileName = f"{requestItem.patient_app_id}/claims-statements/{requestItem.fileName}"
|
||||