1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 12:59:21 +00:00

Improve dark theme

This commit is contained in:
Pierre HUBERT 2019-11-01 14:17:46 +01:00
parent 6a34df6814
commit 481d718338
8 changed files with 83 additions and 53 deletions

View File

@ -71,3 +71,10 @@ class PreferencesHelper {
return v == null ? alternative : v; return v == null ? alternative : v;
} }
} }
PreferencesHelper preferences() {
if (PreferencesHelper._instance == null)
throw Exception("Try to get preference before their initialization!");
return PreferencesHelper._instance;
}

View File

@ -32,7 +32,7 @@ class ComunicApplication extends StatelessWidget {
return MaterialApp( return MaterialApp(
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
home: ComunicApplicationHome(), home: ComunicApplicationHome(),
theme: darkMode ? ThemeData.dark() : null, theme: darkMode ? ThemeData.dark() : ThemeData.light(),
); );
} }
} }

View File

@ -4,6 +4,7 @@ import 'package:comunic/ui/widgets/account_image_widget.dart';
import 'package:comunic/ui/widgets/network_image_widget.dart'; import 'package:comunic/ui/widgets/network_image_widget.dart';
import 'package:comunic/utils/date_utils.dart'; import 'package:comunic/utils/date_utils.dart';
import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
/// Single comment tile /// Single comment tile
@ -90,7 +91,7 @@ class CommentTile extends StatelessWidget {
child: comment.hasContent child: comment.hasContent
? Text( ? Text(
comment.content, comment.content,
style: TextStyle(color: Colors.black), style: TextStyle(color: darkTheme() ? darkAccentColor : Colors.black),
) )
: null, : null,
), ),

View File

@ -5,6 +5,7 @@ import 'package:comunic/ui/widgets/network_image_widget.dart';
import 'package:comunic/ui/widgets/text_rich_content_widget.dart'; import 'package:comunic/ui/widgets/text_rich_content_widget.dart';
import 'package:comunic/utils/date_utils.dart'; import 'package:comunic/utils/date_utils.dart';
import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
/// Conversation message tile /// Conversation message tile
@ -50,20 +51,20 @@ class ConversationMessageTile extends StatelessWidget {
width: 35.0, width: 35.0,
), ),
itemBuilder: (c) => [ itemBuilder: (c) => [
// Update message content // Update message content
PopupMenuItem( PopupMenuItem(
enabled: message.isOwner, enabled: message.isOwner,
value: _MenuChoices.REQUEST_UPDATE_CONTENT, value: _MenuChoices.REQUEST_UPDATE_CONTENT,
child: Text(tr("Update")), child: Text(tr("Update")),
), ),
// Delete the message // Delete the message
PopupMenuItem( PopupMenuItem(
enabled: message.isOwner, enabled: message.isOwner,
value: _MenuChoices.DELETE, value: _MenuChoices.DELETE,
child: Text(tr("Delete")), child: Text(tr("Delete")),
), ),
], ],
onSelected: _menuOptionSelected, onSelected: _menuOptionSelected,
), ),
); );
@ -201,12 +202,17 @@ class ConversationMessageTile extends StatelessWidget {
child: TextRichContentWidget( child: TextRichContentWidget(
message.message, message.message,
textAlign: TextAlign.justify, textAlign: TextAlign.justify,
style: TextStyle(color: Colors.black), style: TextStyle(
color: darkTheme()
? Colors.white
: Colors.black),
), ),
padding: padding:
EdgeInsets.fromLTRB(15.0, 10.0, 15.0, 10.0), EdgeInsets.fromLTRB(15.0, 10.0, 15.0, 10.0),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.black12, color: darkTheme()
? Colors.white12
: Colors.black12,
borderRadius: BorderRadius.circular(8.0), borderRadius: BorderRadius.circular(8.0),
), ),
), ),

View File

@ -3,6 +3,7 @@ import 'package:comunic/lists/users_list.dart';
import 'package:comunic/models/conversation.dart'; import 'package:comunic/models/conversation.dart';
import 'package:comunic/utils/date_utils.dart'; import 'package:comunic/utils/date_utils.dart';
import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
/// Single conversation tile /// Single conversation tile
@ -67,7 +68,9 @@ class ConversationTile extends StatelessWidget {
// Leading icon // Leading icon
leading: Icon( leading: Icon(
conversation.sawLastMessage ? Icons.check_circle : Icons.lens, conversation.sawLastMessage ? Icons.check_circle : Icons.lens,
color: conversation.sawLastMessage ? null : Colors.blue, color: conversation.sawLastMessage
? (darkTheme() ? darkAccentColor : null)
: Colors.blue,
), ),
// Conversation information // Conversation information
@ -94,15 +97,15 @@ class ConversationTile extends StatelessWidget {
// Trailing information // Trailing information
trailing: PopupMenuButton<_PopupMenuChoices>( trailing: PopupMenuButton<_PopupMenuChoices>(
itemBuilder: (b) => <PopupMenuEntry<_PopupMenuChoices>>[ itemBuilder: (b) => <PopupMenuEntry<_PopupMenuChoices>>[
PopupMenuItem( PopupMenuItem(
child: Text(tr("Update")), child: Text(tr("Update")),
value: _PopupMenuChoices.UPDATE, value: _PopupMenuChoices.UPDATE,
), ),
PopupMenuItem( PopupMenuItem(
child: Text(tr("Delete")), child: Text(tr("Delete")),
value: _PopupMenuChoices.DELETE, value: _PopupMenuChoices.DELETE,
) )
], ],
onSelected: _conversationMenuCallback, onSelected: _conversationMenuCallback,
), ),
); );

