颤振映射和开关盒

时间:2020-03-27 09:38:01

标签: flutter flutter-animation flutter-navigation

我刚开始使用Flutter,我想执行一个旋转轮,在其中单击旋转按钮后,我想根据角度打开不同的页面。我用过Map<int,String>

我将在下面添加代码。映射提供值,但它在同一页面上导航。每次单击旋转按钮并使车轮旋转时,我都希望使用不同的路线。

import 'dart:async';

import 'dart:math';

import 'package:audioplayers/audio_cache.dart';
import 'package:audioplayers/audioplayers.dart';
import 'package:bedroom_game_flutter/playscreen.dart';
import 'package:bedroom_game_flutter/shake.dart';
import 'package:bedroom_game_flutter/slide1.dart';


//import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_spinning_wheel/flutter_spinning_wheel.dart';



import 'final.dart';

bool _isEnabled = true;

class Roulette extends StatefulWidget {
  final int selected;

   final Map<int,String> labels = {
     1:"A",
     2:"B",
     3:"C",
     4:"D"


  };

  Roulette(this.selected);

  @override
  _RouletteState createState() => new _RouletteState(this.selected);
}

class _RouletteState extends State<Roulette> {
  final int selected;

    final Map<int,String> labels = {
     1:"A",
     2:"B",
     3:"C",
     4:"D"


  };


  _RouletteState(this.selected);

  AudioCache _audioCache;
  RaisedButton raisedButton;

  final StreamController _dividerController = StreamController<int>();
  final _wheelNotifier = StreamController<double>();

  //bool _isEnabled = true;

  @override
  void initState() {
    super.initState();

    _audioCache = AudioCache(
        prefix: "sound/",
        fixedPlayer: AudioPlayer()..setReleaseMode(ReleaseMode.STOP));
  }

  void _handleclick() {
    _audioCache.play('spinning_wheel.mp3');
    _wheelNotifier.sink.add(
      _generateRandomVelocity(),

    );

    if (_isEnabled = true) {
      setState(() {
        _isEnabled = false;
      });
    }
  }

  void _hasclick() {
    setState(() {
      Navigator.push(context,
          MaterialPageRoute(builder: (context) => Final(this.selected)));
    });

    if (_isEnabled = false) {}
  }

  dispose() {
    _dividerController.close();
    _wheelNotifier.close();
  }

  @override
  Widget build(BuildContext context) {
    SystemChrome.setEnabledSystemUIOverlays([]);
    var _mybtn;
    return Scaffold(
      resizeToAvoidBottomPadding: false,
        // appBar: AppBar(backgroundColor: Color(0xffDDC3FF), elevation: 0.0),
        // backgroundColor: Color(0xffDDC3FF),
        body: Stack(children: <Widget>[
      Container(
        decoration: BoxDecoration(
            image: DecorationImage(
                image: AssetImage("assets/chance_bg.png"),
                fit: BoxFit.fill)),
        child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
          SpinningWheel(
            Image.asset('assets/spinthewheel_star2.png'),
            width: 310,
            height: 310,
            initialSpinAngle: _generateRandomAngle(),
            spinResistance: 0.6,
            canInteractWhileSpinning: false,
            dividers: 4,
            onUpdate: _dividerController.add,
            onEnd: _dividerController.add,
            secondaryImage:
                Image.asset('assets/arrow.png'),
            secondaryImageHeight: 90,
            secondaryImageWidth: 110,
            shouldStartOrStop: _wheelNotifier.stream,
          ),
          SizedBox(height: 30),
          StreamBuilder(
            stream: _dividerController.stream,
            builder: (context, snapshot) =>
                snapshot.hasData ? RouletteScore(snapshot.data) : Container(),
          ),
          SizedBox(height: 100.0),
          ButtonTheme(
              minWidth: 500.0,
              height: 48.0,
              child: MaterialButton(
                  color: Color(0xffff5757),
                  textColor: Colors.white,
                  key: _mybtn,
                  child: new Text(
                    "Spin",
                    style: TextStyle(fontSize: 35.0),
                  ),
                  onPressed: _isEnabled ? _handleclick : null)),
          // SizedBox(height: 50.0),
          // ButtonTheme(
          //     minWidth: 500.0,
          //     height: 48.0,
          //     child: MaterialButton(
          //         color: Color(0xfff14d66),
          //         textColor: Colors.white,
          //         key: _mybtn,
          //         child: new Text(
          //           "View My Task",
          //           style: TextStyle(fontSize: 35.0),
          //         ),
          //         onPressed: ()=>

          //         //_isEnabled ? null : _hasclick,
          //           Navigator.push(context, MaterialPageRoute(builder: (context)=>Final(this.selected))

          //        // },
        ]),
      )
    ]));
  }

  double _generateRandomVelocity() => (Random().nextDouble() * 9000) + 10000;

  double _generateRandomAngle() => Random().nextDouble() * pi * 2;
}

class RouletteScore extends StatefulWidget {
   int selected;

    Map<int,String> labels = {
     1:"A",
     2:"B",
     3:"C",
     4:"D"


  };


  RouletteScore(this.selected);

  @override
  _RouletteScoreState createState() => new _RouletteScoreState(this.selected);
}

class _RouletteScoreState extends State<RouletteScore> {
  final int selected;

  final Map<int,String> labels = {
     1:"A",
     2:"B",
     3:"C",
     4:"D"


  };


  _RouletteScoreState(this.selected);
  void _hasclick() {


    if (_isEnabled = false) {}

  }

  @override
  Widget build(BuildContext context) {
    return ButtonTheme(
              minWidth: 500.0,
              height: 48.0,
              child: MaterialButton(
                color: Color(0xffff5757),
                  child: Text("View My Voucher",
                  style: TextStyle(fontFamily: "font",
                  fontSize: 32.0),),


        onPressed: (){
          //want the different pages to open on this button



        }));
}
}

0 个答案:

没有答案