Skip to content

Commit

Permalink
feat: use hive db cache data
Browse files Browse the repository at this point in the history
  • Loading branch information
sukinosuki committed Sep 3, 2024
1 parent 993a4e7 commit ad0dff3
Show file tree
Hide file tree
Showing 91 changed files with 3,255 additions and 2,116 deletions.
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ linter:
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
public_member_api_docs: false
lines_longer_than_80_chars: false
avoid_function_literals_in_foreach_calls: false

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
Binary file modified assets/images/card_placeholder.webp
Binary file not shown.
110 changes: 110 additions & 0 deletions assets/json/open_source_licenses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
[
{
"name": "cached_network_image",
"repos": "https://github.com/Baseflow/flutter_cached_network_image",
"license_path": "https://github.com/google/json_serializable.dart/blob/master/LICENSE",
"version": "^3.2.3"
},
{
"name": "webview_flutter",
"repos": "https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter",
"license_path": "https://github.com/flutter/packages/blob/main/packages/webview_flutter/webview_flutter/LICENSE",
"version": "^4.7.0"
},
{
"name": "get",
"repos": "https://github.com/jonataslaw/getx",
"license_path": "https://github.com/jonataslaw/getx/blob/master/LICENSE",
"version": "^4.6.5"
},
{
"name": "json_annotation",
"repos": "https://github.com/google/json_serializable.dart/tree/master/json_annotation",
"license_path": "https://github.com/google/json_serializable.dart/blob/master/json_annotation/LICENSE",
"version": "^4.8.1"
},
{
"name": "intl",
"repos": "https://github.com/dart-lang/i18n/tree/main/pkgs/intl",
"license_path": "https://github.com/dart-lang/i18n/blob/main/pkgs/intl/LICENSE",
"version": "^0.19.0"
},
{
"name": "flutter_svg",
"repos": "https://github.com/dnfield/flutter_svg",
"license_path": "https://github.com/dnfield/flutter_svg/blob/master/LICENSE",
"version": "^2.0.10+1"
},
{
"name": "path",
"repos": "https://github.com/dart-lang/path",
"license_path": "https://github.com/dart-lang/path/blob/master/LICENSE",
"version": "^1.9.0"
},
{
"name": "hive",
"repos": "https://github.com/isar/hive",
"license_path": "https://github.com/isar/hive/blob/main/LICENSE",
"version": "^2.2.3"
},
{
"name": "hive_flutter",
"repos": "https://github.com/isar/hive",
"license_path": "https://github.com/isar/hive/blob/main/LICENSE",
"version": "^1.1.0"
},
{
"name": "flutter_smart_dialog",
"repos": "https://github.com/fluttercandies/flutter_smart_dialog",
"license_path": "https://github.com/fluttercandies/flutter_smart_dialog/blob/master/LICENSE",
"version": "^4.9.6+1"
},
{
"name": "animations",
"repos": "https://github.com/flutter/packages/tree/main/packages/animations",
"license_path": "https://github.com/flutter/packages/blob/main/packages/animations/LICENSE",
"version": "^2.0.11"
},
{
"name": "build_runner",
"repos": "https://github.com/dart-lang/build/tree/master/build_runner",
"license_path": "https://github.com/dart-lang/build/blob/master/build_runner/LICENSE",
"version": "^2.4.6"
},
{
"name": "json_serializable",
"repos": "https://github.com/google/json_serializable.dart",
"license_path": "https://github.com/google/json_serializable.dart/blob/master/LICENSE",
"version": "^6.7.1"
},
{
"name": "flutter_lints",
"repos": "https://github.com/flutter/packages/tree/main/packages/flutter_lints",
"license_path": "https://github.com/flutter/packages/blob/main/packages/flutter_lints/LICENSE",
"version": "^3.0.2"
},
{
"name": "flutter_gen_runner",
"repos": "https://github.com/FlutterGen/flutter_gen",
"license_path": "https://github.com/FlutterGen/flutter_gen/blob/main/LICENSE",
"version": "^5.3.1"
},
{
"name": "icons_launcher",
"repos": "https://github.com/mrrhak/icons_launcher",
"license_path": "https://github.com/mrrhak/icons_launcher/blob/master/LICENSE",
"version": "^2.1.7"
},
{
"name": "very_good_analysis",
"repos": "https://github.com/VeryGoodOpenSource/very_good_analysis",
"license_path": "https://github.com/VeryGoodOpenSource/very_good_analysis/blob/main/LICENSE",
"version": "^5.1.0"
},
{
"name": "hive_generator",
"repos": "https://github.com/isar/hive",
"license_path": "https://github.com/isar/hive/blob/main/LICENSE",
"version": "^2.0.1"
}
]
17 changes: 9 additions & 8 deletions lib/components/MdCardItemView.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';