View File

@ -141,20 +141,20 @@ class _PostTileState extends State<PostTile> {
PopupMenuButton<_PostActions>( PopupMenuButton<_PostActions>(
itemBuilder: (c) => [ itemBuilder: (c) => [
// Update post content // Update post content
PopupMenuItem( PopupMenuItem(
child: Text(tr("Update content")), child: Text(tr("Update content")),
value: _PostActions.UPDATE_CONTENT, value: _PostActions.UPDATE_CONTENT,
enabled: widget.post.canUpdate, enabled: widget.post.canUpdate,
), ),
// Delete post // Delete post
PopupMenuItem( PopupMenuItem(
child: Text(tr("Delete")), child: Text(tr("Delete")),
value: _PostActions.DELETE, value: _PostActions.DELETE,
enabled: widget.post.canDelete, enabled: widget.post.canDelete,
), ),
], ],
onSelected: _selectedPostMenuAction, onSelected: _selectedPostMenuAction,
) )
], ],
@ -333,19 +333,19 @@ class _PostTileState extends State<PostTile> {
final comments = List<Widget>.generate( final comments = List<Widget>.generate(
widget.post.comments.length, widget.post.comments.length,
(num) => CommentTile( (num) => CommentTile(
comment: widget.post.comments[num], comment: widget.post.comments[num],
user: widget.usersInfo.getUser(widget.post.comments[num].userID), user: widget.usersInfo.getUser(widget.post.comments[num].userID),
onUpdateLike: _updateCommentLike, onUpdateLike: _updateCommentLike,
onUpdateComment: _updateCommentContent, onUpdateComment: _updateCommentContent,
onDeleteComment: _deleteComment, onDeleteComment: _deleteComment,
), ),
); );
// Add comments form // Add comments form
comments.add(_buildCommentsForm()); comments.add(_buildCommentsForm());
return Container( return Container(
color: Colors.grey[300], color: darkTheme() ? Colors.black38 : Colors.grey[300],
child: Padding( child: Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0), padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
child: Column( child: Column(
@ -375,10 +375,15 @@ class _PostTileState extends State<PostTile> {
controller: _commentController, controller: _commentController,
onChanged: (s) => setState(() {}), onChanged: (s) => setState(() {}),
onSubmitted: _canSubmitComment ? (s) => _submitComment() : null, onSubmitted: _canSubmitComment ? (s) => _submitComment() : null,
style: TextStyle(
color: darkTheme() ? Colors.white : null,
),
decoration: InputDecoration( decoration: InputDecoration(
hintText: tr("New comment..."), hintText: tr("New comment..."),
hintStyle: TextStyle(color: Colors.grey, fontSize: 12), hintStyle: TextStyle(color: Colors.grey, fontSize: 12),
fillColor: Colors.white, fillColor: darkTheme() ? Colors.black38 : Colors.white,
filled: true, filled: true,
border: OutlineInputBorder( border: OutlineInputBorder(
borderSide: BorderSide(width: 0.5, color: Colors.grey), borderSide: BorderSide(width: 0.5, color: Colors.grey),

View File

@ -1,4 +1,5 @@
import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
/// Navigation bar widget /// Navigation bar widget
@ -18,8 +19,8 @@ enum BarCallbackActions {
ACTION_LOGOUT ACTION_LOGOUT
} }
const _PrimaryColor = Colors.blue; Color _primaryColor() => darkTheme() ? Colors.black : Colors.blue;
const _SecondaryColor = Colors.white; Color _secondaryColor() => darkTheme() ? darkAccentColor : Colors.white;
/// Menu item information /// Menu item information
class _MenuItem { class _MenuItem {
@ -93,7 +94,7 @@ class ComunicAppBar extends StatelessWidget implements PreferredSizeWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Material( return Material(
color: Colors.blue, color: darkTheme() ? Colors.black : Colors.blue,
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: List.generate( children: List.generate(
@ -134,7 +135,7 @@ class _MenuItemWidget extends StatelessWidget {
return Expanded( return Expanded(
child: Material( child: Material(
color: isSelected ? _SecondaryColor : _PrimaryColor, color: isSelected ? _secondaryColor() : _primaryColor(),
child: !item.isMenu child: !item.isMenu
? InkWell( ? InkWell(
child: _buildIconContainer(), child: _buildIconContainer(),
@ -151,7 +152,7 @@ class _MenuItemWidget extends StatelessWidget {
children: <Widget>[ children: <Widget>[
IconTheme( IconTheme(
data: IconThemeData( data: IconThemeData(
color: isSelected ? _PrimaryColor : _SecondaryColor), color: isSelected ? _primaryColor() : _secondaryColor()),
child: item.icon, child: item.icon,
) )
], ],

View File

@ -1,4 +1,5 @@
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
import 'package:comunic/helpers/preferences_helper.dart';
import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/intl_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:html/parser.dart'; import 'package:html/parser.dart';
@ -179,3 +180,9 @@ String htmlDecodeCharacters(String input) {
return parse(input).documentElement.text; return parse(input).documentElement.text;
} }
const darkAccentColor = Colors.white70;
/// Check out whether dark theme is enabled or not
bool darkTheme() => preferences().getBool(PreferencesKeyList.ENABLE_DARK_THEME);