Skip to content

Commit

Permalink
Merge pull request #554 from danemadsen/main
Browse files Browse the repository at this point in the history
Disable flickering in Menu button and bump version number
  • Loading branch information
danemadsen authored May 12, 2024
2 parents 36ca59d + f580b49 commit a56d806
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 27 deletions.
83 changes: 57 additions & 26 deletions lib/ui/mobile/widgets/buttons/menu_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,72 @@ class MenuButton extends StatefulWidget {

class _MenuButtonState extends State<MenuButton> {
final iconButtonKey = GlobalKey();
static LargeLanguageModelType lastModelType = LargeLanguageModelType.none;
static DateTime lastCheck = DateTime.now();
static List<String> cache = [];
List<String> 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<Session>(
builder: (context, session, child) {
return FutureBuilder(
future: session.model.options,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
options = snapshot.data as List<String>;
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<String>;
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
),
),
),
),
);
);
}
}
}
);
);
}
}
);
}
Expand Down Expand Up @@ -130,6 +160,7 @@ class _MenuButtonState extends State<MenuButton> {
contentPadding: const EdgeInsets.symmetric(horizontal: 8.0),
title: const Text('App Settings'),
onTap: () {
cache.clear();
Navigator.pop(context);
Navigator.push(
context,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit a56d806

Please sign in to comment.