chat and theme work

This commit is contained in:
Christien Rioux 2023-07-29 10:55:35 -04:00
parent ca6b00e021
commit 96e3251b3b
29 changed files with 729 additions and 389 deletions

View file

@ -1,49 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
class Chat extends ConsumerWidget {
const Chat({super.key});
@override
// ignore: prefer_expression_function_bodies
Widget build(BuildContext context, WidgetRef ref) {
//
return Align(
alignment: AlignmentDirectional.centerEnd,
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).scaffoldBackgroundColor,
),
child: Stack(
children: [
Column(
children: [
Container(
height: 48,
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
),
child: Align(
alignment: AlignmentDirectional.centerStart,
child: Padding(
padding:
const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 0),
child: Text("current contact",
textAlign: TextAlign.start,
style: Theme.of(context).textTheme.titleMedium),
),
),
),
Expanded(
child: Container(
decoration: const BoxDecoration(),
child: Text("Chat"),
),
),
],
),
],
),
));
}
}

View file

@ -0,0 +1,118 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_chat_ui/flutter_chat_ui.dart';
import 'package:flutter_chat_types/flutter_chat_types.dart' as types;
import 'package:intl/date_symbol_data_local.dart';
import 'package:uuid/uuid.dart';
class ChatComponent extends ConsumerStatefulWidget {
const ChatComponent({super.key});
@override
ChatComponentState createState() => ChatComponentState();
}
class ChatComponentState extends ConsumerState<ChatComponent> {
List<types.Message> _messages = [];
final _unfocusNode = FocusNode();
@override
void initState() {
super.initState();
_loadMessages();
}
@override
void dispose() {
_unfocusNode.dispose();
super.dispose();
}
void _loadMessages() {
final messages = <types.Message>[
types.TextMessage(
id: "abcd",
text: "Hello!",
author: types.User(
id: "1234",
firstName: "Foo",
lastName: "Bar",
role: types.Role.user))
];
_messages = messages;
}
final _user = const types.User(
id: '82091008-a484-4a89-ae75-a22bf8d6f3ac',
);
void _addMessage(types.Message message) {
setState(() {
_messages.insert(0, message);
});
}
void _handleSendPressed(types.PartialText message) {
final textMessage = types.TextMessage(
author: _user,
createdAt: DateTime.now().millisecondsSinceEpoch,
id: const Uuid().v4(),
text: message.text,
);
_addMessage(textMessage);
}
@override
// ignore: prefer_expression_function_bodies
Widget build(BuildContext context) {
//
return Align(
alignment: AlignmentDirectional.centerEnd,
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).scaffoldBackgroundColor,
),
child: Stack(
children: [
Column(
children: [
Container(
height: 48,
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
),
child: Align(
alignment: AlignmentDirectional.centerStart,
child: Padding(
padding:
const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 0),
child: Text("current contact",
textAlign: TextAlign.start,
style: Theme.of(context).textTheme.titleMedium),
),
),
),
Expanded(
child: Container(
decoration: const BoxDecoration(),
child: Chat(
//theme: _chatTheme,
messages: _messages,
//onAttachmentPressed: _handleAttachmentPressed,
//onMessageTap: _handleMessageTap,
//onPreviewDataFetched: _handlePreviewDataFetched,
onSendPressed: _handleSendPressed,
showUserAvatars: true,
showUserNames: true,
user: _user,
),
),
),
],
),
],
),
));
}
}

View file

@ -0,0 +1,41 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../entities/proto.dart' as proto;
import 'empty_contact_list_widget.dart';
class ContactListWidget extends ConsumerWidget {
const ContactListWidget({required this.contactList, super.key});
final List<proto.Contact> contactList;
@override
// ignore: prefer_expression_function_bodies
Widget build(BuildContext context, WidgetRef ref) {
//
if (contactList.isEmpty) {
return const EmptyContactListWidget();
}
return Container(
decoration: BoxDecoration(
color: Theme.of(context).scaffoldBackgroundColor,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.group_add,
color: Theme.of(context).disabledColor,
size: 48,
),
Text(
'Contacts',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).disabledColor,
),
),
],
),
);
}
}

View file

