import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_ruler_picker/flutter_ruler_picker.dart'; import 'base/YSBase.dart'; import 'base/YSNetWorking.dart'; class YSAddBodyData extends StatefulWidget { final int index; const YSAddBodyData({Key key, this.index}) : super(key: key); @override _YSAddBodyDataState createState() => _YSAddBodyDataState(); } class _YSAddBodyDataState extends State { RulerPickerController _rulerPickerController = RulerPickerController(value: 0); String number = '0.0'; @override Widget build(BuildContext context) { return YSBase( ystitle: '体重选择', yschild: SingleChildScrollView( child: Column( children: [ Container( margin: EdgeInsets.all(20), child: Text('孕${widget.index}周',style: TextStyle(fontSize: 16,color: Color(0xFFDB5278),fontWeight: FontWeight.w600),), ), Container( margin: EdgeInsets.only(top: 30,bottom: 15), child: RulerPicker( controller: _rulerPickerController, marker: Container( height: 60, width: 3, color: Color(0xFFDB5278), ), onValueChanged: (value) { setState(() { number = value.toString(); }); }, width: MediaQuery.of(context).size.width-60, height: 100, ranges: [RulerRange(end: 200, begin: 0)], onBuildRulerScaleText: (int index, num rulerScaleValue) { return '$index'; }, // beginValue: 1, // endValue: 100, ), ), RichText( text: TextSpan( style: TextStyle(fontSize: 36,color: Color(0xFFDB5278),fontWeight: FontWeight.bold), children: [ TextSpan(text: number), TextSpan(text: ' kg',style: TextStyle(fontSize: 16,fontWeight: FontWeight.normal)), ] ), ), CupertinoButton( padding: EdgeInsets.all(0), child: Container( height: 40, width: MediaQuery.of(context).size.width-150, decoration: BoxDecoration( color: Color(0xFFDB5278), borderRadius: BorderRadius.all(Radius.circular(20)) ), alignment: Alignment.center, child: Text('保存',style: TextStyle(fontSize: 16,color: Colors.white),), margin: EdgeInsets.only(top: 150), ), onPressed: (){ _postWomanBodyData(); }, ) ], ), ), ); } _postWomanBodyData() async{ if(number=='0.0'){ ysFlutterToast(context, '请选择体重数据'); return; } Map dict = await ysRequestHttp(context, requestType.post, 'phase/dueWeightAdd', {'week':widget.index,'weight':number}); if(dict!=null){ Navigator.of(context).pop('确定'); } } }