| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- import 'package:flutter/material.dart';
- import '../styles/colors.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'dart:ui';
- class Rechrage extends StatefulWidget {
- @override
- RechrageState createState() => RechrageState();
- }
- class RechrageState extends State<Rechrage> {
- List<Map> moenyList = [
- {
- 'title': '10金币',
- 'money': 10,
- },
- {
- 'title': '50金币',
- 'money': 50,
- },
- {
- 'title': '100金币',
- 'money': 100,
- },
- {
- 'title': '300金币',
- 'money': 300,
- },
- {
- 'title': '500金币',
- 'money': 500,
- }
- ];
- bool isInput = false;
- int choosemoeny = 0;
- bool autoChoose = false;
- FocusNode _focusNode = FocusNode();
- @override
- void initState() {
- super.initState();
- _focusNode.addListener(_focusNodeListener);
- }
- Future<Null> _focusNodeListener() async {
- if (_focusNode.hasFocus) {
- setState(() {
- if (!autoChoose) {
- autoChoose = true;
- choosemoeny = 0;
- }
- isInput = true;
- });
- } else {
- setState(() {
- isInput = false;
- });
- }
- }
- @override
- Widget build(BuildContext context) {
- ScreenUtil.instance = ScreenUtil(width: 375, height: 667)..init(context);
- return Scaffold(
- appBar: AppBar(
- // backgroundColor: PRIMARY_COLOR,
- title: Text('充值'),
- centerTitle: true,
- elevation: 0,
- ),
- body: GestureDetector(
- ///透明也响应处理
- behavior: HitTestBehavior.translucent,
- onTap: () {
- ///触摸手气键盘
- FocusScope.of(context).requestFocus(FocusNode());
- },
- child: RefreshIndicator(
- color: PRIMARY_COLOR,
- backgroundColor: Colors.white,
- onRefresh: () async {
- await Future.delayed(const Duration(seconds: 1));
- },
- child: Container(
- color: BG_COLOR,
- child: Column(
- children: <Widget>[_useGride(context)],
- ),
- ),
- )));
- }
- Widget _useGride(BuildContext context) {
- return Container(
- padding: EdgeInsets.all(ScreenUtil().setWidth(15)),
- width: double.infinity,
- child: Wrap(
- alignment: WrapAlignment.spaceBetween,
- children: _allChooseBtn(context),
- ),
- );
- }
- List<Widget> _allChooseBtn(BuildContext context) {
- List<Widget> allWidget = List<Widget>.generate(moenyList.length, (int index) {
- return _chooseBtn(context, index);
- });
- Widget _input() {
- return Container(
- padding: EdgeInsets.only(left: 30, right: 5),
- color: autoChoose ? PRIMARY_COLOR : BG_SUB_COLOR,
- margin: EdgeInsets.only(bottom: ScreenUtil().setWidth(5)),
- width: ScreenUtil().setWidth(170),
- height: ScreenUtil().setWidth(60),
- child: TextField(
- focusNode: _focusNode,
- textAlign: TextAlign.center,
- keyboardType: TextInputType.number,
- style: TextStyle(
- fontSize: 16,
- fontWeight: FontWeight.w500,
- color: Colors.white,
- ),
- decoration: InputDecoration(
- hintText: isInput ? '请输入金额' : '其他金额',
- hintStyle: TextStyle(color: Colors.white, fontSize: 14, fontWeight: isInput ? FontWeight.w500 : FontWeight.w400),
- suffixText: '金币',
- suffixStyle: TextStyle(fontSize: 13, fontWeight: FontWeight.w400, color: Colors.white),
- border: OutlineInputBorder(borderSide: BorderSide.none),
- ),
- onChanged: (String str) {
- //输入监听
- choosemoeny = int.parse(str);
- }));
- }
- allWidget.add(_input());
- return allWidget;
- }
- Widget _chooseBtn(BuildContext context, int index) {
- bool isChoose = false;
- if (!autoChoose && moenyList[index]['money'] == choosemoeny) {
- isChoose = true;
- }
- return Container(
- margin: EdgeInsets.only(bottom: ScreenUtil().setWidth(5)),
- width: ScreenUtil().setWidth(170),
- height: ScreenUtil().setWidth(60),
- child: FlatButton(
- color: isChoose ? PRIMARY_COLOR : BG_SUB_COLOR,
- highlightColor: isChoose ? PRIMARY_COLOR.withOpacity(0.3) : BG_COLOR.withOpacity(0.3),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Text(moenyList[index]['title'], style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w500, height: 1)),
- Text('¥' + moenyList[index]['money'].toString(),
- style: TextStyle(color: isChoose ? Colors.white : Color(0xFF727785), fontSize: 13, fontWeight: FontWeight.w400, height: 18 / 13)),
- ],
- ),
- onPressed: () {
- setState(() {
- autoChoose = false;
- choosemoeny = moenyList[index]['money'];
- FocusScope.of(context).requestFocus(FocusNode());
- });
- },
- ),
- );
- }
- }
|