class MdCardItemView extends StatefulWidget {
const MdCardItemView({super.key, required this.mdCard, this.bottomWidget, this.showBanStatus = true, this.trend, this.onTap});
const MdCardItemView({required this.mdCard, super.key, this.bottomWidget, this.showBanStatus = true, this.trend, this.onTap});

final MdCard mdCard;
final Widget? bottomWidget;
Expand Down Expand Up @@ -51,14 +51,15 @@ class _MdCardItemViewState extends State<MdCardItemView> {
),
if (widget.showBanStatus && mdCard.banStatus != null)
Positioned(
child: ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(10)),
child: SvgPicture.asset(
'assets/images/icon_${mdCard.banStatus!.toLowerCase()}.svg',
width: 20,
height: 20,
child: ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(10)),
child: SvgPicture.asset(
'assets/images/icon_${mdCard.banStatus!.toLowerCase()}.svg',
width: 20,
height: 20,
),
),
)),
),
if (widget.trend != null && widget.trend != '')
Positioned(
top: 0,
Expand Down
29 changes: 18 additions & 11 deletions lib/components/MdCardItemView2.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import 'dart:developer';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:duel_links_meta/extension/Future.dart';
import 'package:duel_links_meta/gen/assets.gen.dart';
import 'package:duel_links_meta/hive/MyHive.dart';
import 'package:duel_links_meta/hive/db/CardHiveDb.dart';
import 'package:duel_links_meta/http/CardApi.dart';
import 'package:duel_links_meta/store/BanCardStore.dart';
import 'package:duel_links_meta/type/MdCard.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';

class MdCardItemView2 extends StatefulWidget {
const MdCardItemView2({super.key, this.mdCard, required this.id, this.bottomWidget, this.showBanStatus = true, this.trend, this.onTap});
Expand All @@ -30,18 +31,22 @@ class _MdCardItemViewState extends State<MdCardItemView2> {

MdCard? _mdCard;

BanCardStore banCardStore = Get.put(BanCardStore());

String? get banStatus => banCardStore.idToCardMap[cardId]?.banStatus;

//
Future<void> init() async {
if (widget.mdCard != null && widget.mdCard?.type != '') return;

var card = await MyHive.box2.get('card:$cardId') as MdCard?;
var card = await CardHiveDb.get(cardId);

if (card == null) {
final (err, res) = await CardApi().getById(cardId).toCatch;
if (err != null || res!.isEmpty) return;
if (err != null || res == null) return;

card = res[0];
MyHive.box2.put('card:$cardId', card);
card = res;
await CardHiveDb.setCard(card);
}

setState(() {
Expand All @@ -67,38 +72,40 @@ class _MdCardItemViewState extends State<MdCardItemView2> {
SizedBox(
height: 8,
child: (mdCard != null && mdCard?.rarity != '')
? Image.asset('assets/images/rarity_${mdCard?.rarity.toLowerCase()}.webp')
? Image.asset('assets/images/rarity_${mdCard!.rarity.toLowerCase()}.webp')
: null,
),
],
),
Stack(
children: [
CachedNetworkImage(
// placeholder: (context, url) => Image.asset('assets/images/card_placeholder.webp'),
placeholder: (context, url) => Assets.images.cardPlaceholder.image(),
errorWidget: (context, url, err) => Assets.images.cardPlaceholder.image(),
fadeInDuration: const Duration(milliseconds: 0),
fadeInDuration: Duration.zero,
fadeOutDuration: null,
imageUrl: 'https://s3.duellinksmeta.com/cards/${cardId}_w100.webp'),

if (widget.bottomWidget != null)
Positioned(
bottom: 0,
left: 0,
right: 0,
child: widget.bottomWidget!,
),
if (widget.showBanStatus && mdCard?.banStatus != null)

if (banStatus != null)
Positioned(
child: ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(10)),
child: SvgPicture.asset(
'assets/images/icon_${mdCard?.banStatus?.toLowerCase()}.svg',
'assets/images/icon_${banStatus!.toLowerCase()}.svg',
width: 20,
height: 20,
),
),
),

if (widget.trend != null && widget.trend != '')
Positioned(
top: 0,
Expand Down
Loading

0 comments on commit ad0dff3

Please sign in to comment.