Flutter Scratch Card

 pubspec

nameextravote
descriptionA new Flutter project.
publish_to'none' 


version1.0.0+1


environment:
  sdk">=2.7.0 <3.0.0"


dependencies:
  flutter:
    sdkflutter
  http^0.12.2
  cached_network_image^2.5.0
  webview_flutter^1.0.7 
  
  cupertino_icons^1.0.2
   
  workmanager^0.2.3
  
  flutter_local_notifications^1.4.4+2
  scratcher"^1.4.0"
  
  confetti^0.5.4+1


dev_dependencies:
  flutter_test:
    sdkflutter
  integration_test:
    sdkflutter
flutter:

  uses-material-designtrue


  assets:
    - lib/assets/images/  
module:
  androidXtrue



****************************************************************
main.dart

import 'package:flutter/material.dart';
import 'scratch.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MyHomePage(),
    );
  }
}


****************************************************************

scratch.dart


import 'package:confetti/confetti.dart';
import 'package:flutter/material.dart';
import 'package:scratcher/widgets.dart';

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  ConfettiController _controller;
  int coin = 10;

  @override
  void initState() {
    super.initState();
    _controller = new ConfettiController(
      duration: new Duration(seconds: 1),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.blueGrey,
      body: Center(
        child: Scratcher(
          brushSize: 50,
          threshold: 60,
          color: Colors.red,
          image: Image.asset(
            "lib/assets/images/outerimage.png",
            fit: BoxFit.fill,
          ),
          onChange: (value) => print("Scratch progress: $value%"),
          onThreshold: () => _controller.play(),
          child: Container(
            height: 300,
            width: 300,
            color: Colors.white,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Image.asset(
                  "lib/assets/images/newimage.png",
                  fit: BoxFit.contain,
                  width: 150,
                  height: 150,
                ),
                Column(
                  children: [
                    ConfettiWidget(
                      blastDirectionality: BlastDirectionality.explosive,
                      confettiController: _controller,
                      particleDrag: 0.05,
                      emissionFrequency: coin * 0.05,
                      numberOfParticles: coin * 10,
                      gravity: 0.05,
                      shouldLoop: false,
                      colors: [
                        Colors.green,
                        Colors.red,
                        Colors.yellow,
                        Colors.blue,
                      ],
                    ),
                    Text(
                      "You won",
                      style: TextStyle(
                        fontWeight: FontWeight.w400,
                        fontSize: 25,
                      ),
                    ),
                    Text(
                      "${coin} Coins!",
                      style: TextStyle(
                        fontWeight: FontWeight.w400,
                        fontSize: 25,
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

*******************************************************
newimage.png
and outerimage.png
folder path: lib/assets/images







Problems may arise due to image loading in pubspec


Comments