@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
class EmptyChatComponentWidget extends ConsumerWidget {
const EmptyChatComponentWidget({super.key});
class EmptyChatWidget extends ConsumerWidget {
const EmptyChatWidget({super.key});
@override
// ignore: prefer_expression_function_bodies

View file

@ -1,16 +1,15 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_translate/flutter_translate.dart';
class EmptyContactListComponentWidget extends ConsumerWidget {
const EmptyContactListComponentWidget({super.key});
class EmptyContactListWidget extends ConsumerWidget {
const EmptyContactListWidget({super.key});
@override
// ignore: prefer_expression_function_bodies
Widget build(BuildContext context, WidgetRef ref) {
//
return Container(
width: double.infinity,
height: double.infinity,
decoration: BoxDecoration(
color: Theme.of(context).scaffoldBackgroundColor,
),
@ -18,12 +17,12 @@ class EmptyContactListComponentWidget extends ConsumerWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.group_add,
Icons.person_add_sharp,
color: Theme.of(context).disabledColor,
size: 48,
),
Text(
'Start A Conversation',
translate('empty_contact_list.invite_people'),
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).disabledColor,
),

View file

@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
class NoContactComponentWidget extends ConsumerWidget {
const NoContactComponentWidget({super.key});
class NoContactWidget extends ConsumerWidget {
const NoContactWidget({super.key});
@override
// ignore: prefer_expression_function_bodies

View file

@ -143,7 +143,7 @@ message Attachment {
}
// A single message as part of a series of messages
// Messages are stored in an append-only log in DHT
// Messages are stored in a DHTLog
message Message {
// Author of the message
TypedKey author = 1;
@ -210,9 +210,6 @@ enum Availability {
// Name - Friendly name
// Title - Title of user
// Icon - Little picture to represent user in contact list
//
// DHT Key: None
// Encryption: None
message Profile {
// Friendy name
string name = 1;
@ -230,8 +227,7 @@ message Profile {
// Pointed to by the identity account map in the identity key
//
// DHT Schema: DFLT(1)
// DHT Key (Private): accountPublicKey
// DHT Secret: accountSecretKey
// DHT Private: accountSecretKey
message Account {
// The user's profile that gets shared with contacts
Profile profile = 1;
@ -240,6 +236,6 @@ message Account {
// Auto-away sets 'away' mode after an inactivity time
uint32 auto_away_timeout_sec = 3;
// The contacts DHTList for this account
// Schema: SMPL(0,64,[accountPublicKey]) Encryption: accountSecretKey
// DHT Private: accountSecretKey
TypedKey contact_list = 4;
}

View file

@ -1,11 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:multi_split_view/multi_split_view.dart';
import 'package:split_view/split_view.dart';
import 'package:signal_strength_indicator/signal_strength_indicator.dart';
import '../components/chat.dart';
import '../components/chat_list.dart';
import '../components/chat_component.dart';
import '../providers/window_control.dart';
import '../tools/tools.dart';
import 'main_pager/main_pager.dart';
@ -22,37 +21,10 @@ class HomePageState extends ConsumerState<HomePage>
with TickerProviderStateMixin {
final _unfocusNode = FocusNode();
final MultiSplitViewController _splitController = MultiSplitViewController(
areas: [Area(minimalSize: 300, weight: 0.25), Area(minimalSize: 300)]);
final scaffoldKey = GlobalKey<ScaffoldState>();
bool hasContainerTriggered = false;
final animationsMap = {
'containerOnActionTriggerAnimation': AnimationInfo(
trigger: AnimationTrigger.onActionTrigger,
applyInitialState: false,
effects: [
MoveEffect(
curve: Curves.bounceOut,
delay: 0.ms,
duration: 500.ms,
begin: const Offset(100, 0),
end: Offset.zero,
),
],
),
};
@override
void initState() {
super.initState();
setupAnimations(
animationsMap.values.where((anim) =>
anim.trigger == AnimationTrigger.onActionTrigger ||
!anim.applyInitialState),
this,
);
WidgetsBinding.instance.addPostFrameCallback((_) async {
setState(() {});
await ref.read(windowControlProvider.notifier).changeWindowSetup(
@ -83,34 +55,35 @@ class HomePageState extends ConsumerState<HomePage>
// ignore: prefer_expression_function_bodies
Widget buildTabletRightPane(BuildContext context) {
//
return Chat();
return ChatComponent();
}
// ignore: prefer_expression_function_bodies
Widget buildTablet(BuildContext context) {
final theme = Theme.of(context);
final w = MediaQuery.of(context).size.width;
final children = [
buildTabletLeftPane(context),
buildTabletRightPane(context),
ConstrainedBox(
constraints: BoxConstraints(minWidth: 300, maxWidth: 300),
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: w / 2),
child: buildTabletLeftPane(context))),
Expanded(child: buildTabletRightPane(context)),
];
final multiSplitView = MultiSplitView(
// onWeightChange: _onWeightChange,
// onDividerTap: _onDividerTap,
// onDividerDoubleTap: _onDividerDoubleTap,
controller: _splitController,
children: children);
return Row(
children: children,
);
final theme = MultiSplitViewTheme(
data: isDesktop
? MultiSplitViewThemeData(
dividerThickness: 1,
dividerPainter: DividerPainters.grooved2(thickness: 1))
: MultiSplitViewThemeData(
dividerThickness: 3,
dividerPainter: DividerPainters.grooved2(thickness: 1)),
child: multiSplitView);
return theme;
// final theme = MultiSplitViewTheme(
// data: isDesktop
// ? MultiSplitViewThemeData(
// dividerThickness: 1,
// dividerPainter: DividerPainters.grooved2(thickness: 1))
// : MultiSplitViewThemeData(
// dividerThickness: 3,
// dividerPainter: DividerPainters.grooved2(thickness: 1)),
// child: multiSplitView);
}
@override

View file

@ -1,67 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:window_manager/window_manager.dart';
import '../components/account_bubble.dart';
import '../providers/local_accounts.dart';
import '../providers/logins.dart';
class LoginPage extends ConsumerWidget {
const LoginPage({super.key});
static const path = '/login';
// void _onReorder(WidgetRef ref, int oldIndex, int newIndex) {
// final accounts = ref.read(localAccountsProvider.notifier);
// accounts.reorderAccount(oldIndex, newIndex);
// // xxx fix this so we can await this properly, use FutureBuilder or whatever
// }
@override
Widget build(BuildContext context, WidgetRef ref) {
windowManager.setTitleBarStyle(TitleBarStyle.normal);
final accounts = ref.watch(localAccountsProvider);
final logins = ref.watch(loginsProvider);
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text('Accounts'),
actions: <Widget>[
IconButton(
icon: const Icon(Icons.settings),
tooltip: 'Accessibility',
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content:
Text('Accessibility and language options coming soon')));
},
),
],
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(height: 100, color: const Color.fromARGB(255, 255, 0, 0)),
const Spacer(),
// accounts.when(
// error: (obj, err) => Text("error loading accounts: $err"),
// loading: () => CircularProgressIndicator(),
// data: (accountList) => ReorderableGridView.extent(
// maxCrossAxisExtent: 128,
// onReorder: (oldIndex, newIndex) =>
// _onReorder(ref, oldIndex, newIndex),
// children: accountList.map<Widget>((account) {
// return AccountBubble(
// key: ValueKey(
// account.identityMaster.masterRecordKey),
// account: account);
// }).toList(),
// )),
const AddAccountBubble(key: ValueKey('+')),
const Spacer(),
Container(height: 100, color: const Color.fromARGB(255, 0, 255, 0)),
],
),
);
}
}

View file

@ -5,6 +5,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_translate/flutter_translate.dart';
import 'package:veilid/veilid.dart';
import '../../components/contact_list_widget.dart';
import '../../components/profile.dart';
import '../../entities/local_account.dart';
import '../../entities/proto.dart' as proto;
@ -23,6 +24,7 @@ class AccountPage extends ConsumerStatefulWidget {
class AccountPageState extends ConsumerState<AccountPage> {
final _unfocusNode = FocusNode();
TypedKey? _selectedAccount;
List<proto.Contact> _contactList = List<proto.Contact>.empty(growable: true);
@override
void initState() {
@ -36,13 +38,11 @@ class AccountPageState extends ConsumerState<AccountPage> {
super.dispose();
}
@override
// ignore: prefer_expression_function_bodies
Widget buildAccountList(BuildContext context) {
return Center(child: Text("account list"));
}
@override
Widget buildUnlockAccount(
BuildContext context,
IList<LocalAccount> localAccounts,
@ -51,7 +51,6 @@ class AccountPageState extends ConsumerState<AccountPage> {
return Center(child: Text("unlock account"));
}
@override
Widget buildUserAccount(
BuildContext context,
IList<LocalAccount> localAccounts,
@ -59,8 +58,10 @@ class AccountPageState extends ConsumerState<AccountPage> {
proto.Account account,
// ignore: prefer_expression_function_bodies
) {
return ProfileWidget(
name: account.profile.name, title: account.profile.title);
return Column(children: <Widget>[
ProfileWidget(name: account.profile.name, title: account.profile.title),
ContactListWidget(contactList: _contactList)
]);
}
@override

View file

@ -1,30 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
class ContactsPage extends ConsumerStatefulWidget {
const ContactsPage({super.key});
@override
ContactsPageState createState() => ContactsPageState();
}
class ContactsPageState extends ConsumerState<ContactsPage> {
final _unfocusNode = FocusNode();
@override
void initState() {
super.initState();
}
@override
void dispose() {
_unfocusNode.dispose();
super.dispose();
}
@override
// ignore: prefer_expression_function_bodies
Widget build(BuildContext context) {
return Center(child: Text("Contacts Page"));
}
}

View file

@ -7,7 +7,6 @@ import 'package:stylish_bottom_bar/model/bar_items.dart';
import 'package:stylish_bottom_bar/stylish_bottom_bar.dart';
import 'account_page.dart';
import 'contacts_page.dart';
import 'chats_page.dart';
class MainPager extends ConsumerStatefulWidget {
@ -26,30 +25,22 @@ class MainPagerState extends ConsumerState<MainPager>
final _pageController = PageController();
var _currentPage = 0;
final _selectedIconList = <IconData>[
Icons.chat,
Icons.contacts,
Icons.person
];
final _selectedIconList = <IconData>[Icons.person, Icons.chat];
// final _unselectedIconList = <IconData>[
// Icons.chat_outlined,
// Icons.contacts_outlined,
// Icons.person_outlined
// ];
final _fabIconList = <IconData>[
Icons.add_comment_sharp,
Icons.person_add_sharp,
Icons.settings_sharp,
Icons.add_comment_sharp,
];
final _labelList = <String>[
translate('pager.chats'),
translate('pager.contacts'),
translate('pager.account'),
translate('pager.chats'),
];
final List<Widget> _bottomBarPages = [
const ChatsPage(),
const ContactsPage(),
const AccountPage(),
const ChatsPage(),
];
//////////////////////////////////////////////////////////////////
@ -154,7 +145,7 @@ class MainPagerState extends ConsumerState<MainPager>
currentIndex: _currentPage,
onTap: (index) async {
await _pageController.animateToPage(index,
duration: 250.ms, curve: Curves.bounceOut);
duration: 250.ms, curve: Curves.easeInOut);
setState(() {
_currentPage = index;
});

View file

@ -29,6 +29,17 @@ class NewAccountPageState extends ConsumerState<NewAccountPage> {
static const String formFieldName = 'name';
static const String formFieldTitle = 'title';
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) async {
setState(() {});
await ref.read(windowControlProvider.notifier).changeWindowSetup(
TitleBarStyle.normal, OrientationCapability.portraitOnly);
});
}
Future<void> createAccount() async {
final imws = await newIdentityMaster();
try {

View file

@ -1,4 +0,0 @@
export 'home.dart';
export 'index.dart';
export 'login.dart';
export 'new_account.dart';

View file

@ -112,7 +112,7 @@ class FetchLocalAccountProvider
}
}
String _$localAccountsHash() => r'c8214abbc9720449910e74e32fc52d53ca4453c0';
String _$localAccountsHash() => r'd6ced0ad7108c1111603235cf394faa5f6bcdae1';
/// See also [LocalAccounts].
@ProviderFor(LocalAccounts)

View file

@ -1,4 +1,4 @@
export 'account_profile.dart';
export 'account.dart';
export 'connection_state.dart';
export 'local_accounts.dart';
export 'logins.dart';

View file

@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../pages/pages.dart';
import '../pages/index.dart';
import 'router_notifier.dart';
part 'router.g.dart';

View file

@ -2,7 +2,9 @@ import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../pages/pages.dart';
import '../pages/home.dart';
import '../pages/index.dart';
import '../pages/new_account.dart';
import '../providers/local_accounts.dart';
part 'router_notifier.g.dart';

View file

@ -1,6 +1,9 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:radix_colors/radix_colors.dart';
import 'theme_service.dart';
enum RadixThemeColor {
scarlet, // tomato + red + violet
babydoll, // crimson + purple + pink
@ -265,174 +268,247 @@ RadixColor _radixColorSteps(
}
}
ColorScheme _radixColorScheme(
// ignore: prefer_expression_function_bodies
Brightness brightness,
RadixThemeColor themeColor) {
late RadixColor primaryScale;
late RadixColor primaryAlphaScale;
late RadixColor secondaryScale;
late RadixColor tertiaryScale;
late RadixColor grayScale;
late RadixColor errorScale;
extension ToScaleColor on RadixColor {
ScaleColor toScale() => ScaleColor(
appBackground: step1,
subtleBackground: step2,
elementBackground: step3,
hoverElementBackground: step4,
activedElementBackground: step5,
subtleBorder: step6,
border: step7,
hoverBorder: step8,
background: step9,
hoverBackground: step10,
subtleText: step11,
text: step12,
);
}
class RadixScheme {
RadixScheme(
{required this.primaryScale,
required this.primaryAlphaScale,
required this.secondaryScale,
required this.tertiaryScale,
required this.grayScale,
required this.errorScale});
RadixColor primaryScale;
RadixColor primaryAlphaScale;
RadixColor secondaryScale;
RadixColor tertiaryScale;
RadixColor grayScale;
RadixColor errorScale;
ScaleScheme toScale() => ScaleScheme(
primaryScale: primaryScale.toScale(),
primaryAlphaScale: primaryAlphaScale.toScale(),
secondaryScale: secondaryScale.toScale(),
tertiaryScale: tertiaryScale.toScale(),
grayScale: grayScale.toScale(),
errorScale: errorScale.toScale(),
);
}
RadixScheme _radixScheme(Brightness brightness, RadixThemeColor themeColor) {
late RadixScheme radixScheme;
switch (themeColor) {
// tomato + red + violet
case RadixThemeColor.scarlet:
primaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.tomato);
primaryAlphaScale =
_radixColorSteps(brightness, true, _RadixBaseColor.tomato);
secondaryScale = _radixColorSteps(brightness, false, _RadixBaseColor.red);
tertiaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.violet);
grayScale = _radixGraySteps(brightness, false, _RadixBaseColor.tomato);
errorScale = _radixColorSteps(brightness, false, _RadixBaseColor.yellow);
radixScheme = RadixScheme(
primaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.tomato),
primaryAlphaScale:
_radixColorSteps(brightness, true, _RadixBaseColor.tomato),
secondaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.red),
tertiaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.violet),
grayScale: _radixGraySteps(brightness, false, _RadixBaseColor.tomato),
errorScale:
_radixColorSteps(brightness, false, _RadixBaseColor.yellow));
// crimson + purple + pink
case RadixThemeColor.babydoll:
primaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.crimson);
primaryAlphaScale =
_radixColorSteps(brightness, true, _RadixBaseColor.crimson);
secondaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.purple);
tertiaryScale = _radixColorSteps(brightness, false, _RadixBaseColor.pink);
grayScale = _radixGraySteps(brightness, false, _RadixBaseColor.crimson);
errorScale = _radixColorSteps(brightness, false, _RadixBaseColor.orange);
radixScheme = RadixScheme(
primaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.crimson),
primaryAlphaScale:
_radixColorSteps(brightness, true, _RadixBaseColor.crimson),
secondaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.purple),
tertiaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.pink),
grayScale:
_radixGraySteps(brightness, false, _RadixBaseColor.crimson),
errorScale:
_radixColorSteps(brightness, false, _RadixBaseColor.orange));
// pink + cyan + plum
case RadixThemeColor.vapor:
primaryScale = _radixColorSteps(brightness, false, _RadixBaseColor.pink);
primaryAlphaScale =
_radixColorSteps(brightness, true, _RadixBaseColor.pink);
secondaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.cyan);
tertiaryScale = _radixColorSteps(brightness, false, _RadixBaseColor.plum);
grayScale = _radixGraySteps(brightness, false, _RadixBaseColor.pink);
errorScale = _radixColorSteps(brightness, false, _RadixBaseColor.red);
radixScheme = RadixScheme(
primaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.pink),
primaryAlphaScale:
_radixColorSteps(brightness, true, _RadixBaseColor.pink),
secondaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.cyan),
tertiaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.plum),
grayScale: _radixGraySteps(brightness, false, _RadixBaseColor.pink),
errorScale: _radixColorSteps(brightness, false, _RadixBaseColor.red));
// yellow + amber + orange
case RadixThemeColor.gold:
primaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.yellow);
primaryAlphaScale =
_radixColorSteps(brightness, true, _RadixBaseColor.yellow);
secondaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.amber);
tertiaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.orange);
grayScale = _radixGraySteps(brightness, false, _RadixBaseColor.yellow);
errorScale = _radixColorSteps(brightness, false, _RadixBaseColor.red);
radixScheme = RadixScheme(
primaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.yellow),
primaryAlphaScale:
_radixColorSteps(brightness, true, _RadixBaseColor.yellow),
secondaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.amber),
tertiaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.orange),
grayScale: _radixGraySteps(brightness, false, _RadixBaseColor.yellow),
errorScale: _radixColorSteps(brightness, false, _RadixBaseColor.red));
// grass + orange + brown
case RadixThemeColor.garden:
primaryScale = _radixColorSteps(brightness, false, _RadixBaseColor.grass);
primaryAlphaScale =
_radixColorSteps(brightness, true, _RadixBaseColor.grass);
secondaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.orange);
tertiaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.brown);
grayScale = _radixGraySteps(brightness, false, _RadixBaseColor.grass);
errorScale = _radixColorSteps(brightness, false, _RadixBaseColor.tomato);
radixScheme = RadixScheme(
primaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.grass),
primaryAlphaScale:
_radixColorSteps(brightness, true, _RadixBaseColor.grass),
secondaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.orange),
tertiaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.brown),
grayScale: _radixGraySteps(brightness, false, _RadixBaseColor.grass),
errorScale:
_radixColorSteps(brightness, false, _RadixBaseColor.tomato));
// green + brown + amber
case RadixThemeColor.forest:
primaryScale = _radixColorSteps(brightness, false, _RadixBaseColor.green);
primaryAlphaScale =
_radixColorSteps(brightness, true, _RadixBaseColor.green);
secondaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.brown);
tertiaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.amber);
grayScale = _radixGraySteps(brightness, false, _RadixBaseColor.green);
errorScale = _radixColorSteps(brightness, false, _RadixBaseColor.tomato);
radixScheme = RadixScheme(
primaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.green),
primaryAlphaScale:
_radixColorSteps(brightness, true, _RadixBaseColor.green),
secondaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.brown),
tertiaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.amber),
grayScale: _radixGraySteps(brightness, false, _RadixBaseColor.green),
errorScale:
_radixColorSteps(brightness, false, _RadixBaseColor.tomato));
// sky + teal + violet
case RadixThemeColor.arctic:
primaryScale = _radixColorSteps(brightness, false, _RadixBaseColor.sky);
primaryAlphaScale =
_radixColorSteps(brightness, true, _RadixBaseColor.sky);
secondaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.teal);
tertiaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.violet);
grayScale = _radixGraySteps(brightness, false, _RadixBaseColor.sky);
errorScale = _radixColorSteps(brightness, false, _RadixBaseColor.crimson);
radixScheme = RadixScheme(
primaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.sky),
primaryAlphaScale:
_radixColorSteps(brightness, true, _RadixBaseColor.sky),
secondaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.teal),
tertiaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.violet),
grayScale: _radixGraySteps(brightness, false, _RadixBaseColor.sky),
errorScale:
_radixColorSteps(brightness, false, _RadixBaseColor.crimson));
// blue + indigo + mint
case RadixThemeColor.lapis:
primaryScale = _radixColorSteps(brightness, false, _RadixBaseColor.blue);
primaryAlphaScale =
_radixColorSteps(brightness, true, _RadixBaseColor.blue);
secondaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.indigo);
tertiaryScale = _radixColorSteps(brightness, false, _RadixBaseColor.mint);
grayScale = _radixGraySteps(brightness, false, _RadixBaseColor.blue);
errorScale = _radixColorSteps(brightness, false, _RadixBaseColor.crimson);
radixScheme = RadixScheme(
primaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.blue),
primaryAlphaScale:
_radixColorSteps(brightness, true, _RadixBaseColor.blue),
secondaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.indigo),
tertiaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.mint),
grayScale: _radixGraySteps(brightness, false, _RadixBaseColor.blue),
errorScale:
_radixColorSteps(brightness, false, _RadixBaseColor.crimson));
// violet + purple + indigo
case RadixThemeColor.eggplant:
primaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.violet);
primaryAlphaScale =
_radixColorSteps(brightness, true, _RadixBaseColor.violet);
secondaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.purple);
tertiaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.indigo);
grayScale = _radixGraySteps(brightness, false, _RadixBaseColor.violet);
errorScale = _radixColorSteps(brightness, false, _RadixBaseColor.crimson);
radixScheme = RadixScheme(
primaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.violet),
primaryAlphaScale:
_radixColorSteps(brightness, true, _RadixBaseColor.violet),
secondaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.purple),
tertiaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.indigo),
grayScale: _radixGraySteps(brightness, false, _RadixBaseColor.violet),
errorScale:
_radixColorSteps(brightness, false, _RadixBaseColor.crimson));
// lime + yellow + orange
case RadixThemeColor.lime:
primaryScale = _radixColorSteps(brightness, false, _RadixBaseColor.lime);
primaryAlphaScale =
_radixColorSteps(brightness, true, _RadixBaseColor.lime);
secondaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.yellow);
tertiaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.orange);
grayScale = _radixGraySteps(brightness, false, _RadixBaseColor.lime);
errorScale = _radixColorSteps(brightness, false, _RadixBaseColor.red);
radixScheme = RadixScheme(
primaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.lime),
primaryAlphaScale:
_radixColorSteps(brightness, true, _RadixBaseColor.lime),
secondaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.yellow),
tertiaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.orange),
grayScale: _radixGraySteps(brightness, false, _RadixBaseColor.lime),
errorScale: _radixColorSteps(brightness, false, _RadixBaseColor.red));
// mauve + slate + sage
case RadixThemeColor.grim:
primaryScale = _radixGraySteps(brightness, false, _RadixBaseColor.tomato);
primaryAlphaScale =
_radixColorSteps(brightness, true, _RadixBaseColor.tomato);
secondaryScale =
_radixColorSteps(brightness, false, _RadixBaseColor.indigo);
tertiaryScale = _radixColorSteps(brightness, false, _RadixBaseColor.teal);
grayScale = brightness == Brightness.dark
? RadixColors.dark.gray
: RadixColors.gray;
errorScale = _radixColorSteps(brightness, false, _RadixBaseColor.red);
radixScheme = RadixScheme(
primaryScale:
_radixGraySteps(brightness, false, _RadixBaseColor.tomato),
primaryAlphaScale:
_radixColorSteps(brightness, true, _RadixBaseColor.tomato),
secondaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.indigo),
tertiaryScale:
_radixColorSteps(brightness, false, _RadixBaseColor.teal),
grayScale: brightness == Brightness.dark
? RadixColors.dark.gray
: RadixColors.gray,
errorScale: _radixColorSteps(brightness, false, _RadixBaseColor.red));
}
return radixScheme;
}
return ColorScheme(
ExtendedColorScheme _radixColorScheme(
Brightness brightness, RadixThemeColor themeColor) {
final radix = _radixScheme(brightness, themeColor);
return ExtendedColorScheme(
scaleScheme: radix.toScale(),
brightness: brightness,
primary: primaryScale.step9,
onPrimary: primaryScale.step12,
primaryContainer: primaryScale.step3,
onPrimaryContainer: primaryScale.step11,
secondary: secondaryScale.step9,
onSecondary: secondaryScale.step12,
secondaryContainer: secondaryScale.step3,
onSecondaryContainer: secondaryScale.step11,
tertiary: tertiaryScale.step9,
onTertiary: tertiaryScale.step12,
tertiaryContainer: tertiaryScale.step3,
onTertiaryContainer: tertiaryScale.step11,
error: errorScale.step9,
onError: errorScale.step12,
errorContainer: errorScale.step3,
onErrorContainer: errorScale.step11,
background: primaryScale.step1, //gray scale?
onBackground: primaryScale.step12,
surface: primaryScale.step2, //gray scale?
onSurface: primaryScale.step11,
surfaceVariant: primaryScale.step3, //gray scale?
onSurfaceVariant: primaryScale.step11,
outline: primaryScale.step7,
outlineVariant: primaryScale.step6,
primary: radix.primaryScale.step9,
onPrimary: radix.primaryScale.step12,
primaryContainer: radix.primaryScale.step4,
onPrimaryContainer: radix.primaryScale.step11,
secondary: radix.secondaryScale.step9,
onSecondary: radix.secondaryScale.step12,
secondaryContainer: radix.secondaryScale.step3,
onSecondaryContainer: radix.secondaryScale.step11,
tertiary: radix.tertiaryScale.step9,
onTertiary: radix.tertiaryScale.step12,
tertiaryContainer: radix.tertiaryScale.step3,
onTertiaryContainer: radix.tertiaryScale.step11,
error: radix.errorScale.step9,
onError: radix.errorScale.step12,
errorContainer: radix.errorScale.step3,
onErrorContainer: radix.errorScale.step11,
background: radix.grayScale.step1,
onBackground: radix.grayScale.step11,
surface: radix.primaryScale.step1,
onSurface: radix.primaryScale.step12,
surfaceVariant: radix.secondaryScale.step2,
onSurfaceVariant: radix.secondaryScale.step11,
outline: radix.primaryScale.step7,
outlineVariant: radix.primaryScale.step6,
shadow: RadixColors.dark.gray.step1,
scrim: primaryScale.step4,
inverseSurface: primaryScale.step11,
onInverseSurface: primaryScale.step2,
inversePrimary: primaryScale.step10,
surfaceTint: primaryAlphaScale.step9,
scrim: radix.primaryScale.step9,
inverseSurface: radix.primaryScale.step11,
onInverseSurface: radix.primaryScale.step2,
inversePrimary: radix.primaryScale.step10,
surfaceTint: radix.primaryAlphaScale.step4,
);
}

View file

@ -1,11 +1,112 @@
// ignore_for_file: always_put_required_named_parameters_first
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../entities/preferences.dart';
import 'radix_generator.dart';
@immutable
class ExtendedColorScheme extends ColorScheme {
const ExtendedColorScheme({
required this.scaleScheme,
required super.brightness,
required super.primary,
required super.onPrimary,
super.primaryContainer,
super.onPrimaryContainer,
required super.secondary,
required super.onSecondary,
super.secondaryContainer,
super.onSecondaryContainer,
super.tertiary,
super.onTertiary,
super.tertiaryContainer,
super.onTertiaryContainer,
required super.error,
required super.onError,
super.errorContainer,
super.onErrorContainer,
required super.background,
required super.onBackground,
required super.surface,
required super.onSurface,
super.surfaceVariant,
super.onSurfaceVariant,
super.outline,
super.outlineVariant,
super.shadow,
super.scrim,
super.inverseSurface,
super.onInverseSurface,
super.inversePrimary,
super.surfaceTint,
});
final ScaleScheme scaleScheme;
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<ScaleScheme>('scales', scaleScheme));
}
}
class ScaleColor {
ScaleColor({
required this.appBackground,
required this.subtleBackground,
required this.elementBackground,
required this.hoverElementBackground,
required this.activedElementBackground,
required this.subtleBorder,
required this.border,
required this.hoverBorder,
required this.background,
required this.hoverBackground,
required this.subtleText,
required this.text,
});
Color appBackground;
Color subtleBackground;
Color elementBackground;
Color hoverElementBackground;
Color activedElementBackground;
Color subtleBorder;
Color border;
Color hoverBorder;
Color background;
Color hoverBackground;
Color subtleText;
Color text;
}
class ScaleScheme {
ScaleScheme(
{required this.primaryScale,
required this.primaryAlphaScale,
required this.secondaryScale,
required this.tertiaryScale,
required this.grayScale,
required this.errorScale});
ScaleColor primaryScale;
ScaleColor primaryAlphaScale;
ScaleColor secondaryScale;
ScaleColor tertiaryScale;
ScaleColor grayScale;
ScaleColor errorScale;
static ScaleScheme of(BuildContext context) =>
(Theme.of(context).colorScheme as ExtendedColorScheme).scaleScheme;
}
////////////////////////////////////////////////////////////////////////
class ThemeService {
ThemeService._();
static late SharedPreferences prefs;