forked from yaso_meth/mih-project
Merge pull request #72 from yaso-meth/BUG-Theme-link-to-system-theme
BUG-Theme-link-to-system-theme-and-error-page-enhancement
This commit is contained in:
@@ -18,7 +18,6 @@ class MzanziInnovationHub extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MzanziInnovationHubState extends State<MzanziInnovationHub> {
|
||||
late ThemeMode _themeMode;
|
||||
late MihTheme theme;
|
||||
|
||||
Color getPrimany() {
|
||||
@@ -35,12 +34,11 @@ class _MzanziInnovationHubState extends State<MzanziInnovationHub> {
|
||||
|
||||
void changeTheme(ThemeMode themeMode) {
|
||||
setState(() {
|
||||
_themeMode = themeMode;
|
||||
if (_themeMode == ThemeMode.light) {
|
||||
if (themeMode == ThemeMode.light) {
|
||||
setState(() {
|
||||
theme.mode = "Light";
|
||||
});
|
||||
} else if (_themeMode == ThemeMode.dark) {
|
||||
} else if (themeMode == ThemeMode.dark) {
|
||||
setState(() {
|
||||
theme.mode = "Dark";
|
||||
});
|
||||
@@ -60,10 +58,8 @@ class _MzanziInnovationHubState extends State<MzanziInnovationHub> {
|
||||
bool isDarkMode = systemTheme == Brightness.dark;
|
||||
if (isDarkMode) {
|
||||
theme.mode = "Dark";
|
||||
_themeMode = ThemeMode.dark;
|
||||
} else {
|
||||
theme.mode = "Light";
|
||||
_themeMode = ThemeMode.light;
|
||||
}
|
||||
|
||||
theme.platform = Theme.of(context).platform;
|
||||
@@ -80,7 +76,7 @@ class _MzanziInnovationHubState extends State<MzanziInnovationHub> {
|
||||
precacheImage(theme.logoFrame(), context);
|
||||
return MaterialApp(
|
||||
title: getTitle(),
|
||||
themeMode: _themeMode,
|
||||
themeMode: ThemeMode.system,
|
||||
theme: theme.getThemeData(),
|
||||
darkTheme: theme.getThemeData(),
|
||||
debugShowCheckedModeBanner: false,
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import 'package:Mzansi_Innovation_Hub/main.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_button.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_package/mih-app_tool_body.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_package/mih_app.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_package/mih_app_action.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_package/mih_app_tools.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../mih_apis/mih_api_calls.dart';
|
||||
import '../../mih_components/mih_layout/mih_action.dart';
|
||||
import '../../mih_components/mih_layout/mih_body.dart';
|
||||
import '../../mih_components/mih_layout/mih_header.dart';
|
||||
import '../../mih_components/mih_layout/mih_layout_builder.dart';
|
||||
import '../../mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
||||
import '../../mih_env/env.dart';
|
||||
import '../../mih_objects/app_user.dart';
|
||||
@@ -31,6 +33,7 @@ class _MIHProfileGetterState extends State<MIHProfileGetter> {
|
||||
|
||||
String proPicUrl = "empty";
|
||||
ImageProvider<Object>? propicFile;
|
||||
int _selcetedIndex = 0;
|
||||
|
||||
ImageProvider<Object>? isPictureAvailable(String url) {
|
||||
if (url == "") {
|
||||
@@ -74,6 +77,150 @@ class _MIHProfileGetterState extends State<MIHProfileGetter> {
|
||||
}
|
||||
}
|
||||
|
||||
MihAppTools getErrorTools() {
|
||||
Map<Widget, void Function()?> temp = {};
|
||||
temp[const Icon(Icons.power_off_outlined)] = () {
|
||||
setState(() {
|
||||
_selcetedIndex = 0;
|
||||
});
|
||||
};
|
||||
|
||||
return MihAppTools(
|
||||
tools: temp,
|
||||
selcetedIndex: _selcetedIndex,
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> getErrorToolBody(String error) {
|
||||
List<Widget> toolBodies = [
|
||||
MihAppToolBody(
|
||||
borderOn: true,
|
||||
bodyItem: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"Connection Error",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
fontSize: 35,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.power_off_outlined,
|
||||
size: 150,
|
||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
),
|
||||
SizedBox(
|
||||
width: 500,
|
||||
child: Text(
|
||||
"Looks like we ran into an issue getting your data.\nPlease check you internet connection and try again.",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color:
|
||||
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
MIHButton(
|
||||
onTap: () {
|
||||
Navigator.of(context).popAndPushNamed("/");
|
||||
},
|
||||
buttonText: "Refresh",
|
||||
buttonColor:
|
||||
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
textColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: SizedBox(
|
||||
width: 500,
|
||||
child: SelectionArea(
|
||||
child: Text(
|
||||
"Error: $error",
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
color:
|
||||
MzanziInnovationHub.of(context)!.theme.errorColor(),
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
];
|
||||
return toolBodies;
|
||||
}
|
||||
|
||||
Widget errorPage(String error) {
|
||||
return MihApp(
|
||||
appActionButton: MihAppAction(
|
||||
icon: const Icon(Icons.refresh),
|
||||
iconSize: 35,
|
||||
onTap: () {
|
||||
Navigator.of(context).popAndPushNamed("/");
|
||||
},
|
||||
),
|
||||
appTools: getErrorTools(),
|
||||
appBody: getErrorToolBody(error),
|
||||
selectedbodyIndex: _selcetedIndex,
|
||||
onIndexChange: (newValue) {
|
||||
setState(() {
|
||||
_selcetedIndex = newValue;
|
||||
});
|
||||
//print("Index: $_selcetedIndex");
|
||||
},
|
||||
);
|
||||
// return MIHLayoutBuilder(
|
||||
// actionButton: MIHAction(
|
||||
// icon: const Icon(Icons.refresh),
|
||||
// iconSize: 35,
|
||||
// onTap: () {
|
||||
// Navigator.of(context).popAndPushNamed("/");
|
||||
// },
|
||||
// ),
|
||||
// header: const MIHHeader(
|
||||
// headerAlignment: MainAxisAlignment.center,
|
||||
// headerItems: [
|
||||
// Text(
|
||||
// "Mzanzi Innovation Hub",
|
||||
// style: TextStyle(
|
||||
// fontWeight: FontWeight.bold,
|
||||
// fontSize: 20,
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// secondaryActionButton: null,
|
||||
// body: MIHBody(
|
||||
// borderOn: false,
|
||||
// bodyItems: [
|
||||
// Align(
|
||||
// alignment: Alignment.center,
|
||||
// child: Text(
|
||||
// '$error occurred',
|
||||
// style: const TextStyle(fontSize: 18),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// actionDrawer: null,
|
||||
// secondaryActionDrawer: null,
|
||||
// bottomNavBar: null,
|
||||
// pullDownToRefresh: false,
|
||||
// onPullDown: () async {},
|
||||
// );
|
||||
}
|
||||
|
||||
// <a href="https://www.flaticon.com/free-icons/dont-know" title="dont know icons">Dont know icons created by Freepik - Flaticon</a>
|
||||
@override
|
||||
void dispose() {
|
||||
@@ -109,44 +256,7 @@ class _MIHProfileGetterState extends State<MIHProfileGetter> {
|
||||
personalSelected: widget.personalSelected,
|
||||
);
|
||||
} else {
|
||||
return MIHLayoutBuilder(
|
||||
actionButton: MIHAction(
|
||||
icon: const Icon(Icons.refresh),
|
||||
iconSize: 35,
|
||||
onTap: () {
|
||||
Navigator.of(context).popAndPushNamed("/");
|
||||
},
|
||||
),
|
||||
header: const MIHHeader(
|
||||
headerAlignment: MainAxisAlignment.center,
|
||||
headerItems: [
|
||||
Text(
|
||||
"Mzanzi Innovation Hub",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
secondaryActionButton: null,
|
||||
body: MIHBody(
|
||||
borderOn: false,
|
||||
bodyItems: [
|
||||
Center(
|
||||
child: Text(
|
||||
'${snapshot.error} occurred',
|
||||
style: const TextStyle(fontSize: 18),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
actionDrawer: null,
|
||||
secondaryActionDrawer: null,
|
||||
bottomNavBar: null,
|
||||
pullDownToRefresh: false,
|
||||
onPullDown: () async {},
|
||||
);
|
||||
return errorPage(snapshot.error.toString());
|
||||
}
|
||||
}
|
||||
return const Mihloadingcircle();
|
||||
|
||||
Reference in New Issue
Block a user