From fe24a51181a148395f3b208a8e6f55e9a85c6c2a Mon Sep 17 00:00:00 2001 From: danemadsen Date: Sun, 12 May 2024 20:46:56 +1000 Subject: [PATCH 1/2] disable flickering in menubutton --- .../mobile/widgets/buttons/menu_button.dart | 83 +++++++++++++------ 1 file changed, 57 insertions(+), 26 deletions(-) diff --git a/lib/ui/mobile/widgets/buttons/menu_button.dart b/lib/ui/mobile/widgets/buttons/menu_button.dart index a0f4e041..d486f1b5 100644 --- a/lib/ui/mobile/widgets/buttons/menu_button.dart +++ b/lib/ui/mobile/widgets/buttons/menu_button.dart @@ -19,42 +19,72 @@ class MenuButton extends StatefulWidget { class _MenuButtonState extends State { final iconButtonKey = GlobalKey(); + static LargeLanguageModelType lastModelType = LargeLanguageModelType.none; + static DateTime lastCheck = DateTime.now(); + static List cache = []; List options = []; + bool canUseCache(Session session) { + if (cache.isEmpty && session.model.type != LargeLanguageModelType.llamacpp) return false; + + if (session.model.type != lastModelType) return false; + + if (DateTime.now().difference(lastCheck).inMinutes > 1) return false; + + return true; + } + @override Widget build(BuildContext context) { return Consumer( builder: (context, session, child) { - return FutureBuilder( - future: session.model.options, - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.done) { - options = snapshot.data as List; + if (canUseCache(session)) { + options = cache; + return IconButton( + key: iconButtonKey, + icon: const Icon( + Icons.account_tree_rounded, + size: 24, + ), + onPressed: onPressed, + ); + } + else { + lastModelType = session.model.type; + lastCheck = DateTime.now(); - return IconButton( - key: iconButtonKey, - icon: const Icon( - Icons.account_tree_rounded, - size: 24, - ), - onPressed: onPressed, - ); - } else { - return const Padding( - padding: EdgeInsets.all(8.0), // Adjust padding to match the visual space of the IconButton - child: SizedBox( - width: 24, // Width of the CircularProgressIndicator - height: 24, // Height of the CircularProgressIndicator - child: Center( - child: CircularProgressIndicator( - strokeWidth: 3.0, // Adjust the thickness of the spinner here + return FutureBuilder( + future: session.model.options, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.done) { + options = snapshot.data as List; + cache = options; + + return IconButton( + key: iconButtonKey, + icon: const Icon( + Icons.account_tree_rounded, + size: 24, + ), + onPressed: onPressed, + ); + } else { + return const Padding( + padding: EdgeInsets.all(8.0), // Adjust padding to match the visual space of the IconButton + child: SizedBox( + width: 24, // Width of the CircularProgressIndicator + height: 24, // Height of the CircularProgressIndicator + child: Center( + child: CircularProgressIndicator( + strokeWidth: 3.0, // Adjust the thickness of the spinner here + ), ), ), - ), - ); + ); + } } - } - ); + ); + } } ); } @@ -130,6 +160,7 @@ class _MenuButtonState extends State { contentPadding: const EdgeInsets.symmetric(horizontal: 8.0), title: const Text('App Settings'), onTap: () { + cache.clear(); Navigator.pop(context); Navigator.push( context, From f580b49d798cae740d1c664d9871276db7d7061f Mon Sep 17 00:00:00 2001 From: danemadsen Date: Sun, 12 May 2024 20:48:39 +1000 Subject: [PATCH 2/2] 1.2.7 --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index e22089b3..5c77b47c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.2.6+26 +version: 1.2.7+27 environment: sdk: '>=3.0.0 <4.0.0'