-
Notifications
You must be signed in to change notification settings - Fork 740
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22025bb
commit 25fe1e2
Showing
33 changed files
with
1,127 additions
and
1,172 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
253 changes: 147 additions & 106 deletions
253
packages/flutter_chat_core/lib/src/theme/chat_theme.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,168 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
import 'chat_theme_constants.dart'; | ||
import 'image_message_theme.dart'; | ||
import 'input_theme.dart'; | ||
import 'is_typing_theme.dart'; | ||
import 'scroll_to_bottom_theme.dart'; | ||
import 'text_message_theme.dart'; | ||
|
||
part 'chat_theme.freezed.dart'; | ||
|
||
@Freezed(fromJson: false, toJson: false, copyWith: false) | ||
@freezed | ||
class ChatTheme with _$ChatTheme { | ||
factory ChatTheme.light({ | ||
Color? backgroundColor, | ||
String? fontFamily, | ||
ImageMessageTheme? imageMessageTheme, | ||
InputTheme? inputTheme, | ||
IsTypingTheme? isTypingTheme, | ||
ScrollToBottomTheme? scrollToBottomTheme, | ||
TextMessageTheme? textMessageTheme, | ||
}) { | ||
return ChatTheme( | ||
backgroundColor: backgroundColor ?? defaultChatBackgroundColor.light, | ||
fontFamily: fontFamily ?? defaultChatFontFamily, | ||
imageMessageTheme: ImageMessageTheme.light().merge(imageMessageTheme), | ||
inputTheme: | ||
InputTheme.light(fontFamily: fontFamily ?? defaultChatFontFamily) | ||
.merge(inputTheme), | ||
isTypingTheme: IsTypingTheme.light().merge(isTypingTheme), | ||
scrollToBottomTheme: | ||
ScrollToBottomTheme.light().merge(scrollToBottomTheme), | ||
textMessageTheme: TextMessageTheme.light( | ||
fontFamily: fontFamily ?? defaultChatFontFamily, | ||
).merge(textMessageTheme), | ||
); | ||
} | ||
const factory ChatTheme({ | ||
required ChatColors colors, | ||
required ChatTypography typography, | ||
required BorderRadiusGeometry shape, | ||
}) = _ChatTheme; | ||
|
||
factory ChatTheme.dark({ | ||
Color? backgroundColor, | ||
String? fontFamily, | ||
ImageMessageTheme? imageMessageTheme, | ||
InputTheme? inputTheme, | ||
IsTypingTheme? isTypingTheme, | ||
ScrollToBottomTheme? scrollToBottomTheme, | ||
TextMessageTheme? textMessageTheme, | ||
}) { | ||
return ChatTheme( | ||
backgroundColor: backgroundColor ?? defaultChatBackgroundColor.dark, | ||
fontFamily: fontFamily ?? defaultChatFontFamily, | ||
imageMessageTheme: ImageMessageTheme.dark().merge(imageMessageTheme), | ||
inputTheme: | ||
InputTheme.dark(fontFamily: fontFamily ?? defaultChatFontFamily) | ||
.merge(inputTheme), | ||
isTypingTheme: IsTypingTheme.dark().merge(isTypingTheme), | ||
scrollToBottomTheme: | ||
ScrollToBottomTheme.dark().merge(scrollToBottomTheme), | ||
textMessageTheme: TextMessageTheme.dark( | ||
fontFamily: fontFamily ?? defaultChatFontFamily, | ||
).merge(textMessageTheme), | ||
); | ||
} | ||
const ChatTheme._(); | ||
|
||
factory ChatTheme.fromThemeData(ThemeData themeData, {String? fontFamily}) { | ||
final family = fontFamily ?? | ||
themeData.textTheme.bodyMedium?.fontFamily ?? | ||
defaultChatFontFamily; | ||
|
||
return ChatTheme( | ||
backgroundColor: themeData.colorScheme.surface, | ||
fontFamily: family, | ||
imageMessageTheme: ImageMessageTheme.fromThemeData(themeData), | ||
inputTheme: InputTheme.fromThemeData(themeData, fontFamily: family), | ||
isTypingTheme: IsTypingTheme.fromThemeData(themeData), | ||
scrollToBottomTheme: ScrollToBottomTheme.fromThemeData(themeData), | ||
textMessageTheme: TextMessageTheme.fromThemeData( | ||
themeData, | ||
fontFamily: family, | ||
), | ||
factory ChatTheme.light({String? fontFamily}) => ChatTheme( | ||
colors: ChatColors.light(), | ||
typography: ChatTypography.standard(fontFamily: fontFamily), | ||
shape: const BorderRadius.all(Radius.circular(12)), | ||
); | ||
|
||
factory ChatTheme.dark({String? fontFamily}) => ChatTheme( | ||
colors: ChatColors.dark(), | ||
typography: ChatTypography.standard(fontFamily: fontFamily), | ||
shape: const BorderRadius.all(Radius.circular(12)), | ||
); | ||
|
||
factory ChatTheme.fromThemeData(ThemeData themeData) => ChatTheme( | ||
colors: ChatColors.fromThemeData(themeData), | ||
typography: ChatTypography.fromThemeData(themeData), | ||
shape: const BorderRadius.all(Radius.circular(12)), | ||
); | ||
|
||
ChatTheme merge(ChatTheme? other) { | ||
if (other == null) return this; | ||
return copyWith( | ||
colors: colors.merge(other.colors), | ||
typography: typography.merge(other.typography), | ||
shape: other.shape, | ||
); | ||
} | ||
} | ||
|
||
const factory ChatTheme({ | ||
required Color backgroundColor, | ||
required String fontFamily, | ||
required ImageMessageTheme imageMessageTheme, | ||
required InputTheme inputTheme, | ||
required IsTypingTheme isTypingTheme, | ||
required ScrollToBottomTheme scrollToBottomTheme, | ||
required TextMessageTheme textMessageTheme, | ||
}) = _ChatTheme; | ||
@freezed | ||
class ChatColors with _$ChatColors { | ||
const factory ChatColors({ | ||
required Color primary, | ||
required Color onPrimary, | ||
required Color surface, | ||
required Color onSurface, | ||
required Color surfaceContainer, | ||
required Color surfaceContainerLow, | ||
required Color surfaceContainerHigh, | ||
}) = _ChatColors; | ||
|
||
const ChatTheme._(); | ||
const ChatColors._(); | ||
|
||
factory ChatColors.light() => const ChatColors( | ||
primary: Color(0xff4169e1), | ||
onPrimary: Colors.white, | ||
surface: Colors.white, | ||
onSurface: Color(0xff101010), | ||
surfaceContainerLow: Color(0xfffafafa), | ||
surfaceContainer: Color(0xfff5f5f5), | ||
surfaceContainerHigh: Color(0xffeeeeee), | ||
); | ||
|
||
ChatTheme copyWith({ | ||
Color? backgroundColor, | ||
String? fontFamily, | ||
ImageMessageTheme? imageMessageTheme, | ||
InputTheme? inputTheme, | ||
IsTypingTheme? isTypingTheme, | ||
ScrollToBottomTheme? scrollToBottomTheme, | ||
TextMessageTheme? textMessageTheme, | ||
}) { | ||
return ChatTheme( | ||
backgroundColor: backgroundColor ?? this.backgroundColor, | ||
fontFamily: fontFamily ?? this.fontFamily, | ||
imageMessageTheme: this.imageMessageTheme.merge(imageMessageTheme), | ||
inputTheme: this.inputTheme.merge(inputTheme), | ||
isTypingTheme: this.isTypingTheme.merge(isTypingTheme), | ||
scrollToBottomTheme: this.scrollToBottomTheme.merge(scrollToBottomTheme), | ||
textMessageTheme: this.textMessageTheme.merge(textMessageTheme), | ||
factory ChatColors.dark() => const ChatColors( | ||
primary: Color(0xff4169e1), | ||
onPrimary: Colors.white, | ||
surface: Color(0xff101010), | ||
onSurface: Colors.white, | ||
surfaceContainerLow: Color(0xff121212), | ||
surfaceContainer: Color(0xff1c1c1c), | ||
surfaceContainerHigh: Color(0xff242424), | ||
); | ||
|
||
factory ChatColors.fromThemeData(ThemeData themeData) => ChatColors( | ||
primary: themeData.colorScheme.primary, | ||
onPrimary: themeData.colorScheme.onPrimary, | ||
surface: themeData.colorScheme.surface, | ||
onSurface: themeData.colorScheme.onSurface, | ||
surfaceContainerLow: themeData.colorScheme.surfaceContainerLow, | ||
surfaceContainer: themeData.colorScheme.surfaceContainer, | ||
surfaceContainerHigh: themeData.colorScheme.surfaceContainerHigh, | ||
); | ||
|
||
ChatColors merge(ChatColors? other) { | ||
if (other == null) return this; | ||
return copyWith( | ||
primary: other.primary, | ||
onPrimary: other.onPrimary, | ||
surface: other.surface, | ||
onSurface: other.onSurface, | ||
surfaceContainerLow: other.surfaceContainerLow, | ||
surfaceContainer: other.surfaceContainer, | ||
surfaceContainerHigh: other.surfaceContainerHigh, | ||
); | ||
} | ||
} | ||
|
||
ChatTheme merge(ChatTheme? other) { | ||
@freezed | ||
class ChatTypography with _$ChatTypography { | ||
const factory ChatTypography({ | ||
required TextStyle bodyLarge, | ||
required TextStyle bodyMedium, | ||
required TextStyle bodySmall, | ||
required TextStyle labelLarge, | ||
required TextStyle labelMedium, | ||
required TextStyle labelSmall, | ||
}) = _ChatTypography; | ||
|
||
const ChatTypography._(); | ||
|
||
factory ChatTypography.standard({String? fontFamily}) => ChatTypography( | ||
bodyLarge: TextStyle( | ||
fontSize: 16, | ||
fontWeight: FontWeight.w400, | ||
fontFamily: fontFamily, | ||
), | ||
bodyMedium: TextStyle( | ||
fontSize: 14, | ||
fontWeight: FontWeight.w400, | ||
fontFamily: fontFamily, | ||
), | ||
bodySmall: TextStyle( | ||
fontSize: 12, | ||
fontWeight: FontWeight.w400, | ||
fontFamily: fontFamily, | ||
), | ||
labelLarge: TextStyle( | ||
fontSize: 14, | ||
fontWeight: FontWeight.w500, | ||
fontFamily: fontFamily, | ||
), | ||
labelMedium: TextStyle( | ||
fontSize: 12, | ||
fontWeight: FontWeight.w500, | ||
fontFamily: fontFamily, | ||
), | ||
labelSmall: TextStyle( | ||
fontSize: 10, | ||
fontWeight: FontWeight.w500, | ||
fontFamily: fontFamily, | ||
), | ||
); | ||
|
||
factory ChatTypography.fromThemeData(ThemeData themeData) => ChatTypography( | ||
bodyLarge: themeData.textTheme.bodyLarge!, | ||
bodyMedium: themeData.textTheme.bodyMedium!, | ||
bodySmall: themeData.textTheme.bodySmall!, | ||
labelLarge: themeData.textTheme.labelLarge!, | ||
labelMedium: themeData.textTheme.labelMedium!, | ||
labelSmall: themeData.textTheme.labelSmall!, | ||
); | ||
|
||
ChatTypography merge(ChatTypography? other) { | ||
if (other == null) return this; | ||
return copyWith( | ||
backgroundColor: other.backgroundColor, | ||
fontFamily: other.fontFamily, | ||
imageMessageTheme: other.imageMessageTheme, | ||
inputTheme: other.inputTheme, | ||
isTypingTheme: other.isTypingTheme, | ||
scrollToBottomTheme: other.scrollToBottomTheme, | ||
textMessageTheme: other.textMessageTheme, | ||
bodyLarge: other.bodyLarge, | ||
bodyMedium: other.bodyMedium, | ||
bodySmall: other.bodySmall, | ||
labelLarge: other.labelLarge, | ||
labelMedium: other.labelMedium, | ||
labelSmall: other.labelSmall, | ||
); | ||
} | ||
} |
Oops, something went wrong.