Skip to content

Commit

Permalink
feat: cupertino dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed Nov 5, 2019
1 parent bfc41cd commit 1b7578f
Show file tree
Hide file tree
Showing 18 changed files with 300 additions and 240 deletions.
39 changes: 20 additions & 19 deletions lib/main.dart
Expand Up @@ -131,40 +131,41 @@ class _HomeState extends State<Home> {

@override
Widget build(BuildContext context) {
var settings = Provider.of<AuthModel>(context);
var themData = ThemeData(
final authModel = Provider.of<AuthModel>(context);
final themeModel = Provider.of<ThemeModel>(context);

final themData = ThemeData(
brightness: themeModel.brightness,
primaryColor: PrimerColors.white,
accentColor: PrimerColors.blue500,
);

// TODO:
if (!settings.ready || !Provider.of<ThemeModel>(context).ready) {
if (!authModel.ready || !Provider.of<ThemeModel>(context).ready) {
return MaterialApp(theme: themData, home: Scaffold(body: Text('a')));
}

// Fimber.d(settings.activeLogin);
if (settings.activeAccount == null) {
if (authModel.activeAccount == null) {
return MaterialApp(theme: themData, home: LoginScreen());
}

switch (Provider.of<ThemeModel>(context).theme) {
switch (themeModel.theme) {
case AppThemeType.cupertino:
return CupertinoApp(
home: CupertinoTheme(
data: CupertinoThemeData(
primaryColor: PrimerColors.blue500,
),
child: CupertinoTabScaffold(
tabBar: CupertinoTabBar(
items: _navigationItems,
// backgroundColor: PrimerColors.gray000, // TODO:
),
tabBuilder: (context, index) {
return CupertinoTabView(builder: (context) {
theme: CupertinoThemeData(
brightness: themeModel.brightness,
primaryColor: PrimerColors.blue500,
),
home: CupertinoTabScaffold(
tabBar: CupertinoTabBar(items: _navigationItems),
tabBuilder: (context, index) {
return CupertinoTabView(
builder: (context) {
return _buildScreen(index);
});
},
),
},
);
},
),
);
default:
Expand Down
52 changes: 52 additions & 0 deletions lib/models/theme.dart
Expand Up @@ -4,6 +4,7 @@ import 'package:fimber/fimber.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:git_touch/widgets/action_button.dart';
import 'package:primer/primer.dart';
import 'package:shared_preferences/shared_preferences.dart';

class DialogOption<T> {
Expand Down Expand Up @@ -63,13 +64,64 @@ class StaticRoute extends PageRouteBuilder {
);
}

class Palette {
Color primary;
Color text;
Color secondaryText;
Color tertiaryText;
Color background;
Color border;

Palette({
this.primary,
this.text,
this.secondaryText,
this.tertiaryText,
this.background,
this.border,
});
}

class ThemeModel with ChangeNotifier {
static const storageKey = 'theme';

int _theme;
int get theme => _theme;
bool get ready => _theme != null;

Brightness _brightness = Brightness.dark;
Brightness get brightness => _brightness;
Future<void> setBrightness(Brightness v) async {
// TODO: Save
_brightness = v;
notifyListeners();
}

Palette get palette {
switch (brightness) {
case Brightness.light:
return Palette(
primary: PrimerColors.blue500,
text: PrimerColors.gray900,
secondaryText: PrimerColors.gray700,
tertiaryText: PrimerColors.gray500,
background: PrimerColors.white,
border: PrimerColors.gray100,
);
case Brightness.dark:
return Palette(
primary: PrimerColors.blue500,
text: PrimerColors.gray400,
secondaryText: PrimerColors.gray500,
tertiaryText: PrimerColors.gray600,
background: PrimerColors.black,
border: PrimerColors.gray900,
);
default:
return null;
}
}

Future<void> init() async {
var prefs = await SharedPreferences.getInstance();

Expand Down
7 changes: 0 additions & 7 deletions lib/scaffolds/common.dart
@@ -1,41 +1,34 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:git_touch/models/theme.dart';
import 'package:primer/primer.dart';
import 'package:provider/provider.dart';

class CommonScaffold extends StatelessWidget {
final Widget title;
final Widget body;
final Widget action;
final PreferredSizeWidget bottom;
final Color backgroundColor;

CommonScaffold({
@required this.title,
@required this.body,
this.action,
this.bottom,
this.backgroundColor = Colors.white,
});

@override
Widget build(BuildContext context) {
switch (Provider.of<ThemeModel>(context).theme) {
case AppThemeType.cupertino:
return CupertinoPageScaffold(
backgroundColor: backgroundColor,
navigationBar: CupertinoNavigationBar(
middle: title,
trailing: action,
backgroundColor: PrimerColors.gray000,
// border: Border(),
),
child: SafeArea(child: body),
);
default:
return Scaffold(
backgroundColor: backgroundColor,
appBar: AppBar(
title: title,
actions: [
Expand Down
2 changes: 0 additions & 2 deletions lib/scaffolds/refresh_stateful.dart
Expand Up @@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:git_touch/scaffolds/common.dart';
import 'package:git_touch/scaffolds/utils.dart';
import 'package:primer/primer.dart';

class RefreshStatefulScaffold<T> extends StatefulWidget {
final Widget title;
Expand Down Expand Up @@ -64,7 +63,6 @@ class _RefreshStatefulScaffoldState<T>
@override
Widget build(BuildContext context) {
return CommonScaffold(
backgroundColor: _data == null ? Colors.white : PrimerColors.gray100,
title: widget.title,
body: RefreshWrapper(
onRefresh: _refresh,
Expand Down
3 changes: 0 additions & 3 deletions lib/scaffolds/single.dart
Expand Up @@ -5,13 +5,11 @@ class SingleScaffold extends StatelessWidget {
final Widget title;
final Widget body;
final Widget action;
final Color backgroundColor;

SingleScaffold({
@required this.title,
@required this.body,
this.action,
this.backgroundColor,
});

@override
Expand All @@ -20,7 +18,6 @@ class SingleScaffold extends StatelessWidget {
title: title,
body: Scrollbar(child: SingleChildScrollView(child: body)),
action: action,
backgroundColor: backgroundColor,
);
}
}
6 changes: 5 additions & 1 deletion lib/screens/image_view.dart
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:git_touch/models/theme.dart';
import 'package:git_touch/scaffolds/common.dart';
import 'package:photo_view/photo_view.dart';
import 'package:provider/provider.dart';

class ImageViewScreen extends StatelessWidget {
final String url;
Expand All @@ -10,11 +12,13 @@ class ImageViewScreen extends StatelessWidget {

@override
Widget build(BuildContext context) {
final theme = Provider.of<ThemeModel>(context);

return CommonScaffold(
title: title,
body: PhotoView(
imageProvider: NetworkImage(url),
backgroundDecoration: BoxDecoration(color: Colors.white),
backgroundDecoration: BoxDecoration(color: theme.palette.background),
),
);
}
Expand Down
20 changes: 11 additions & 9 deletions lib/screens/repository.dart
Expand Up @@ -211,15 +211,17 @@ class RepositoryScreen extends StatelessWidget {
child: SizedBox(
height: 10,
child: Row(
children: join(
SizedBox(width: 1),
(repo['languages']['edges'] as List)
.map((lang) => Container(
color: convertColor(lang['node']['color']),
width: langWidth *
lang['size'] /
repo['languages']['totalSize']))
.toList())),
children: join(
SizedBox(width: 1),
(repo['languages']['edges'] as List)
.map((lang) => Container(
color: convertColor(lang['node']['color']),
width: langWidth *
lang['size'] /
repo['languages']['totalSize']))
.toList(),
),
),
),
),
),
Expand Down
2 changes: 0 additions & 2 deletions lib/screens/settings.dart
Expand Up @@ -7,7 +7,6 @@ import 'package:git_touch/screens/issue_form.dart';
import 'package:git_touch/screens/repository.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:primer/primer.dart';
import 'package:provider/provider.dart';
import 'package:launch_review/launch_review.dart';
import '../widgets/table_view.dart';
Expand All @@ -25,7 +24,6 @@ class SettingsScreen extends StatelessWidget {

return SingleScaffold(
title: AppBarTitle('Settings'),
backgroundColor: PrimerColors.gray000,
body: Column(
children: <Widget>[
CommonStyle.verticalGap,
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/utils.dart
Expand Up @@ -25,7 +25,7 @@ class StorageKeys {

class CommonStyle {
static const padding = EdgeInsets.all(12);
static const border = BorderView();
static final border = BorderView();
static const verticalGap = SizedBox(height: 18);
static final monospace = Platform.isIOS ? 'Menlo' : 'monospace'; // FIXME:
}
Expand Down Expand Up @@ -87,7 +87,7 @@ Tuple2<String, String> parseRepositoryFullName(String fullName) {
return Tuple2(ls[0], ls[1]);
}

class Palette {
class GithubPalette {
static const green = Color(0xff2cbe4e);
}

Expand Down
28 changes: 13 additions & 15 deletions lib/widgets/border_view.dart
@@ -1,39 +1,37 @@
import 'package:flutter/material.dart';
import 'package:primer/primer.dart';
import 'package:git_touch/models/theme.dart';
import 'package:provider/provider.dart';

class BorderView extends StatelessWidget {
final double height;
final Color color;
final double leftPadding;

const BorderView({
BorderView({
this.height = 1,
this.color = PrimerColors.gray100,
this.leftPadding = 0,
});

@override
Widget build(BuildContext context) {
final b = SizedBox(
height: height,
child: DecoratedBox(
decoration: BoxDecoration(color: color),
),
);
if (leftPadding == 0) {
return b;
}
final theme = Provider.of<ThemeModel>(context);

return Row(
children: <Widget>[
SizedBox(
width: leftPadding,
height: height,
child: DecoratedBox(
decoration: BoxDecoration(color: PrimerColors.white),
decoration: BoxDecoration(color: theme.palette.background),
),
),
Expanded(
child: SizedBox(
height: height,
child: DecoratedBox(
decoration: BoxDecoration(color: theme.palette.border),
),
),
),
Expanded(child: b),
],
);

Expand Down
13 changes: 10 additions & 3 deletions lib/widgets/entry_item.dart
@@ -1,6 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:git_touch/models/theme.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:primer/primer.dart';
import 'package:provider/provider.dart';
import 'link.dart';

class EntryItem extends StatelessWidget {
Expand All @@ -13,6 +14,8 @@ class EntryItem extends StatelessWidget {

@override
Widget build(BuildContext context) {
final theme = Provider.of<ThemeModel>(context);

return Expanded(
child: Link(
child: Container(
Expand All @@ -21,13 +24,17 @@ class EntryItem extends StatelessWidget {
children: <Widget>[
Text(
numberFormat.format(count),
style: TextStyle(fontSize: 17, fontWeight: FontWeight.w600),
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w600,
color: theme.palette.text,
),
),
Text(
text,
style: TextStyle(
fontSize: 12,
color: PrimerColors.gray700,
color: theme.palette.secondaryText,
fontWeight: FontWeight.w500,
),
)
Expand Down

0 comments on commit 1b7578f

Please sign in to comment.