Skip to content

Commit

Permalink
✨ improve structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
iota9star committed Jun 10, 2021
1 parent 01305e4 commit f1f457d
Show file tree
Hide file tree
Showing 21 changed files with 79 additions and 49 deletions.
28 changes: 14 additions & 14 deletions lib/internal/hive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ class MyHive {

static const int THEME_ITEM = 1;

static const int MIAKN_BANGUMI = 2;
static const int MIAKN_BANGUMI_ROW = 3;
static const int MIAKN_CAROUSEL = 4;
static const int MIAKN_INDEX = 5;
static const int MIAKN_USER = 6;
static const int MIAKN_SUBGROUP = 7;
static const int MIAKN_SEASON = 8;
static const int MIAKN_YEARSEASON = 9;
static const int MIAKN_RECORD_ITEM = 10;
static const int MIAKN_ITEM_LOCATION = 11;
static const int MIKAN_BANGUMI = THEME_ITEM + 1;
static const int MIKAN_BANGUMI_ROW = MIKAN_BANGUMI + 1;
static const int MIKAN_CAROUSEL = MIKAN_BANGUMI_ROW + 1;
static const int MIKAN_INDEX = MIKAN_CAROUSEL + 1;
static const int MIKAN_USER = MIKAN_INDEX + 1;
static const int MIKAN_SUBGROUP = MIKAN_USER + 1;
static const int MIKAN_SEASON = MIKAN_SUBGROUP + 1;
static const int MIKAN_YEAR_SEASON = MIKAN_SEASON + 1;
static const int MIKAN_RECORD_ITEM = MIKAN_YEAR_SEASON + 1;
static const int MIKAN_ITEM_LOCATION = MIKAN_RECORD_ITEM + 1;

static late Box<ThemeItem> themeItemBox;
static late Box<Index> indexBox;
Expand All @@ -55,12 +55,12 @@ class MyHive {
..canDelete = false
..autoMode = true
..isDark = false
..primaryColor = HexColor.fromHex("#3bc0c3").value
..accentColor = HexColor.fromHex("#fe9b36").value
..primaryColor = HexColor.fromHex("#39c7a5").value
..accentColor = HexColor.fromHex("#f94800").value
..lightBackgroundColor = Colors.white.value
..darkBackgroundColor = HexColor.fromHex("#293444").value
..darkBackgroundColor = HexColor.fromHex("#132149").value
..lightScaffoldBackgroundColor = HexColor.fromHex("#f1f2f7").value
..darkScaffoldBackgroundColor = HexColor.fromHex("#1c262f").value;
..darkScaffoldBackgroundColor = HexColor.fromHex("#000000").value;
themeItemBox.add(defaultTheme);
}
db = await Hive.openBox("DB");
Expand Down
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class MikanApp extends StatelessWidget {
),
],
child: Consumer<ThemeModel>(
builder: (context, themeModel, child) {
builder: (context, themeModel, _) {
final firebaseModel = isMobile
? Provider.of<FirebaseModel>(
context,
Expand Down Expand Up @@ -160,7 +160,7 @@ class MikanApp extends StatelessWidget {
final ThemeModel themeModel,
final FirebaseModel? firebaseModel,
) {
final ThemeData theme = themeModel.theme();
final ThemeData theme = themeModel.theme(darkTheme: !isMobile);
return Theme(
data: theme,
child: OKToast(
Expand Down
2 changes: 1 addition & 1 deletion lib/model/bangumi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:mikan_flutter/internal/hive.dart';

part 'bangumi.g.dart';

@HiveType(typeId: MyHive.MIAKN_BANGUMI)
@HiveType(typeId: MyHive.MIKAN_BANGUMI)
class Bangumi extends HiveObject {
// 番剧的id
@HiveField(0)
Expand Down
2 changes: 1 addition & 1 deletion lib/model/bangumi_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:mikan_flutter/model/bangumi.dart';

part 'bangumi_row.g.dart';

@HiveType(typeId: MyHive.MIAKN_BANGUMI_ROW)
@HiveType(typeId: MyHive.MIKAN_BANGUMI_ROW)
class BangumiRow extends HiveObject {
// 周几或者剧场版之类的名称
@HiveField(0)
Expand Down
2 changes: 1 addition & 1 deletion lib/model/carousel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:mikan_flutter/internal/hive.dart';

part 'carousel.g.dart';

@HiveType(typeId: MyHive.MIAKN_CAROUSEL)
@HiveType(typeId: MyHive.MIKAN_CAROUSEL)
class Carousel extends HiveObject {
@HiveField(0)
late String id;
Expand Down
2 changes: 1 addition & 1 deletion lib/model/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:mikan_flutter/model/year_season.dart';

part 'index.g.dart';

@HiveType(typeId: MyHive.MIAKN_INDEX)
@HiveType(typeId: MyHive.MIKAN_INDEX)
class Index extends HiveObject {
@HiveField(0)
final List<YearSeason> years;
Expand Down
2 changes: 1 addition & 1 deletion lib/model/record_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:mikan_flutter/model/subgroup.dart';

part 'record_item.g.dart';

@HiveType(typeId: MyHive.MIAKN_RECORD_ITEM)
@HiveType(typeId: MyHive.MIKAN_RECORD_ITEM)
class RecordItem {
@HiveField(0)
String? id;
Expand Down
2 changes: 1 addition & 1 deletion lib/model/season.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:mikan_flutter/internal/hive.dart';

part 'season.g.dart';

@HiveType(typeId: MyHive.MIAKN_SEASON)
@HiveType(typeId: MyHive.MIKAN_SEASON)
class Season extends HiveObject {
@HiveField(0)
late String year = "";
Expand Down
2 changes: 1 addition & 1 deletion lib/model/subgroup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:mikan_flutter/internal/hive.dart';

part 'subgroup.g.dart';

@HiveType(typeId: MyHive.MIAKN_SUBGROUP)
@HiveType(typeId: MyHive.MIKAN_SUBGROUP)
class Subgroup extends HiveObject {
@HiveField(0)
String? id;
Expand Down
49 changes: 40 additions & 9 deletions lib/model/theme_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,63 @@ class ThemeItem extends HiveObject {
late int id;

@HiveField(1)
bool canDelete = true;
late bool canDelete = true;

@HiveField(2)
bool autoMode = true;
late bool autoMode = true;

@HiveField(4)
bool isDark = false;
late bool isDark = false;

@HiveField(5)
int primaryColor = 0;
late int primaryColor = 0;

@HiveField(6)
int accentColor = 0;
late int accentColor = 0;

@HiveField(7)
int lightBackgroundColor = 0;
late int lightBackgroundColor = 0;

@HiveField(8)
int darkBackgroundColor = 0;
late int darkBackgroundColor = 0;

@HiveField(9)
int lightScaffoldBackgroundColor = 0;
late int lightScaffoldBackgroundColor = 0;

@HiveField(10)
int darkScaffoldBackgroundColor = 0;
late int darkScaffoldBackgroundColor = 0;

@HiveField(11)
String? fontFamily;

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is ThemeItem &&
runtimeType == other.runtimeType &&
id == other.id &&
canDelete == other.canDelete &&
autoMode == other.autoMode &&
isDark == other.isDark &&
primaryColor == other.primaryColor &&
accentColor == other.accentColor &&
lightBackgroundColor == other.lightBackgroundColor &&
darkBackgroundColor == other.darkBackgroundColor &&
lightScaffoldBackgroundColor == other.lightScaffoldBackgroundColor &&
darkScaffoldBackgroundColor == other.darkScaffoldBackgroundColor &&
fontFamily == other.fontFamily;

@override
int get hashCode =>
id.hashCode ^
canDelete.hashCode ^
autoMode.hashCode ^
isDark.hashCode ^
primaryColor.hashCode ^
accentColor.hashCode ^
lightBackgroundColor.hashCode ^
darkBackgroundColor.hashCode ^
lightScaffoldBackgroundColor.hashCode ^
darkScaffoldBackgroundColor.hashCode ^
fontFamily.hashCode;
}
2 changes: 1 addition & 1 deletion lib/model/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:mikan_flutter/internal/hive.dart';

part 'user.g.dart';

@HiveType(typeId: MyHive.MIAKN_USER)
@HiveType(typeId: MyHive.MIKAN_USER)
class User extends HiveObject {
@HiveField(0)
String? name;
Expand Down
2 changes: 1 addition & 1 deletion lib/model/year_season.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:mikan_flutter/model/season.dart';

part 'year_season.g.dart';

@HiveType(typeId: MyHive.MIAKN_YEARSEASON)
@HiveType(typeId: MyHive.MIKAN_YEAR_SEASON)
class YearSeason extends HiveObject {
@HiveField(0)
late String year;
Expand Down
5 changes: 2 additions & 3 deletions lib/ui/components/normal_record_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class NormalRecordItem extends StatelessWidget {
borderRadius: borderRadius16,
),
margin: edgeB16,
height: 164.0,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
Expand All @@ -68,11 +67,11 @@ class NormalRecordItem extends StatelessWidget {
record.title,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: textStyle14B500,
style: textStyle15B500,
),
),
),
spacer,
sizedBoxH4,
Container(
margin: edgeH16T4,
width: double.infinity,
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/components/ova_record_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class OVARecordItem extends StatelessWidget {
theme.primaryColor.computeLuminance() < 0.5 ? Colors.white : Colors.black,
);
return TapScaleContainer(
width: 375.0,
width: 340.0,
onTap: onTap,
margin: edgeR16,
decoration: BoxDecoration(
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/fragments/bangumi_sliver_grid_fragment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class BangumiSliverGridFragment extends StatelessWidget {
crossAxisSpacing: 12.0,
mainAxisSpacing: 12.0,
maxCrossAxisExtent: 156.0,
childAspectRatio: 0.6,
childAspectRatio: 0.56,
),
delegate: SliverChildBuilderDelegate(
(context, index) {
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/fragments/index_fragment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ class _IndexFragmentState extends State<IndexFragment> {
if (records.isNullOrEmpty) return emptySliverToBoxAdapter;
return SliverToBoxAdapter(
child: Container(
height: 146.0,
height: 154.0,
padding: const EdgeInsets.only(bottom: 12.0, top: 12.0),
child: ListView.builder(
physics: const BouncingScrollPhysics(),
Expand Down
8 changes: 4 additions & 4 deletions lib/ui/fragments/theme_panel_fragment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ class ThemePanelFragment extends StatelessWidget {
if (themeItem.id == 1) return "默认主题不可修改".toast();
this._showEditThemePanel(context, themeItem: themeItem);
},
margin: EdgeInsets.all(8.0),
padding: EdgeInsets.all(2.0),
margin: edge8,
padding: edge2,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24.0),
borderRadius: borderRadius24,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
Expand Down Expand Up @@ -115,7 +115,7 @@ class ThemePanelFragment extends StatelessWidget {
margin: edge8,
padding: EdgeInsets.zero,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24.0),
borderRadius: borderRadius24,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/pages/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class LoginPage extends StatelessWidget {
shape: circleShape,
color: theme.backgroundColor,
),
sizedBoxW12,
sizedBoxW16,
Expanded(child: _buildLoginButton(theme)),
],
),
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/pages/record_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class RecordDetailPage extends StatelessWidget {
style: TextStyle(
color: theme.accentColor,
fontWeight: FontWeight.bold,
fontSize: 24.0,
fontSize: 20.0,
),
),
if (recordDetail.name.isNotBlank) sizedBoxH8,
Expand Down Expand Up @@ -352,7 +352,7 @@ class RecordDetailPage extends StatelessWidget {
theme.primaryColor,
],
),
borderRadius: BorderRadius.circular(24.0),
borderRadius: borderRadius24,
),
child: Icon(
FluentIcons.clipboard_link_24_regular,
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/pages/register_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class RegisterPage extends StatelessWidget {
shape: circleShape,
color: theme.backgroundColor,
),
sizedBoxW12,
sizedBoxW16,
Expanded(
child: _buildRegisterButton(theme),
)
Expand Down
2 changes: 1 addition & 1 deletion lib/widget/tap_scale_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class _TapScaleContainerState extends State<TapScaleContainer> {
_tapStart() {
_clickTime = DateTime.now();
setState(() {
_transform = Matrix4.diagonal3Values(0.9, 0.9, 1);
_transform = Matrix4.diagonal3Values(0.92, 0.92, 1);
});
}
}

0 comments on commit f1f457d

Please sign in to comment.