theme-loading-fix #830

Merged
sarah merged 3 commits from theme-loading-fix into trunk 2024-02-14 04:30:28 +00:00
5 changed files with 38 additions and 36 deletions

View File

@ -88,6 +88,7 @@ class Settings extends ChangeNotifier {
bool get useSemanticDebugger => _useSemanticDebugger;
String? _themeId;
String? get themeId => _themeId;
String? _mode;
OpaqueThemeType get theme => themeloader.getTheme(_themeId, _mode);
void setTheme(String themeId, String mode) {
@ -481,7 +482,7 @@ class Settings extends ChangeNotifier {
dynamic asJson() {
return {
"Locale": this.locale.toString(),
"Theme": theme.theme,
"Theme": _themeId,
"ThemeMode": theme.mode,
"ThemeImages": _themeImages,
"PreviousPid": -1,

View File

@ -284,6 +284,5 @@ ThemeData mkThemeData(Settings opaque) {
snackBarTheme: SnackBarThemeData(
backgroundColor: opaque.current().snackbarBackgroundColor,
contentTextStyle: TextStyle(color: opaque.current().snackbarTextColor),
)
);
));
}

View File

@ -91,7 +91,7 @@ class _GlobalSettingsAppearanceViewState extends State<GlobalSettingsAppearanceV
child: DropdownButton<String>(
key: Key("DropdownTheme"),
isExpanded: true,
value: Provider.of<Settings>(context).theme.theme,
value: Provider.of<Settings>(context).themeId,
onChanged: (String? newValue) {
setState(() {
settings.setTheme(newValue!, settings.theme.mode);
@ -101,7 +101,7 @@ class _GlobalSettingsAppearanceViewState extends State<GlobalSettingsAppearanceV
items: settings.themeloader.themes.keys.map<DropdownMenuItem<String>>((String themeId) {
return DropdownMenuItem<String>(
value: themeId,
child: Text(getThemeName(context, themeId), style: settings.scaleFonts(defaultDropDownMenuItemTextStyle)), //"ddi_$themeId", key: Key("ddi_$themeId")),
child: Text(getThemeName(context, settings, themeId), style: settings.scaleFonts(defaultDropDownMenuItemTextStyle)), //"ddi_$themeId", key: Key("ddi_$themeId")),
);
}).toList())),
leading: Icon(Icons.palette, color: settings.current().mainTextColor),
@ -329,7 +329,7 @@ class _GlobalSettingsAppearanceViewState extends State<GlobalSettingsAppearanceV
}
/// Since we don't seem to able to dynamically pull translations, this function maps themes to their names
String getThemeName(context, String theme) {
String getThemeName(context, Settings settings, String theme) {
switch (theme) {
case cwtch_theme:
return AppLocalizations.of(context)!.themeNameCwtch;
@ -352,7 +352,7 @@ class _GlobalSettingsAppearanceViewState extends State<GlobalSettingsAppearanceV
case "juniper":
return "Juniper"; // Juniper is a noun, and doesn't get subject to translation...
}
return theme;
return settings.themeloader.themes[theme]?[settings.theme.mode]?.theme ?? theme;
}
void importThemeCheck(BuildContext context, Settings settings, String themesDir, String newThemeDirectory) async {

View File

@ -258,7 +258,7 @@ class _MessageViewState extends State<MessageView> {
actions: appBarButtons,
),
body: Padding(
padding: EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 182.0),
padding: EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 164.0),
child: MessageList(
scrollListener,
)),

View File

@ -122,36 +122,38 @@ class _MessageListState extends State<MessageList> {
image: AssetImage("assets/core/negative_heart_512px.png"),
colorFilter: ColorFilter.mode(Provider.of<Settings>(context).theme.hilightElementColor.withOpacity(0.15), BlendMode.srcIn))),
// Don't load messages for syncing server...
child: loadMessages
? ScrollablePositionedList.builder(
itemPositionsListener: widget.scrollListener,
itemScrollController: Provider.of<ContactInfoState>(outerContext).messageScrollController,
initialScrollIndex: initi > 4 ? initi - 4 : 0,
itemCount: Provider.of<ContactInfoState>(outerContext).totalMessages,
reverse: true, // NOTE: There seems to be a bug in flutter that corrects the mouse wheel scroll, but not the drag direction...
itemBuilder: (itemBuilderContext, index) {
var profileOnion = Provider.of<ProfileInfoState>(itemBuilderContext, listen: false).onion;
var contactHandle = Provider.of<ContactInfoState>(itemBuilderContext, listen: false).identifier;
var messageIndex = index;
child: Padding(
padding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 20.0),
child: loadMessages
? ScrollablePositionedList.builder(
itemPositionsListener: widget.scrollListener,
itemScrollController: Provider.of<ContactInfoState>(outerContext).messageScrollController,
initialScrollIndex: initi > 4 ? initi - 4 : 0,
itemCount: Provider.of<ContactInfoState>(outerContext).totalMessages,
reverse: true, // NOTE: There seems to be a bug in flutter that corrects the mouse wheel scroll, but not the drag direction...
itemBuilder: (itemBuilderContext, index) {
var profileOnion = Provider.of<ProfileInfoState>(itemBuilderContext, listen: false).onion;
var contactHandle = Provider.of<ContactInfoState>(itemBuilderContext, listen: false).identifier;
var messageIndex = index;
return FutureBuilder(
future: messageHandler(itemBuilderContext, profileOnion, contactHandle, ByIndex(messageIndex)),
builder: (fbcontext, snapshot) {
if (snapshot.hasData) {
var message = snapshot.data as Message;
// here we create an index key for the contact and assign it to the row. Indexes are unique so we can
// reliably use this without running into duplicate keys...it isn't ideal as it means keys need to be re-built
// when new messages are added...however it is better than the alternative of not having widget keys at all.
var key = Provider.of<ContactInfoState>(itemBuilderContext, listen: false).getMessageKey(contactHandle, messageIndex);
return message.getWidget(fbcontext, key, messageIndex);
} else {
return MessageLoadingBubble();
}
return FutureBuilder(
future: messageHandler(itemBuilderContext, profileOnion, contactHandle, ByIndex(messageIndex)),
builder: (fbcontext, snapshot) {
if (snapshot.hasData) {
var message = snapshot.data as Message;
// here we create an index key for the contact and assign it to the row. Indexes are unique so we can
// reliably use this without running into duplicate keys...it isn't ideal as it means keys need to be re-built
// when new messages are added...however it is better than the alternative of not having widget keys at all.
var key = Provider.of<ContactInfoState>(itemBuilderContext, listen: false).getMessageKey(contactHandle, messageIndex);
return message.getWidget(fbcontext, key, messageIndex);
} else {
return MessageLoadingBubble();
}
},
);
},
);
},
)
: null))
)
: null)))
])));
}
}