diff --git a/CHANGELOG.md b/CHANGELOG.md index fbc8d68..2aafee1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ 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 * Add new icons to MihIcons pt2. diff --git a/example/lib/main.dart b/example/lib/main.dart index 3727b55..9e9caa9 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -97,6 +97,25 @@ class _ExampleMihPackageState extends State { 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"), + ), ], ), ), diff --git a/example/pubspec.lock b/example/pubspec.lock index 463195b..8080e11 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -209,7 +209,7 @@ packages: path: ".." relative: true source: path - version: "0.0.5" + version: "0.0.6" path: dependency: transitive description: diff --git a/lib/src/mih_package_window.dart b/lib/src/mih_package_window.dart index 8dafa6d..73c0f1c 100644 --- a/lib/src/mih_package_window.dart +++ b/lib/src/mih_package_window.dart @@ -79,37 +79,52 @@ class MihPackageWindow extends StatefulWidget { } class _MihPackageWindowState extends State { - late double windowTitleSize; - late double horizontralWindowPadding; - late double verticalWindowPadding; - late double windowWidth; - late double windowHeight; - late double width; - late double height; - - void checkScreenSize(Size screenSize) { - // print("screen width: $width"); - // print("screen height: $height"); + // late double windowTitleSize; + // late double horizontralWindowPadding; + // late double verticalWindowPadding; + // late double windowWidth; + // late double windowHeight; + // late double width; + // late double height; + // + // void checkScreenSize(Size screenSize) { + // // print("screen width: $width"); + // // 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 _getResponsiveDimensions(Size screenSize) { if (screenSize.width > 800) { - setState(() { - windowTitleSize = 25; - horizontralWindowPadding = width / 7; - verticalWindowPadding = 10; - windowWidth = width; - windowHeight = height; - }); + return { + 'titleSize': 25.0, + 'horizontalPadding': screenSize.width / 7, + 'verticalPadding': 10.0, + }; } else { - setState(() { - windowTitleSize = 20; - horizontralWindowPadding = 10; - verticalWindowPadding = 10; - windowWidth = width; - windowHeight = height; - }); + return { + 'titleSize': 20.0, + 'horizontalPadding': 10.0, + 'verticalPadding': 10.0, + }; } } - Widget getHeader() { + Widget getHeader(double titleSize) { return Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, @@ -138,10 +153,9 @@ class _MihPackageWindowState extends State { overflow: TextOverflow.ellipsis, textAlign: TextAlign.center, style: TextStyle( - fontSize: windowTitleSize, + fontSize: titleSize, fontWeight: FontWeight.bold, - color: - widget.foregroundColor ?? + color: widget.foregroundColor ?? MihColors.secondary(darkMode: widget.darkMode), ), ), @@ -178,45 +192,45 @@ class _MihPackageWindowState extends State { @override Widget build(BuildContext context) { var size = MediaQuery.of(context).size; - setState(() { - width = size.width; - height = size.height; - }); - checkScreenSize(size); + final dimensions = _getResponsiveDimensions(size); + + final double titleSize = dimensions['titleSize']!; + final double horizontalPadding = dimensions['horizontalPadding']!; + final double verticalPadding = dimensions['verticalPadding']!; + + final bool isScrollbarOn = widget.scrollbarOn ?? false; return Dialog( insetPadding: EdgeInsets.symmetric( - horizontal: horizontralWindowPadding, - vertical: verticalWindowPadding, + horizontal: horizontalPadding, + vertical: verticalPadding, ), insetAnimationCurve: Easing.emphasizedDecelerate, insetAnimationDuration: Durations.short1, child: Material( elevation: 10, shadowColor: Colors.black, - color: - widget.backgroundColor ?? + color: widget.backgroundColor ?? MihColors.primary(darkMode: widget.darkMode), borderRadius: BorderRadius.circular(25.0), child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(25.0), - border: widget.borderOn == null || !widget.borderOn! - ? null - : Border.all( - color: - widget.foregroundColor ?? + border: widget.borderOn == true + ? Border.all( + color: widget.foregroundColor ?? MihColors.secondary(darkMode: widget.darkMode), width: 5.0, - ), + ) + : null, ), child: widget.fullscreen ? Column( mainAxisSize: MainAxisSize.max, children: [ - getHeader(), + getHeader(titleSize), const SizedBox(height: 5), Expanded( - child: widget.scrollbarOn != null || !widget.scrollbarOn! + child: !isScrollbarOn ? widget.windowBody : MihSingleChildScroll( scrollbarOn: true, @@ -228,19 +242,19 @@ class _MihPackageWindowState extends State { : Column( mainAxisSize: MainAxisSize.min, children: [ - getHeader(), + getHeader(titleSize), const SizedBox(height: 5), Flexible( child: Padding( padding: EdgeInsets.only( left: 25, right: 25, - bottom: verticalWindowPadding, + bottom: verticalPadding, ), child: ConstrainedBox( constraints: BoxConstraints( - maxHeight: windowHeight * 0.85, - maxWidth: windowWidth * 0.85, + maxHeight: size.height * 0.85, + maxWidth: size.width * 0.85, ), child: MihSingleChildScroll( scrollbarOn: true, diff --git a/pubspec.yaml b/pubspec.yaml index 3fc9d84..a8a5b0f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: mih_package_toolkit 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 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