当前位置:   article > 正文

flutter 让TextFeild可以根据输入法上移_flutter textfield背景上移

flutter textfield背景上移

1.需要保证TextFeild可以滑动,不然滑动不了

 

2.需要获取输入法高度,然后包裹TextFeild的布局高度需要减去输入法高度

  1. Scaffold(
  2. body: Stack(
  3. children: <Widget>[
  4. Column(
  5. children: <Widget>[
  6. Container(height: getTopBarHeight(), color: Colors.white),
  7. getTop('填写售后信息'),
  8. getLine(size: ScreenUtil.getInstance().getWidth(20), width: 0),
  9. Container(
  10. height: ScreenUtil.getInstance().screenHeight -
  11. ScreenUtil.getInstance().getWidth(100) -
  12. getTopBarHeight()-
  13. MediaQuery.of(context).viewInsets.bottom,//输入法 高度 此高度跟随输入法变化
  14. child: Scrollbar(
  15. //包裹让其可以滑动
  16. child: SingleChildScrollView(
  17. scrollDirection: Axis.vertical,
  18. reverse: true,
  19. padding: EdgeInsets.all(0.0),
  20. physics: BouncingScrollPhysics(),
  21. child: Column(
  22. children: <Widget>[
  23. Container(
  24. alignment: Alignment.centerLeft,
  25. margin: EdgeInsets.fromLTRB(
  26. ScreenUtil.getInstance().getWidth(20),
  27. 0,
  28. ScreenUtil.getInstance().getWidth(20),
  29. 0),
  30. height: ScreenUtil.getInstance().getWidth(90),
  31. width: double.infinity,
  32. child: Text(
  33. '售后原因:订单金额有误',
  34. style: TextStyle(
  35. color: MyColors.color_79,
  36. fontSize: ScreenUtil.getInstance().getWidth(30)),
  37. ),
  38. ),
  39. getLine(
  40. size: ScreenUtil.getInstance().getWidth(1),
  41. width: 0,
  42. color: '#E5E5E5'),
  43. Container(
  44. alignment: Alignment.centerLeft,
  45. margin: EdgeInsets.fromLTRB(
  46. ScreenUtil.getInstance().getWidth(20),
  47. 0,
  48. ScreenUtil.getInstance().getWidth(20),
  49. 0),
  50. height: ScreenUtil.getInstance().getWidth(80),
  51. width: double.infinity,
  52. child: Row(
  53. children: <Widget>[
  54. Text(
  55. '请选择您需要申请售后的商品',
  56. style: TextStyle(
  57. color: MyColors.color_home_top_text,
  58. fontSize:
  59. ScreenUtil.getInstance().getWidth(30)),
  60. ),
  61. getStart()
  62. ],
  63. ),
  64. ),
  65. Container(
  66. margin: EdgeInsets.only(
  67. left: ScreenUtil.getInstance().getWidth(10),
  68. right: ScreenUtil.getInstance().getWidth(10)),
  69. padding: EdgeInsets.fromLTRB(
  70. ScreenUtil.getInstance().getWidth(10),
  71. ScreenUtil.getInstance().getWidth(20),
  72. ScreenUtil.getInstance().getWidth(10),
  73. ScreenUtil.getInstance().getWidth(20)),
  74. color: MyColors.color_F9,
  75. child: Stack(
  76. alignment: Alignment.bottomRight,
  77. children: <Widget>[
  78. Row(
  79. children: <Widget>[
  80. Image.asset(
  81. Utils.getImgPath('bg_goods_default'),
  82. height:
  83. ScreenUtil.getInstance().getWidth(138),
  84. width: ScreenUtil.getInstance().getWidth(138),
  85. ),
  86. Container(
  87. width: ScreenUtil.getInstance().getWidth(430),
  88. height:
  89. ScreenUtil.getInstance().getWidth(138),
  90. margin: EdgeInsets.only(
  91. left:
  92. ScreenUtil.getInstance().getWidth(10),
  93. right: ScreenUtil.getInstance()
  94. .getWidth(10)),
  95. child: Column(
  96. crossAxisAlignment:
  97. CrossAxisAlignment.start,
  98. children: <Widget>[
  99. Container(
  100. height: ScreenUtil.getInstance()
  101. .getWidth(100),
  102. child: Text(
  103. '大师傅的世风不古发挥更加开阔更加开阔',
  104. style: TextStyle(
  105. fontSize: ScreenUtil.getInstance()
  106. .getSp(28),
  107. color:
  108. MyColors.color_home_top_text),
  109. maxLines: 2,
  110. ),
  111. ),
  112. Text('实际付款¥10.99',
  113. style: TextStyle(
  114. fontSize: ScreenUtil.getInstance()
  115. .getSp(28),
  116. color:
  117. MyColors.color_home_top_text))
  118. ],
  119. ),
  120. ),
  121. Container(
  122. alignment: Alignment.topRight,
  123. height:
  124. ScreenUtil.getInstance().getWidth(134),
  125. child: Column(
  126. crossAxisAlignment: CrossAxisAlignment.end,
  127. children: <Widget>[
  128. Text(
  129. S.of(context).null_rmb + '33.90',
  130. style: TextStyle(
  131. color: MyColors.color_home_top_text,
  132. fontSize: ScreenUtil.getInstance()
  133. .getSp(26)),
  134. ),
  135. Padding(
  136. padding: EdgeInsets.only(
  137. top: ScreenUtil.getInstance()
  138. .getWidth(10)),
  139. child: Text(
  140. 'x2',
  141. style: TextStyle(
  142. color: MyColors.color_79,
  143. fontSize: ScreenUtil.getInstance()
  144. .getSp(26)),
  145. ),
  146. )
  147. ],
  148. ),
  149. )
  150. ],
  151. ),
  152. Row(
  153. mainAxisAlignment: MainAxisAlignment.end,
  154. children: <Widget>[
  155. GestureDetector(
  156. onTap: () {
  157. LogUtil.e("jianshao商品");
  158. },
  159. child: Image.asset(Utils.getImgPath(
  160. 'refund_commit_cut_goods')),
  161. ),
  162. Container(
  163. margin: EdgeInsets.only(
  164. left:
  165. ScreenUtil.getInstance().getWidth(14),
  166. right: ScreenUtil.getInstance()
  167. .getWidth(14)),
  168. child: Text(
  169. '2',
  170. style: TextStyle(
  171. fontSize:
  172. ScreenUtil.getInstance().getSp(30),
  173. color: MyColors.color_home_top_text),
  174. ),
  175. ),
  176. GestureDetector(
  177. onTap: () {
  178. LogUtil.e("添加商品");
  179. },
  180. child: Image.asset(Utils.getImgPath(
  181. 'refund_commit_add_goods')),
  182. ),
  183. ],
  184. )
  185. ],
  186. ),
  187. ),
  188. Container(
  189. height: ScreenUtil.getInstance().getWidth(92),
  190. alignment: Alignment.centerLeft,
  191. margin: EdgeInsets.fromLTRB(
  192. ScreenUtil.getInstance().getWidth(20),
  193. 0,
  194. ScreenUtil.getInstance().getWidth(20),
  195. 0),
  196. child: Row(
  197. children: <Widget>[
  198. Container(
  199. width: ScreenUtil.getInstance().getWidth(340),
  200. child: Text(
  201. '预计退款',
  202. style: TextStyle(
  203. fontSize:
  204. ScreenUtil.getInstance().getWidth(30),
  205. color: MyColors.color_home_top_text),
  206. ),
  207. ),
  208. Container(
  209. width: ScreenUtil.getInstance().getWidth(340),
  210. alignment: Alignment.centerRight,
  211. child: Text(
  212. S.of(context).null_rmb + " " + "0.00",
  213. style: TextStyle(
  214. fontSize:
  215. ScreenUtil.getInstance().getWidth(30),
  216. color: MyColors.color_main),
  217. ),
  218. )
  219. ],
  220. ),
  221. ),
  222. getLine(
  223. size: ScreenUtil.getInstance().getWidth(1),
  224. width: 0,
  225. color: '#E5E5E5'),
  226. Container(
  227. margin: EdgeInsets.fromLTRB(
  228. ScreenUtil.getInstance().getWidth(20),
  229. ScreenUtil.getInstance().getWidth(30),
  230. ScreenUtil.getInstance().getWidth(20),
  231. ScreenUtil.getInstance().getWidth(18)),
  232. child: Row(
  233. children: <Widget>[
  234. Text(
  235. '说明',
  236. style: TextStyle(
  237. fontSize: ScreenUtil.getInstance().getSp(30),
  238. color: MyColors.color_home_top_text),
  239. ),
  240. getStart()
  241. ],
  242. ),
  243. ),
  244. Container(
  245. width: double.infinity,
  246. height: ScreenUtil.getInstance().getWidth(160),
  247. margin: EdgeInsets.fromLTRB(
  248. ScreenUtil.getInstance().getWidth(20),
  249. 0,
  250. ScreenUtil.getInstance().getWidth(20),
  251. 0),
  252. decoration: BoxDecoration(
  253. border: new Border.all(
  254. color: MyColors.color_input_text_hint,
  255. width: ScreenUtil.getInstance().getWidth(1)),
  256. // 边色与边宽
  257. shape: BoxShape.rectangle,
  258. // 默认值也是矩形
  259. ),
  260. child: Padding(
  261. padding: EdgeInsets.fromLTRB(
  262. ScreenUtil.getInstance().getWidth(24),
  263. ScreenUtil.getInstance().getWidth(16),
  264. ScreenUtil.getInstance().getWidth(24),
  265. ScreenUtil.getInstance().getWidth(16)),
  266. child: TextField(
  267. controller: _feedBackControllder,
  268. minLines: 3,
  269. maxLines: 5,
  270. decoration: InputDecoration(
  271. contentPadding:
  272. const EdgeInsets.symmetric(vertical: 4.0),
  273. hintText: '请描述售后原因',
  274. hintStyle: TextStyle(
  275. fontSize:
  276. ScreenUtil.getInstance().getWidth(28),
  277. color: MyColors.color_input_text_hint),
  278. border: OutlineInputBorder(
  279. borderRadius: BorderRadius.circular(15),
  280. borderSide: BorderSide.none),
  281. ),
  282. ),
  283. ),
  284. ),
  285. Container(
  286. margin: EdgeInsets.fromLTRB(
  287. ScreenUtil.getInstance().getWidth(20),
  288. ScreenUtil.getInstance().getWidth(30),
  289. ScreenUtil.getInstance().getWidth(20),
  290. ScreenUtil.getInstance().getWidth(18)),
  291. child: Row(
  292. children: <Widget>[
  293. Text(
  294. '上传照片',
  295. style: TextStyle(
  296. fontSize: ScreenUtil.getInstance().getSp(30),
  297. color: MyColors.color_home_top_text),
  298. ),
  299. getStart(),
  300. Text(
  301. "(请上传商品照片,照片需包含标签)",
  302. style: TextStyle(
  303. fontSize:
  304. ScreenUtil.getInstance().getWidth(26),
  305. color: MyColors.color_input_text_hint),
  306. )
  307. ],
  308. ),
  309. ),
  310. Container(
  311. margin: EdgeInsets.only(
  312. left: ScreenUtil.getInstance().getWidth(20),
  313. right: ScreenUtil.getInstance().getWidth(20),
  314. bottom: ScreenUtil.getInstance().getWidth(70)),
  315. child: Row(
  316. children: <Widget>[
  317. Container(
  318. decoration: BoxDecoration(
  319. border: new Border.all(
  320. color: MyColors.color_input_text_hint,
  321. width:
  322. ScreenUtil.getInstance().getWidth(1)),
  323. // 边色与边宽
  324. shape: BoxShape.rectangle,
  325. // 默认值也是矩形
  326. color: MyColors.color_white),
  327. alignment: Alignment.center,
  328. height: ScreenUtil.getInstance().getWidth(126),
  329. width: ScreenUtil.getInstance().getWidth(126),
  330. child: Image.asset(
  331. Utils.getImgPath('refund_commit_5_img')),
  332. )
  333. ],
  334. ),
  335. ),
  336. Container(
  337. margin: EdgeInsets.only(
  338. left: ScreenUtil.getInstance().getWidth(20),
  339. right: ScreenUtil.getInstance().getWidth(20)),
  340. child: MaterialButton(
  341. onPressed: isCommit != 0
  342. ? () {
  343. _onClickNext();
  344. }
  345. : null,
  346. height: ScreenUtil.getInstance().getWidth(80),
  347. minWidth: ScreenUtil.getInstance().getWidth(648),
  348. child: Text(
  349. '提交',
  350. style: TextStyle(
  351. color: isCommit != 0
  352. ? Colors.white
  353. : MyColors.color_red_pack_data,
  354. fontSize:
  355. ScreenUtil.getInstance().getWidth(36)),
  356. textAlign: TextAlign.center,
  357. ),
  358. color: MyColors.color_main,
  359. disabledColor: MyColors.color_input_button_no_click,
  360. shape: RoundedRectangleBorder(
  361. borderRadius: BorderRadius.circular(
  362. ScreenUtil.getInstance().getWidth(8)),
  363. side: BorderSide(
  364. width: ScreenUtil.getInstance().getWidth(1),
  365. color: MyColors.color_CE)),
  366. elevation: 0,
  367. //按钮下面的阴影
  368. highlightElevation: 0,
  369. //高亮时候的阴影
  370. disabledElevation: 0, //按下的时候的阴影
  371. ),
  372. ),
  373. ],
  374. ),
  375. ),
  376. ),
  377. )
  378. ],
  379. ),
  380. ],
  381. ),
  382. backgroundColor: MyColors.color_white,
  383. resizeToAvoidBottomPadding: false,
  384. )

上面的输入法高度是跟随输入法出现而有的,输入法不出现是0:

MediaQuery.of(context).viewInsets.bottom

是让其可滑动

以上两点即可完成TextFeild跟随输入法高度滑动。主要代码截图如下:

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号