Flutter--简易的原神角色培养计算器

267 阅读1分钟

原来你也玩原神?!!!

输入你的当前面板属性,计算结果得到攻击暴击爆伤的收益系数,选择系数大的去提升,这样一点点修正培养,你就可以越来越接近理论最大值。

注意:输入的暴击/爆伤比如是 50%, 计算时需要输入0.5。


import 'package:flutter/material.dart';


void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '收益计算器',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: AttributePage(),
    );
  }
}

class AttributePage extends StatefulWidget {
  AttributePage({Key key}) : super(key: key);

  @override
  _AttributePageState createState() => _AttributePageState();
}

class _AttributePageState extends State<AttributePage> {

  double get a => a2 / a1;

  double a1 = 0; 
  double a2 = 0;

  double b = 0; 
  double c = 0;

  double sa = 0;
  double sb = 0;
  double sc = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: ListView(children: [
          textFieldCell("基础攻击力", (value) => a1 = value),
          textFieldCell("总攻击力   ", (value) => a2 = value),
          textFieldCell("暴击率      ", (value) => b = value),
          textFieldCell("暴击伤害   ", (value) => c = value),
          SizedBox(height: 20,),
          Text("攻击力收益:$sa"),
          SizedBox(height: 10,),
          Text("暴击率收益:$sb"),
          SizedBox(height: 10,),
          Text("暴击伤害收益:$sc"),
          SizedBox(height: 50,),
          TextButton(
            onPressed: () {
              setState(() {
                sa = 3 * (1 + b * c);
                sb = 2 * a * c;
                sc = 4 * a * b;
              });
            },
            child: Text("计算")
          )
        ], padding: EdgeInsets.all(12),),
      ),
    );
  }

  Widget textFieldCell(String title, ValueChanged<double> onChanged) {
    return Row(children: [
      Text(title),
      SizedBox(width: 8,),
      textField(onChanged),
    ],);
  }

  Widget textField(ValueChanged<double> onChanged) {
    return Expanded(child: TextField(
      keyboardType: TextInputType.number,
      onChanged: (value) {
        double v = double.tryParse(value);
        if (v == null)
          return;

        onChanged(v);
      },
    ));
  }
}