From 891ca417cd680c9296f4a01d22307e3893ebcb1e Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Sat, 21 Dec 2019 17:26:26 +0800 Subject: [PATCH] refactor: using palette --- lib/main.dart | 11 +++++------ lib/models/theme.dart | 2 +- lib/utils/utils.dart | 8 +++++--- lib/widgets/table_view.dart | 16 ++++++++-------- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 555e2b4..1c81bcc 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -21,7 +21,6 @@ import 'package:git_touch/screens/settings.dart'; import 'package:git_touch/screens/stargazers.dart'; import 'package:git_touch/screens/user.dart'; import 'package:git_touch/screens/watchers.dart'; -import 'package:primer/primer.dart'; import 'package:provider/provider.dart'; import 'package:git_touch/models/notification.dart'; import 'package:fluro/fluro.dart'; @@ -43,6 +42,7 @@ class _HomeState extends State { // String login; Widget _buildNotificationIcon(BuildContext context, bool isActive) { + final theme = Provider.of(context); final iconData = isActive ? Icons.notifications : Icons.notifications_none; int count = Provider.of(context).count; if (count == 0) { @@ -57,7 +57,7 @@ class _HomeState extends State { right: -2, top: -2, child: Icon(Octicons.primitive_dot, - color: PrimerColors.red500, size: 14)) + color: theme.palette.primary, size: 14)) ], ); } @@ -150,8 +150,7 @@ class _HomeState extends State { final themData = ThemeData( brightness: theme.brightness, - primaryColor: PrimerColors.white, - accentColor: PrimerColors.blue500, + primaryColor: Colors.white, ); // TODO: @@ -169,7 +168,7 @@ class _HomeState extends State { return CupertinoApp( theme: CupertinoThemeData( brightness: theme.brightness, - primaryColor: PrimerColors.blue500, + primaryColor: theme.palette.primary, ), home: CupertinoTabScaffold( tabBar: CupertinoTabBar(items: _navigationItems), @@ -189,7 +188,7 @@ class _HomeState extends State { body: _buildScreen(active), bottomNavigationBar: BottomNavigationBar( backgroundColor: Colors.white, - selectedItemColor: PrimerColors.blue500, + selectedItemColor: theme.palette.primary, items: _navigationItems, currentIndex: active, type: BottomNavigationBarType.fixed, diff --git a/lib/models/theme.dart b/lib/models/theme.dart index 34718e2..60fc005 100644 --- a/lib/models/theme.dart +++ b/lib/models/theme.dart @@ -117,7 +117,7 @@ class ThemeModel with ChangeNotifier { ); case Brightness.dark: return Palette( - primary: PrimerColors.blue400, + primary: PrimerColors.blue500, text: PrimerColors.gray300, secondaryText: PrimerColors.gray400, tertiaryText: PrimerColors.gray500, diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 44ea464..aac7346 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -63,15 +63,16 @@ TextSpan createLinkSpan( String text, String url, ) { + final theme = Provider.of(context); return TextSpan( text: text, style: TextStyle( - color: PrimerColors.blue500, + color: theme.palette.primary, fontWeight: FontWeight.w600, ), recognizer: TapGestureRecognizer() ..onTap = () { - Provider.of(context).push(context, url); + theme.push(context, url); }, ); } @@ -149,6 +150,7 @@ class PrimerBranchName extends StatelessWidget { @override Widget build(BuildContext context) { + final theme = Provider.of(context); return Container( padding: EdgeInsets.symmetric(vertical: 2, horizontal: 4), height: 16, @@ -159,7 +161,7 @@ class PrimerBranchName extends StatelessWidget { child: Text( name, style: TextStyle( - color: PrimerColors.blue500, + color: theme.palette.primary, fontSize: 14, height: 1, fontFamily: CommonStyle.monospace, diff --git a/lib/widgets/table_view.dart b/lib/widgets/table_view.dart index 5edfac5..20455ff 100644 --- a/lib/widgets/table_view.dart +++ b/lib/widgets/table_view.dart @@ -3,7 +3,6 @@ import 'package:flutter/cupertino.dart'; import 'package:git_touch/models/theme.dart'; import 'package:git_touch/utils/utils.dart'; import 'package:git_touch/widgets/border_view.dart'; -import 'package:primer/primer.dart'; import 'package:provider/provider.dart'; import 'link.dart'; @@ -14,11 +13,12 @@ class TableViewHeader extends StatelessWidget { @override Widget build(BuildContext context) { + final theme = Provider.of(context); return Container( padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6), child: Text( title.toUpperCase(), - style: TextStyle(color: PrimerColors.gray600, fontSize: 13), + style: TextStyle(color: theme.palette.secondaryText, fontSize: 13), ), ); } @@ -55,7 +55,7 @@ class TableView extends StatelessWidget { @override Widget build(BuildContext context) { - final themeModel = Provider.of(context); + final theme = Provider.of(context); return Column( crossAxisAlignment: CrossAxisAlignment.stretch, @@ -74,18 +74,18 @@ class TableView extends StatelessWidget { height: 24, decoration: BoxDecoration( borderRadius: BorderRadius.circular(12), - color: PrimerColors.blue500, + color: theme.palette.primary, ), child: Icon( item.leftIconData, - color: themeModel.palette.background, + color: theme.palette.background, size: 14, ), ); } final widget = DefaultTextStyle( - style: TextStyle(fontSize: 17, color: themeModel.palette.text), + style: TextStyle(fontSize: 17, color: theme.palette.text), overflow: TextOverflow.ellipsis, child: Container( height: 44, @@ -100,7 +100,7 @@ class TableView extends StatelessWidget { DefaultTextStyle( style: TextStyle( fontSize: 16, - color: themeModel.palette.tertiaryText, + color: theme.palette.tertiaryText, ), child: item.rightWidget, ), @@ -109,7 +109,7 @@ class TableView extends StatelessWidget { if ((item.onTap != null || item.url != null) && !item.hideRightChevron) Icon(CupertinoIcons.right_chevron, - size: 20, color: themeModel.palette.tertiaryText) + size: 20, color: theme.palette.tertiaryText) else SizedBox(width: 2), SizedBox(width: 8),