fix null error when in full screen window

This commit is contained in:
Yasien Mac Mini 2026-05-25 11:18:32 +02:00
parent 3b031b854b
commit 3a7abe6102
5 changed files with 89 additions and 52 deletions

View file

@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## 0.0.6
* Fix null value error thrown in `MihPackageWindow` while in full screen mode.
## 0.0.5 ## 0.0.5
* Add new icons to MihIcons pt2. * Add new icons to MihIcons pt2.

View file

@ -97,6 +97,25 @@ class _ExampleMihPackageState extends State<ExampleMihPackage> {
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Icon(MihIcons.link),
MihButton(
width: 300,
onPressed: () {
showDialog(
context: context,
builder: (context) => MihPackageWindow(
fullscreen: true,
windowTitle: "Full Screen Test",
onWindowTapClose: () {
Navigator.pop(context);
},
windowBody: Placeholder(),
),
);
},
buttonColor: MihColors.green(),
child: Text("Press"),
),
], ],
), ),
), ),

View file

@ -209,7 +209,7 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "0.0.5" version: "0.0.6"
path: path:
dependency: transitive dependency: transitive
description: description:

View file

@ -79,37 +79,52 @@ class MihPackageWindow extends StatefulWidget {
} }
class _MihPackageWindowState extends State<MihPackageWindow> { class _MihPackageWindowState extends State<MihPackageWindow> {
late double windowTitleSize; // late double windowTitleSize;
late double horizontralWindowPadding; // late double horizontralWindowPadding;
late double verticalWindowPadding; // late double verticalWindowPadding;
late double windowWidth; // late double windowWidth;
late double windowHeight; // late double windowHeight;
late double width; // late double width;
late double height; // late double height;
//
void checkScreenSize(Size screenSize) { // void checkScreenSize(Size screenSize) {
// print("screen width: $width"); // // print("screen width: $width");
// print("screen height: $height"); // // print("screen height: $height");
// if (screenSize.width > 800) {
// setState(() {
// windowTitleSize = 25;
// horizontralWindowPadding = width / 7;
// verticalWindowPadding = 10;
// windowWidth = width;
// windowHeight = height;
// });
// } else {
// setState(() {
// windowTitleSize = 20;
// horizontralWindowPadding = 10;
// verticalWindowPadding = 10;
// windowWidth = width;
// windowHeight = height;
// });
// }
// }
Map<String, double> _getResponsiveDimensions(Size screenSize) {
if (screenSize.width > 800) { if (screenSize.width > 800) {
setState(() { return {
windowTitleSize = 25; 'titleSize': 25.0,
horizontralWindowPadding = width / 7; 'horizontalPadding': screenSize.width / 7,
verticalWindowPadding = 10; 'verticalPadding': 10.0,
windowWidth = width; };
windowHeight = height;
});
} else { } else {
setState(() { return {
windowTitleSize = 20; 'titleSize': 20.0,
horizontralWindowPadding = 10; 'horizontalPadding': 10.0,
verticalWindowPadding = 10; 'verticalPadding': 10.0,
windowWidth = width; };
windowHeight = height;
});
} }
} }
Widget getHeader() { Widget getHeader(double titleSize) {
return Row( return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
@ -138,10 +153,9 @@ class _MihPackageWindowState extends State<MihPackageWindow> {
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
fontSize: windowTitleSize, fontSize: titleSize,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: color: widget.foregroundColor ??
widget.foregroundColor ??
MihColors.secondary(darkMode: widget.darkMode), MihColors.secondary(darkMode: widget.darkMode),
), ),
), ),
@ -178,45 +192,45 @@ class _MihPackageWindowState extends State<MihPackageWindow> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var size = MediaQuery.of(context).size; var size = MediaQuery.of(context).size;
setState(() { final dimensions = _getResponsiveDimensions(size);
width = size.width;
height = size.height; final double titleSize = dimensions['titleSize']!;
}); final double horizontalPadding = dimensions['horizontalPadding']!;
checkScreenSize(size); final double verticalPadding = dimensions['verticalPadding']!;
final bool isScrollbarOn = widget.scrollbarOn ?? false;
return Dialog( return Dialog(
insetPadding: EdgeInsets.symmetric( insetPadding: EdgeInsets.symmetric(
horizontal: horizontralWindowPadding, horizontal: horizontalPadding,
vertical: verticalWindowPadding, vertical: verticalPadding,
), ),
insetAnimationCurve: Easing.emphasizedDecelerate, insetAnimationCurve: Easing.emphasizedDecelerate,
insetAnimationDuration: Durations.short1, insetAnimationDuration: Durations.short1,
child: Material( child: Material(
elevation: 10, elevation: 10,
shadowColor: Colors.black, shadowColor: Colors.black,
color: color: widget.backgroundColor ??
widget.backgroundColor ??
MihColors.primary(darkMode: widget.darkMode), MihColors.primary(darkMode: widget.darkMode),
borderRadius: BorderRadius.circular(25.0), borderRadius: BorderRadius.circular(25.0),
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25.0), borderRadius: BorderRadius.circular(25.0),
border: widget.borderOn == null || !widget.borderOn! border: widget.borderOn == true
? null ? Border.all(
: Border.all( color: widget.foregroundColor ??
color:
widget.foregroundColor ??
MihColors.secondary(darkMode: widget.darkMode), MihColors.secondary(darkMode: widget.darkMode),
width: 5.0, width: 5.0,
), )
: null,
), ),
child: widget.fullscreen child: widget.fullscreen
? Column( ? Column(
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: [ children: [
getHeader(), getHeader(titleSize),
const SizedBox(height: 5), const SizedBox(height: 5),
Expanded( Expanded(
child: widget.scrollbarOn != null || !widget.scrollbarOn! child: !isScrollbarOn
? widget.windowBody ? widget.windowBody
: MihSingleChildScroll( : MihSingleChildScroll(
scrollbarOn: true, scrollbarOn: true,
@ -228,19 +242,19 @@ class _MihPackageWindowState extends State<MihPackageWindow> {
: Column( : Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
getHeader(), getHeader(titleSize),
const SizedBox(height: 5), const SizedBox(height: 5),
Flexible( Flexible(
child: Padding( child: Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(
left: 25, left: 25,
right: 25, right: 25,
bottom: verticalWindowPadding, bottom: verticalPadding,
), ),
child: ConstrainedBox( child: ConstrainedBox(
constraints: BoxConstraints( constraints: BoxConstraints(
maxHeight: windowHeight * 0.85, maxHeight: size.height * 0.85,
maxWidth: windowWidth * 0.85, maxWidth: size.width * 0.85,
), ),
child: MihSingleChildScroll( child: MihSingleChildScroll(
scrollbarOn: true, scrollbarOn: true,

View file

@ -1,6 +1,6 @@
name: mih_package_toolkit name: mih_package_toolkit
description: "A comprehensive UI toolkit and utility library for building consistent MIH Packages within the MIH Project ecosystem." description: "A comprehensive UI toolkit and utility library for building consistent MIH Packages within the MIH Project ecosystem."
version: 0.0.5 version: 0.0.6
homepage: https://git.mzansi-innovation-hub.co.za/yaso_meth/mih_package_toolkit homepage: https://git.mzansi-innovation-hub.co.za/yaso_meth/mih_package_toolkit
repository: https://git.mzansi-innovation-hub.co.za/yaso_meth/mih_package_toolkit repository: https://git.mzansi-innovation-hub.co.za/yaso_meth/mih_package_toolkit
issue_tracker: https://git.mzansi-innovation-hub.co.za/yaso_meth/mih_package_toolkit/issues issue_tracker: https://git.mzansi-innovation-hub.co.za/yaso_meth/mih_package_toolkit/issues