From 8668e668131860b502e7966f5dbe25215e28dcb7 Mon Sep 17 00:00:00 2001 From: Nutcake Date: Thu, 25 May 2023 19:30:15 +0200 Subject: [PATCH] Improve light-mode support --- lib/auxiliary.dart | 11 +++++++++++ lib/clients/api_client.dart | 2 -- lib/main.dart | 6 ++++++ lib/models/friend.dart | 6 +++--- .../friend_online_status_indicator.dart | 4 ++-- lib/widgets/friends/friends_list.dart | 4 ++-- lib/widgets/generic_avatar.dart | 18 +++++++++--------- lib/widgets/messages/message_input_bar.dart | 5 +++-- lib/widgets/messages/messages_list.dart | 3 ++- lib/widgets/my_profile_dialog.dart | 2 +- 10 files changed, 39 insertions(+), 22 deletions(-) diff --git a/lib/auxiliary.dart b/lib/auxiliary.dart index 5a606be..6f792d9 100644 --- a/lib/auxiliary.dart +++ b/lib/auxiliary.dart @@ -1,4 +1,5 @@ import 'package:contacts_plus_plus/config.dart'; +import 'package:flutter/material.dart'; import 'package:path/path.dart' as p; import 'package:html/parser.dart' as htmlparser; @@ -90,4 +91,14 @@ extension Format on Duration { extension DateTimeX on DateTime { static DateTime epoch = DateTime.fromMillisecondsSinceEpoch(0); static DateTime one = DateTime(1); +} + +extension ColorX on Color { + Color invert() { + final r = 255 - red; + final g = 255 - green; + final b = 255 - blue; + + return Color.fromARGB((opacity * 255).round(), r, g, b); + } } \ No newline at end of file diff --git a/lib/clients/api_client.dart b/lib/clients/api_client.dart index 913b671..cc2472d 100644 --- a/lib/clients/api_client.dart +++ b/lib/clients/api_client.dart @@ -1,8 +1,6 @@ import 'dart:async'; import 'dart:convert'; import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_phoenix/flutter_phoenix.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:http/http.dart' as http; import 'package:contacts_plus_plus/models/authentication_data.dart'; diff --git a/lib/main.dart b/lib/main.dart index 1e17929..d03b902 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -119,10 +119,16 @@ class _ContactsPlusPlusState extends State { debugShowCheckedModeBanner: false, title: 'Contacts++', theme: ThemeData( + useMaterial3: true, + textTheme: _typography.black, + colorScheme: lightDynamic ?? ColorScheme.fromSeed(seedColor: Colors.purple, brightness: Brightness.light), + ), + darkTheme: ThemeData( useMaterial3: true, textTheme: _typography.white, colorScheme: darkDynamic ?? ColorScheme.fromSeed(seedColor: Colors.purple, brightness: Brightness.dark), ), + themeMode: ThemeMode.dark, home: Builder( // Builder is necessary here since we need a context which has access to the ClientHolder builder: (context) { showUpdateDialogOnFirstBuild(context); diff --git a/lib/models/friend.dart b/lib/models/friend.dart index cc8c89f..15ec426 100644 --- a/lib/models/friend.dart +++ b/lib/models/friend.dart @@ -93,14 +93,14 @@ enum OnlineStatus { online; static final List _colors = [ - Colors.white54, - Colors.white54, + Colors.transparent, + Colors.transparent, Colors.yellow, Colors.red, Colors.green, ]; - Color get color => _colors[index]; + Color color(BuildContext context) => this == OnlineStatus.offline || this == OnlineStatus.invisible ? Theme.of(context).colorScheme.onSurface : _colors[index]; factory OnlineStatus.fromString(String? text) { return OnlineStatus.values.firstWhere((element) => element.name.toLowerCase() == text?.toLowerCase(), diff --git a/lib/widgets/friends/friend_online_status_indicator.dart b/lib/widgets/friends/friend_online_status_indicator.dart index 6e3328b..98b8ac8 100644 --- a/lib/widgets/friends/friend_online_status_indicator.dart +++ b/lib/widgets/friends/friend_online_status_indicator.dart @@ -15,11 +15,11 @@ class FriendOnlineStatusIndicator extends StatelessWidget { child: Image.asset( "assets/images/logo-white.png", alignment: Alignment.center, - color: userStatus.onlineStatus.color, + color: userStatus.onlineStatus.color(context), ), ) : Icon( userStatus.onlineStatus == OnlineStatus.offline ? Icons.circle_outlined : Icons.circle, - color: userStatus.onlineStatus.color, + color: userStatus.onlineStatus.color(context), size: 10, ); } diff --git a/lib/widgets/friends/friends_list.dart b/lib/widgets/friends/friends_list.dart index 86fbff7..b67331c 100644 --- a/lib/widgets/friends/friends_list.dart +++ b/lib/widgets/friends/friends_list.dart @@ -77,7 +77,7 @@ class _FriendsListState extends State { children: [ Padding( padding: const EdgeInsets.only(right: 8.0), - child: Icon(Icons.circle, size: 16, color: userStatus.onlineStatus.color,), + child: Icon(Icons.circle, size: 16, color: userStatus.onlineStatus.color(context),), ), Text(toBeginningOfSentenceCase(userStatus.onlineStatus.name) ?? "Unknown"), ], @@ -112,7 +112,7 @@ class _FriendsListState extends State { child: Row( mainAxisAlignment: MainAxisAlignment.start, children: [ - Icon(Icons.circle, size: 16, color: item.color,), + Icon(Icons.circle, size: 16, color: item.color(context),), const SizedBox(width: 8,), Text(toBeginningOfSentenceCase(item.name)!), ], diff --git a/lib/widgets/generic_avatar.dart b/lib/widgets/generic_avatar.dart index fa30337..552b1cf 100644 --- a/lib/widgets/generic_avatar.dart +++ b/lib/widgets/generic_avatar.dart @@ -13,14 +13,14 @@ class GenericAvatar extends StatelessWidget { Widget build(BuildContext context) { return imageUri.isEmpty ? CircleAvatar( radius: radius, - foregroundColor: foregroundColor, - backgroundColor: Colors.transparent, + foregroundColor: foregroundColor ?? Theme.of(context).colorScheme.onPrimaryContainer, + backgroundColor: Theme.of(context).colorScheme.primaryContainer, child: Icon(placeholderIcon, color: foregroundColor,), ) : CachedNetworkImage( imageBuilder: (context, imageProvider) { return CircleAvatar( foregroundImage: imageProvider, - foregroundColor: foregroundColor, + foregroundColor: Colors.transparent, backgroundColor: Colors.transparent, radius: radius, ); @@ -28,20 +28,20 @@ class GenericAvatar extends StatelessWidget { imageUrl: imageUri, placeholder: (context, url) { return CircleAvatar( - backgroundColor: Colors.white54, - foregroundColor: foregroundColor, + backgroundColor: Theme.of(context).colorScheme.primaryContainer, + foregroundColor: foregroundColor ?? Theme.of(context).colorScheme.onPrimaryContainer, radius: radius, child: Padding( padding: const EdgeInsets.all(8.0), - child: CircularProgressIndicator(color: foregroundColor, strokeWidth: 2), + child: CircularProgressIndicator(color: foregroundColor ?? Theme.of(context).colorScheme.onPrimaryContainer, strokeWidth: 2), ), ); }, errorWidget: (context, error, what) => CircleAvatar( radius: radius, - foregroundColor: foregroundColor, - backgroundColor: Colors.transparent, - child: Icon(placeholderIcon, color: foregroundColor,), + foregroundColor: foregroundColor ?? Theme.of(context).colorScheme.onPrimaryContainer, + backgroundColor: Theme.of(context).colorScheme.primaryContainer, + child: Icon(placeholderIcon, color: foregroundColor ?? Theme.of(context).colorScheme.onPrimaryContainer,), ), ); } diff --git a/lib/widgets/messages/message_input_bar.dart b/lib/widgets/messages/message_input_bar.dart index 82c064f..0e3cc35 100644 --- a/lib/widgets/messages/message_input_bar.dart +++ b/lib/widgets/messages/message_input_bar.dart @@ -205,7 +205,7 @@ class _MessageInputBarState extends State { }, child: Container( decoration: BoxDecoration( - border: const Border(top: BorderSide(width: 1, color: Colors.black38)), + border: const Border(top: BorderSide(width: 1, color: Colors.black)), color: Theme .of(context) .colorScheme @@ -389,13 +389,14 @@ class _MessageInputBarState extends State { } _currentText = text; }, + style: Theme.of(context).textTheme.bodyLarge, decoration: InputDecoration( isDense: true, hintText: _isRecording ? "" : "Message ${widget.recipient .username}...", hintMaxLines: 1, contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), - fillColor: Colors.black38, + fillColor: Colors.black26, filled: true, border: OutlineInputBorder( borderSide: BorderSide.none, diff --git a/lib/widgets/messages/messages_list.dart b/lib/widgets/messages/messages_list.dart index f0e61c0..17768da 100644 --- a/lib/widgets/messages/messages_list.dart +++ b/lib/widgets/messages/messages_list.dart @@ -1,3 +1,4 @@ +import 'package:contacts_plus_plus/auxiliary.dart'; import 'package:contacts_plus_plus/clients/audio_cache_client.dart'; import 'package:contacts_plus_plus/clients/messaging_client.dart'; import 'package:contacts_plus_plus/models/friend.dart'; @@ -89,7 +90,7 @@ class _MessagesListState extends State with SingleTickerProviderSt constraints: const BoxConstraints(maxHeight: 64), decoration: BoxDecoration( color: appBarColor, - border: const Border(top: BorderSide(width: 1, color: Colors.black26),) + border: const Border(bottom: BorderSide(width: 1, color: Colors.black),) ), child: Stack( children: [ diff --git a/lib/widgets/my_profile_dialog.dart b/lib/widgets/my_profile_dialog.dart index 8674eec..0929376 100644 --- a/lib/widgets/my_profile_dialog.dart +++ b/lib/widgets/my_profile_dialog.dart @@ -56,7 +56,7 @@ class _MyProfileDialogState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(profile.username, style: tt.titleLarge), - Text(profile.email, style: tt.labelMedium?.copyWith(color: Colors.white54),) + Text(profile.email, style: tt.labelMedium?.copyWith(color: Theme.of(context).colorScheme.onSurface.withAlpha(150)),) ], ), GenericAvatar(imageUri: Aux.neosDbToHttp(profile.userProfile.iconUrl), radius: 24,)