Skip to content

Commit

Permalink
添加刮刮卡效果
Browse files Browse the repository at this point in the history
  • Loading branch information
simplezhli committed Mar 1, 2021
1 parent 972095b commit 6290fca
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/demo/demo_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_deer/demo/focus/focus_demo_page.dart';
import 'package:flutter_deer/demo/navigator/books_main.dart';
import 'package:flutter_deer/demo/overlay/overlay_main.dart';
import 'package:flutter_deer/demo/ripple/home_page.dart';
import 'package:flutter_deer/demo/scratcher/scratch_card_demo_page.dart';
import 'package:flutter_deer/res/resources.dart';
import 'package:flutter_deer/util/app_navigator.dart';
import 'package:flutter_deer/widgets/click_item.dart';
Expand Down Expand Up @@ -40,6 +41,10 @@ class _DemoPageState extends State<DemoPage> {
title: 'Navigator 2.0',
onTap: () => AppNavigator.push(context, NestedRouterDemo()),
),
ClickItem(
title: 'ScratchCard',
onTap: () => AppNavigator.push(context, ScratchCardDemoPage()),
),
],
),
);
Expand Down
75 changes: 75 additions & 0 deletions lib/demo/scratcher/scratch_card_demo_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

import 'package:flutter/material.dart';
import 'package:flutter_deer/res/colors.dart';
import 'package:flutter_deer/res/gaps.dart';
import 'package:flutter_deer/util/theme_utils.dart';
import 'package:flutter_deer/widgets/load_image.dart';
import 'package:scratcher/scratcher.dart';

class ScratchCardDemoPage extends StatefulWidget {
@override
_ScratchCardDemoPageState createState() => _ScratchCardDemoPageState();
}

class _ScratchCardDemoPageState extends State<ScratchCardDemoPage> {

final GlobalKey<ScratcherState> scratchKey = GlobalKey<ScratcherState>();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: context.isDark ? Colours.dark_bg_color : Colors.blue,
title: const Text('ScratchCard Demo'),
),
body: Column(
children: <Widget>[
Gaps.vGap16,
Scratcher(
key: scratchKey,
brushSize: 20,
threshold: 50,
color: Colors.grey,
onChange: (value) => print('Scratch progress: ${value.toStringAsFixed(2)}%'),
onThreshold: () {
/// 这里设置刮开50%,就揭开所有。
print('Threshold reached!');
scratchKey.currentState.reveal(
duration: const Duration(milliseconds: 1000),
);
},
child: Container(
padding: const EdgeInsets.symmetric(vertical: 20),
color: Colors.white,
height: 200,
width: 300,
child: const LoadAssetImage('logo',),
),
),
Gaps.vGap50,
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
OutlinedButton(
child: const Text('Reset'),
onPressed: () {
scratchKey.currentState.reset(
duration: const Duration(milliseconds: 2000),
);
},
),
ElevatedButton(
child: const Text('Reveal'),
onPressed: () {
scratchKey.currentState.reveal(
duration: const Duration(milliseconds: 2000),
);
},
),
],
),
],
),
);
}
}
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ dependencies:
barcode_scan: 3.0.1
# App Shortcuts https://github.com/flutter/plugins/tree/master/packages/quick_actions
quick_actions: 0.4.0+10
# 刮刮卡 https://github.com/vintage/scratcher
scratcher: ^1.4.1
# 高德2D地图插件 https://github.com/simplezhli/flutter_2d_amap
flutter_2d_amap:
git:
Expand Down

0 comments on commit 6290fca

Please sign in to comment.