|
@@ -10,6 +10,7 @@ import 'package:sport/pages/login/license.dart';
|
|
import 'package:sport/provider/user_model.dart';
|
|
import 'package:sport/provider/user_model.dart';
|
|
import 'package:sport/services/api/inject_api.dart';
|
|
import 'package:sport/services/api/inject_api.dart';
|
|
import 'package:sport/widgets/button_primary.dart';
|
|
import 'package:sport/widgets/button_primary.dart';
|
|
|
|
+import 'package:sport/widgets/dialog/request_dialog.dart';
|
|
|
|
|
|
class Input extends StatefulWidget {
|
|
class Input extends StatefulWidget {
|
|
String labelText;
|
|
String labelText;
|
|
@@ -62,28 +63,41 @@ class _InputState extends State<Input> {
|
|
if (widget.textInputType == TextInputType.phone) WhitelistingTextInputFormatter(RegExp("[0-9*#]")),
|
|
if (widget.textInputType == TextInputType.phone) WhitelistingTextInputFormatter(RegExp("[0-9*#]")),
|
|
],
|
|
],
|
|
decoration: InputDecoration(
|
|
decoration: InputDecoration(
|
|
- counterText: "",
|
|
|
|
- contentPadding: EdgeInsets.symmetric(vertical: widget.height >= 40 ? 14.0: 9.0, horizontal: 16.0),
|
|
|
|
- border: OutlineInputBorder(
|
|
|
|
- borderSide: BorderSide(color: Color.fromRGBO(206, 206, 206, 1),width: 0.5),
|
|
|
|
- borderRadius: BorderRadius.all(Radius.circular(44.0)),
|
|
|
|
- ),
|
|
|
|
- focusedBorder: OutlineInputBorder(
|
|
|
|
- borderSide: BorderSide(color: Theme.of(context).accentColor,width:1.0),
|
|
|
|
- borderRadius: BorderRadius.all(Radius.circular(44.0)),
|
|
|
|
- ),
|
|
|
|
- enabledBorder: OutlineInputBorder(
|
|
|
|
- borderSide: BorderSide(color: Color.fromRGBO(206, 206, 206, 1),width: 0.5),
|
|
|
|
- borderRadius: BorderRadius.all(Radius.circular(44.0)),
|
|
|
|
- ),
|
|
|
|
- labelText: widget.labelText,
|
|
|
|
- labelStyle: TextStyle(fontSize: 14.0, color: Color(0xffc2c2c2)),
|
|
|
|
- floatingLabelBehavior: FloatingLabelBehavior.never,
|
|
|
|
- prefixIcon: widget.textInputType == TextInputType.phone ?Row(children: <Widget>[Padding(
|
|
|
|
- padding: const EdgeInsets.only(left: 12.0, right: 4.0),
|
|
|
|
- child: Text("+86", style: Theme.of(context).textTheme.subtitle1,),
|
|
|
|
- ), VerticalDivider(indent: 8.0, endIndent: 8.0,)],mainAxisSize: MainAxisSize.min,):null
|
|
|
|
- ),
|
|
|
|
|
|
+ counterText: "",
|
|
|
|
+ contentPadding: EdgeInsets.symmetric(vertical: widget.height >= 40 ? 14.0 : 9.0, horizontal: 16.0),
|
|
|
|
+ border: OutlineInputBorder(
|
|
|
|
+ borderSide: BorderSide(color: Color.fromRGBO(206, 206, 206, 1), width: 0.5),
|
|
|
|
+ borderRadius: BorderRadius.all(Radius.circular(44.0)),
|
|
|
|
+ ),
|
|
|
|
+ focusedBorder: OutlineInputBorder(
|
|
|
|
+ borderSide: BorderSide(color: Theme.of(context).accentColor, width: 1.0),
|
|
|
|
+ borderRadius: BorderRadius.all(Radius.circular(44.0)),
|
|
|
|
+ ),
|
|
|
|
+ enabledBorder: OutlineInputBorder(
|
|
|
|
+ borderSide: BorderSide(color: Color.fromRGBO(206, 206, 206, 1), width: 0.5),
|
|
|
|
+ borderRadius: BorderRadius.all(Radius.circular(44.0)),
|
|
|
|
+ ),
|
|
|
|
+ labelText: widget.labelText,
|
|
|
|
+ labelStyle: TextStyle(fontSize: 14.0, color: Color(0xffc2c2c2)),
|
|
|
|
+ floatingLabelBehavior: FloatingLabelBehavior.never,
|
|
|
|
+ prefixIcon: widget.textInputType == TextInputType.phone
|
|
|
|
+ ? Row(
|
|
|
|
+ children: <Widget>[
|
|
|
|
+ Padding(
|
|
|
|
+ padding: const EdgeInsets.only(left: 12.0, right: 4.0),
|
|
|
|
+ child: Text(
|
|
|
|
+ "+86",
|
|
|
|
+ style: Theme.of(context).textTheme.subtitle1,
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ VerticalDivider(
|
|
|
|
+ indent: 8.0,
|
|
|
|
+ endIndent: 8.0,
|
|
|
|
+ )
|
|
|
|
+ ],
|
|
|
|
+ mainAxisSize: MainAxisSize.min,
|
|
|
|
+ )
|
|
|
|
+ : null),
|
|
onChanged: widget.callBack));
|
|
onChanged: widget.callBack));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -137,7 +151,7 @@ class _BuildCroppingImagePageState extends State<BuildCroppingImagePage> with In
|
|
@override
|
|
@override
|
|
void initState() {
|
|
void initState() {
|
|
super.initState();
|
|
super.initState();
|
|
- _openImage();
|
|
|
|
|
|
+ _openImage().then((value) => setState(() {}));
|
|
}
|
|
}
|
|
|
|
|
|
@override
|
|
@override
|
|
@@ -148,12 +162,12 @@ class _BuildCroppingImagePageState extends State<BuildCroppingImagePage> with In
|
|
_lastCropped?.delete();
|
|
_lastCropped?.delete();
|
|
}
|
|
}
|
|
|
|
|
|
- Future<void> _cropImage() async {
|
|
|
|
|
|
+ Future<String> _cropImage() async {
|
|
final scale = cropKey.currentState.scale;
|
|
final scale = cropKey.currentState.scale;
|
|
final area = cropKey.currentState.area;
|
|
final area = cropKey.currentState.area;
|
|
if (area == null) {
|
|
if (area == null) {
|
|
// cannot crop, widget is not setup
|
|
// cannot crop, widget is not setup
|
|
- return;
|
|
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
// scale up to use maximum possible number of pixels
|
|
// scale up to use maximum possible number of pixels
|
|
@@ -173,21 +187,14 @@ class _BuildCroppingImagePageState extends State<BuildCroppingImagePage> with In
|
|
|
|
|
|
_lastCropped?.delete();
|
|
_lastCropped?.delete();
|
|
_lastCropped = file;
|
|
_lastCropped = file;
|
|
- setState(() {
|
|
|
|
- _sample = null;
|
|
|
|
- });
|
|
|
|
|
|
+
|
|
print(_file);
|
|
print(_file);
|
|
- fetchUploadProductBanner(_file);
|
|
|
|
- Navigator.pop(context, _lastCropped);
|
|
|
|
|
|
+ return await fetchUploadProductBanner(_file);
|
|
}
|
|
}
|
|
|
|
|
|
- void fetchUploadProductBanner(File path) async {
|
|
|
|
- SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
-
|
|
|
|
|
|
+ Future<String> fetchUploadProductBanner(File path) async {
|
|
var resp = await loginApi.setAvatar(path);
|
|
var resp = await loginApi.setAvatar(path);
|
|
- String uploadUrl = resp.data;
|
|
|
|
- Provider.of<UserModel>(context, listen: false).saveUserInfoAvator(uploadUrl);
|
|
|
|
- prefs.setString('avatar', uploadUrl);
|
|
|
|
|
|
+ return resp.data;
|
|
}
|
|
}
|
|
|
|
|
|
Future<void> _openImage() async {
|
|
Future<void> _openImage() async {
|
|
@@ -204,10 +211,8 @@ class _BuildCroppingImagePageState extends State<BuildCroppingImagePage> with In
|
|
_sample?.delete();
|
|
_sample?.delete();
|
|
_file?.delete();
|
|
_file?.delete();
|
|
|
|
|
|
- setState(() {
|
|
|
|
- _sample = sample;
|
|
|
|
- _file = file;
|
|
|
|
- });
|
|
|
|
|
|
+ _sample = sample;
|
|
|
|
+ _file = file;
|
|
}
|
|
}
|
|
|
|
|
|
@override
|
|
@override
|
|
@@ -227,12 +232,21 @@ class _BuildCroppingImagePageState extends State<BuildCroppingImagePage> with In
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: <Widget>[
|
|
children: <Widget>[
|
|
FlatButton(
|
|
FlatButton(
|
|
- child: Text(
|
|
|
|
- '确定',
|
|
|
|
- style: Theme.of(context).textTheme.button.copyWith(color: Colors.white),
|
|
|
|
- ),
|
|
|
|
- onPressed: () => _cropImage(),
|
|
|
|
- ),
|
|
|
|
|
|
+ child: Text(
|
|
|
|
+ '确定',
|
|
|
|
+ style: Theme.of(context).textTheme.button.copyWith(color: Colors.white),
|
|
|
|
+ ),
|
|
|
|
+ onPressed: () async {
|
|
|
|
+ await request(context, () async {
|
|
|
|
+ var url = await _cropImage();
|
|
|
|
+ if (url?.isNotEmpty == true) {
|
|
|
|
+ SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
+ prefs.setString('avatar', url);
|
|
|
|
+ Provider.of<UserModel>(context, listen: false).saveUserInfoAvator(url);
|
|
|
|
+ Navigator.pop(context, _file);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
)
|
|
)
|