Flutter鍏ラ棬鍩虹
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flutter鍏ラ棬鍩虹相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/package' title='package'>package
amber -o bottom tin 娉ㄦ剰 璇嗗埆 datetime schFlutter鏄疓oogle寮€鍙戠殑涓€濂楀叏鏂扮殑璺ㄥ钩鍙般€佸紑婧怳I妗嗘灦(鏈川涓婂氨鏄痵dk)銆?鏀寔iOS銆丄ndroid绯荤粺锛屽苟涓旀槸Fuchsia绯荤粺鐨勯粯璁ゅ紑鍙戝浠躲€傛闈㈠拰web涓婄殑鏀寔涔熼兘鍦ㄥ疄楠屼腑銆?br /> Flutter鐗圭偣锛氳法骞冲彴锛團lutter鏄疐uchsia鐨勫紑鍙戞鏋讹紝鍚屾椂鏀寔Android銆両OS锛夛紝濯茬編鍘熺敓鎬ц兘锛岀儹閲嶈浇(鐩墠涓嶆敮鎸佺儹鏇存柊锛屼絾宸插姞鍏?019宸ヤ綔璁″垝)銆?/p>
鍏跺畼鏂圭紪绋嬭瑷€涓?strong>Dart锛?a href="https://juejin.im/post/5bcc8527f265da0aff17729a" rel="nofollow" target="_blank">鐔熸倝Dart璇█銆?/p>
鍏ラ棬缃戠珯锛?a href="https://flutterchina.club/" rel="nofollow" target="_blank">Flutter涓枃缃?/a> Flutter瀹樼綉锛堣嫳鏂囷級
1銆佸伐绋嬪熀纭€绠€浠?/h5>
1.1 Dart瀵煎寘瑙勫垯
锛?锛夊鍖卍art搴撻噷闈㈢殑鍖?/p>
import 鈥榙art:html鈥?span class="token punctuation">;
锛?锛夊鍏ubspec.yaml 鐨刣ependencies渚濊禆鐨勫寘
import 鈥榩ackage:test/test.dart鈥?span class="token punctuation">;
锛?锛夊鍏ヨ矾寰勫寘锛宐ase涓篺lutter鏍圭洰褰?/p>
import 鈥榩ackage:base/components/swiper.dart鈥?span class="token punctuation">;
锛?锛夊彧瀵煎叆foo
import 鈥榩ackage:lib1/lib1.dart鈥?show foo;
锛?锛塈m闄や簡foo閮藉鍏?/p>
import 鈥榩ackage:lib2/lib2.dart鈥?hide foo;
锛?锛夊寘閲岄潰瀛樺湪鏍囪瘑绗﹀啿绐?/p>
import 鈥榩ackage:lib1/lib1.dart鈥?span class="token punctuation">;
import 鈥榩ackage:lib2/lib2.dart鈥?as lib2;
锛?锛夊欢杩熷姞杞斤紙鎳掑姞杞斤級鍏佽搴旂敤绋嬪簭鍦ㄩ渶瑕佹椂鍔犺浇搴撱€備互涓嬫槸涓€浜涙偍鍙兘浣跨敤寤惰繜鍔犺浇鐨勬儏鍐碉細
鍑忓皯搴旂敤绋嬪簭鐨勫垵濮嬪惎鍔ㄦ椂闂淬€?br />
渚嬪锛屾墽琛孉 / B娴嬭瘯 - 璇曠敤绠楁硶鐨勫叾浠栧疄鐜般€?br />
鍔犺浇寰堝皯浣跨敤鐨勫姛鑳斤紝渚嬪鍙€夌殑瀵硅瘽妗嗐€?/p>
import 鈥榩ackage:greetings/hello.dart鈥?deferred as hello;
1.2 宸ョ▼閰嶇疆鏂囦欢锛?/h6>
Flutter椤圭洰涓殑pubspec.yaml鏂囦欢鐩稿綋浜嶢ndroid椤圭洰涓殑gradle鏂囦欢锛岄」鐩殑淇℃伅浠ュ強渚濊禆鍦ㄦ鏂囦欢涓0鏄庛€備緷璧栧寘鐢眕ub鍖呬粨搴撶鐞嗭細https://pub.dartlang.org/ 锛屾湭鍙戝竷鍦╬ub鍖呬粨搴撶殑鎻掍欢鍙互浣跨敤鏈湴鏂囦欢璺緞锛岀敋鑷冲彲浠ョ洿鎺ヤ娇鐢╣it椤圭洰鍦板潃銆?鍙傝€冿細https://flutterchina.club/using-packages/
渚濊禆鍐茬獊锛氱敤any鏉ヨВ鍐筹紝浼氭壘鍒版渶鍚堥€傜殑涓嶅啿绐佺増鏈紝鍐嶅埌 pubspec.lock涓壘鍒扮増鏈彿鏇挎崲锛屾渶缁堜笉瑕佺洿鎺ョ敤any锛屾槸涓闄┿€?/p>
#name寰堥噸瑕侊紝濡傛灉淇敼浜唍ame鎵€鏈夌殑dart鐨勬枃浠剁殑import鍓嶅紩鐢ㄧ殑鏈湴鐨勬枃浠跺晩鐨勫寘鍚嶉兘闇€瑕佷慨鏀?
name: flutterdemo
description: A new Flutter application.
dependencies:
flutter:
sdk: flutter
#娣诲姞渚濊禆packages
cupertino_icons: ^0.1.2
english_words: ^3.1.0
# image_picker: ^0.4.8
dev_dependencies:
flutter_test:
sdk: flutter
#鍚敤鍥介檯鍖?
flutter_localizations:
sdk: flutter
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
#娣诲姞璧勬簮锛屼笉鍗曞崟鏄浘鐗囷紝images鏄釜鍜宲ubspec.yaml閰嶇疆鏂囦欢鍚岀骇鐨勭洰褰曪紝濡傛灉涓嶅悓绾э紝闇€瑕佹坊鍔?.
assets:
- images/park.jpg
- images/lake.jpg
- images/touxiang.jpg
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#瀛椾綋璁剧疆
fonts:
- family: Schyler
fonts:
- asset: fonts/Schyler-Regular.ttf
- asset: fonts/Schyler-Italic.ttf
style: italic
- family: Trajan Pro
fonts:
- asset: fonts/TrajanPro.ttf
- asset: fonts/TrajanPro_Bold.ttf
weight: 700
2銆佸叧浜嶮aterialApp鍜孲caffold锛?/h5>
Flutter鎻愪緵浜嗕袱濂椾笉鍚岄鏍肩殑UI鎺т欢锛屽垎鍒槸绫籄ndroid椋庢牸鐨凪aterialApp鍜岀被IOS椋庢牸鐨凜upertinoApp銆備袱绉嶉鏍间笅闈㈢殑widget涓嶈兘瀹屽叏閫氱敤锛屼笖Material椋庢牸鐨剋idget鏁伴噺瑕佸涓€浜涖€?/p>
~ MaterialApp鏄疐lutter鎻愪緵缁橝ndroid鐨勪竴涓熀纭€widget锛岄噰鐢ㄤ簡鏉愭枡璁捐椋庢牸銆?br /> 缁忚繃瀹炶返锛孧aterialApp鍏ㄥ眬鏈€濂藉彧鏈変竴涓紝浣滀负涓荤晫闈紝app鐨勪富棰樸€佷富椤电瓑鍏ㄥ眬璁剧疆鍙互鍦ㄦ瀹氫箟銆?br /> 鏈€鍒濇寜鐓у畼缃戞暀绋嬫瘡涓猵age鎴戦兘杩斿洖鐨凪aterialApp锛屾樉绀烘槸娌′粈涔堥棶棰橈紝鍥犱负閮芥槸widget锛屼絾鏄細鍑虹幇鍗¢】鍜屽叾浠栫晫闈笂鐨勯棶棰橈紝澶у鍙互鑷繁璇曚竴涓嬨€?/p>
~ 瀛愰〉闈㈢洿鎺ヨ繑鍥濻caffold锛孲caffold鏄疢aterialApp鐨勫竷灞€瀹炵幇锛屾彁渚涗簡appbar锛宖loatingActionButton锛宒rawer锛宐ottomNavigationBar绛塎D椋庢牸鐨勬帶浠禷pi銆?/p>
Flutter榛樿浼氬湪debug妯″紡涓嬪湪鍙充笂瑙掓樉绀烘按鍗帮紝鍘婚櫎鏂瑰紡锛?/p>
debugShowCheckedModeBanner: false
3銆佽嚜瀹氫箟鎺т欢銆?/h5>
Flutter妗嗘灦缁欐垜浠彁渚涗簡StatelessWidget鍜孲tatefulWidget涓や釜鎶借薄绫伙紝鐢ㄤ簬鑷畾涔夋帶浠躲€?br /> 锛?锛?strong>StatelessWidget鏄?lsquo;‘鏃犵姸鎬佹帶浠?rsquo;’,涓嶅彲鍙樼姸鎬佹帶浠?閫氳繃鏋勫缓鍏朵粬鎺т欢鏉ユ弿杩扮敤鎴风晫闈㈢殑涓€閮ㄥ垎銆傚繀椤诲疄鐜癰uild鏂规硶锛岃繑鍥炰竴涓獁idget瀵硅薄銆?Icon銆?IconButton, 鍜孴ext绛夐兘鏄棤鐘舵€亀idget, 浠栦滑閮芥槸 StatelessWidget鐨勫瓙绫汇€?br /> 锛?锛?strong>StatefulWidget 鏄姩鎬佺殑. 鐢ㄦ埛鍙互鍜屽叾浜や簰 (渚嬪杈撳叆涓€涓〃鍗曘€?鎴栬€呯Щ鍔ㄤ竴涓猻lider婊戝潡),鎴栬€呭彲浠ラ殢鏃堕棿鏀瑰彉 (涔熻鏄暟鎹敼鍙樺鑷寸殑UI鏇存柊).Checkbox, Radio, Slider, Form, 鍜孴extField 閮芥槸 stateful widgets, 浠栦滑閮芥槸 StatefulWidget鐨勫瓙绫汇€?/p>
锛?锛?strong>鑷畾涔塛idget锛氱户鎵縎tatefulWidget锛屽苟閲嶅啓createState()鏂规硶锛岃繑鍥炰竴涓猄tate瀵硅薄銆?br /> 鑷畾涔夋棤鐘舵€佺殑widget锛?/p>
class RedBoard extends StatelessWidget {
const RedBoard({ Key key }) : super(key: key);
@override
Widget build(BuildContext context) {
return new Container(
color: Colors.red
);
}
}
鑷畾涔夊彲鍙樼姸鎬佺殑widget锛?/p>
class RandomWords extends StatefulWidget {
锛?锛?strong>缁ф壙鑷狢ustomPaint鐢绘帶浠?/strong>
Flutter涔熷彲浠ュ儚Android涓户鎵縑iew鐨勬柟寮忔潵缁樺埗鎺т欢锛岄€氳繃缁ф壙CustomPaint绫绘潵瀹炵幇锛屽叿浣撶敤娉曟澶勭暐銆?/p>
4銆乀extField鏍峰紡
decoration: new InputDecoration(
hintText: 鈥榠nput name to search鈥?span class="token punctuation">,
border: InputBorder.none
)
鍘绘帀涓嬭竟妗嗐€?br /> 澶栭潰濂椾笂Container锛屽姞涓婅楗板疄鐜板洓闈㈣竟妗嗘晥鏋?/p>
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.green, width: 1.0),
borderRadius: BorderRadius.circular(4)),
娉ㄦ剰锛?br /> 鍦╠ecoration涓姞浜哻olor灞炴€э紝鍦–ontainer涓氨涓嶈兘鍔燾olor灞炴€э紝鍚﹀垯浼氬嚭閿欍€?/p>
TextField鍧?/strong>锛?br /> 杞敭鐩榬esize绐楀彛锛岃В鍐虫柟寮忥細
In your `Scaffold`, set `resizeToAvoidBottomPadding` property to `false`.
preprefixIcon鍜宻uffixIcon濡傛灉浣跨敤绯荤粺鎻愪緵鐨剆vg璧勬簮锛岄渶瑕佹寚瀹氶鑹诧紝涓嶇劧鍦ㄨ幏鍙栫劍鐐规椂浼氬彉鎴愪笉鍙鐘舵€併€?/p>
5銆丩istView
ListView鐨勪娇鐢ㄥ彲浠ュ弬鑰冩鏂囷細https://blog.csdn.net/hao_m582/article/details/84112278
濡傛灉涓庡叾浠杦idget鏀惧湪鍚屼竴涓狢olumn涓紝ListView澶栧姞Expanded鎵嶈兘姝e父鏄剧ず銆?/p>
鍙互鐢↙istView浣滀负婊氬姩鍧楋紝鐩稿綋浜巃ndroid涓殑ScrollView鏁堟灉锛屼絾鏄瓙view涓嶆槸鍐欏湪widget涓紝鑰屾槸鐩存帴鍐欏湪ListView鐨刢hildren灞炴€т腑锛屽锛?/p>
//...
body: new ListView(
children: [
new Image.asset(
鈥榠mages/lake.jpg鈥?span class="token punctuation">,
width: 600.0,
height: 240.0,
fit: BoxFit.cover,
),
titleSection,
buttonSection,
textSection,
],
),
//..
6銆佸姞杞藉浘鐗囦笌鎺т欢缂╂斁
闇€瑕佸湪pubspec.xml涓厤缃浘鐗囪矾寰勶紝鍙互鐪嬩笂娈典唬鐮佺墖娈点€?/p>
assets:
- images/park.jpg
- images/lake.jpg
- images/touxiang.jpg
鍏朵腑images鏂囦欢澶规斁鍦ㄥ伐绋嬬殑鏍圭洰褰曘€傚姞杞藉浘鐗囧彲浠ョ洿鎺ヤ娇鐢ˋssertImage绫伙紝涔熷彲浠ヤ娇鐢↖mage.asset鏂规硶銆?br />
缁忚繃鏌ユ壘锛宖lutter涓嶅畬鍏ㄦ敮鎸乻vg锛寈ml鏍煎紡鐨刅ectorDrawable鍦╢lutter涓婃棤娉曠洿鎺ュ姞杞?/em>
绫讳技Android涓璉mageView鐨剆caleType灞炴€э紝flutter鐨処mage鎺т欢涔熸湁鍏跺睘鎬oxfit锛岃€屼笖杩欎釜灞炴€т笉浠呬粎閫傜敤浜嶪mage鐩稿叧鐨刉idget锛孎ittedBox涔熷叿鏈夋灞炴€с€?br />
FittedBox浼氬湪鑷繁鐨勫昂瀵歌寖鍥村唴缂╂斁骞朵笖璋冩暣child浣嶇疆锛屼娇寰梒hild閫傚悎鍏跺昂瀵搞€?br />
绀轰緥浠g爜锛?/p>
new Container(
color: Colors.amberAccent,
width: 300.0,
height: 300.0,
child: new FittedBox(
fit: BoxFit.contain,
alignment: Alignment.topLeft,
child: new Container(
color: Colors.red,
child: new Text("FittedBox"),
),
),
)
鐪嬩竴涓嬪嚑绉嶇缉鏀炬柟寮忕殑鍖哄埆锛?/p>
7銆丗lutter鏋勫缓甯冨眬瀹炰緥
Flutter甯冨眬鏈哄埗鐨勬牳蹇冩槸Widget銆傚湪Flutter涓紝鍑犱箮鎵€鏈変笢瑗块兘鏄疻idget - 鐢氳嚦甯冨眬妯″瀷閮芥槸Widget銆備綘鍦‵lutter搴旂敤涓湅鍒扮殑鍥惧儚銆佸浘鏍囧拰鏂囨湰閮芥槸widget銆?鐢氳嚦浣犵湅涓嶅埌鐨勪笢瑗夸篃鏄痺idget锛屼緥濡傝锛坮ow锛夈€佸垪锛坈olumn锛変互鍙婄敤鏉ユ帓鍒椼€佺害鏉熷拰瀵归綈杩欎簺鍙widget鐨勭綉鏍硷紙grid锛夈€?/p>
鏌ョ湅Flutter涓枃缃戠殑鏁欑▼锛?a href="https://flutterchina.club/tutorials/layout/" rel="nofollow" target="_blank">鍦‵lutter涓瀯寤哄竷灞€
甯哥敤Widget锛?br /> 锛?锛塁olumn鍜孯ow鐩稿浜嶢ndroid涓殑LinearLayout锛孋olumn鐩稿浜嶰rientation.Vertical锛汻ow鐩稿綋浜嶰rientation.Horizontal銆?/p>
锛?锛塋istView 锛孏ridView涓嶢ndroid涓殑鍚屽悕鎺т欢鏁堟灉绛夊悓
ListTitle鏄疐lutter灏佽濂界殑鍦ㄥ垪琛ㄤ腑鏄剧ず鐨刬tem鎺т欢锛屼粬鏈夊浐瀹氱殑鏄剧ず鏍煎紡锛屽涓嬶細
锛?锛塖tack鐩稿綋浜嶢ndroid涓殑FrameLayout锛屼絾鏄畠鍙堝叿鏈塕elativeLayout鐨勪竴浜涘睘鎬с€?/p>
锛?锛塁ard鐩稿綋浜嶢ndroid涓殑CardView
锛?锛変簨浠跺搷搴旓細Flutter骞堕潪涓烘墍鏈塛idget閮界洿鎺ユ彁渚涗簡鐐瑰嚮锛岄暱鎸夌瓑浜嬩欢鍝嶅簲锛岃繖鏃舵垜浠渶瑕佺敤 GestureDetector杩欎釜widget鍖呰9闇€瑕佸搷搴斾簨浠剁殑widget鏉ュ疄鐜板姛鑳姐€?br />
GestureDetector鎻愪緵浜嗗涓嬫墜鍔匡細
Tap
onTapDown 鎸囬拡宸茬粡鍦ㄧ壒瀹氫綅缃笌灞忓箷鎺ヨЕ
onTapUp 鎸囬拡鍋滄鍦ㄧ壒瀹氫綅缃笌灞忓箷鎺ヨЕ
onTap tap浜嬩欢瑙﹀彂
onTapCancel 鍏堝墠鎸囬拡瑙﹀彂鐨刼nTapDown涓嶄細鍦ㄨЕ鍙憈ap浜嬩欢
鍙屽嚮
onDoubleTap 鐢ㄦ埛蹇€熻繛缁袱娆″湪鍚屼竴浣嶇疆杞绘暡灞忓箷.
闀挎寜
onLongPress 鎸囬拡鍦ㄧ浉鍚屼綅缃暱鏃堕棿淇濇寔涓庡睆骞曟帴瑙?br />
鍨傜洿鎷栧姩
onVerticalDragStart 鎸囬拡宸茬粡涓庡睆骞曟帴瑙﹀苟鍙兘寮€濮嬪瀭鐩寸Щ鍔?br />
onVerticalDragUpdate 鎸囬拡涓庡睆骞曟帴瑙﹀苟宸叉部鍨傜洿鏂瑰悜绉诲姩.
onVerticalDragEnd 鍏堝墠涓庡睆骞曟帴瑙﹀苟鍨傜洿绉诲姩鐨勬寚閽堜笉鍐嶄笌灞忓箷鎺ヨЕ锛屽苟涓斿湪鍋滄鎺ヨЕ灞忓箷鏃朵互鐗瑰畾閫熷害绉诲姩
姘村钩鎷栧姩
onHorizontalDragStart 鎸囬拡宸茬粡鎺ヨЕ鍒板睆骞曞苟鍙兘寮€濮嬫按骞崇Щ鍔?br />
onHorizontalDragUpdate 鎸囬拡涓庡睆骞曟帴瑙﹀苟宸叉部姘村钩鏂瑰悜绉诲姩
onHorizontalDragEnd 鍏堝墠涓庡睆骞曟帴瑙﹀苟姘村钩绉诲姩鐨勬寚閽堜笉鍐嶄笌灞忓箷鎺ヨЕ锛屽苟鍦ㄥ仠姝㈡帴瑙﹀睆骞曟椂浠ョ壒瀹氶€熷害绉诲姩銆?/p>
锛?锛塀utton锛欶lutter鎻愪緵浜嗗嚑绉嶆牱寮忕殑鎸夐挳锛屽垎鍒负锛?br /> FlatButton锛氭墎骞崇殑锛屾病鏈夐槾褰辨晥鏋滅殑銆?br /> RaisedButton锛氭湁闃村奖鏁堟灉鐨勩€?br /> FloatingActionButton锛氭偓娴寜閽紝绫讳技Android涓婂悓鍚嶇殑鎺т欢銆?br /> OutlineButton锛氱嚎妗嗘寜閽紝甯﹀杈规鐨勬寜閽€?/p>
锛?锛塃xpanded銆丗lexible锛欵xpanded 杩欐槸涓敤鏉ヨ瀛愰」鍏锋湁浼哥缉鑳藉姏鐨剋idget锛岀户鎵胯嚜Flexible銆傚畠浠袱涓殑榛樿鐏垫椿绯绘暟鏄竴鏍风殑锛屼絾鏄痜it鍙傛暟涓嶅悓锛孍xpanded鏄粯璁よ鍗犳弧鍒嗛厤鐨勭┖闂寸殑锛岃€孎lexible鍒欓粯璁や笉闇€瑕併€?/p>
锛?锛塕ipple鏁堟灉锛欶lutter涓枃缃戝皢InkWell缈昏瘧鎴?ldquo;澧ㄦ按椋炴簠”鏁堟灉锛屽叾瀹炵湅鍒版晥鏋滃悗锛屾垜浠┈涓婂氨鑳借仈鎯冲埌Android涓殑ripple鏁堟灉銆?/p>
鐢ㄦ硶涔熸槸鐢↖nkWell濂楄捣鎯宠杈惧埌鏁堟灉鐨剋idget锛屽叿浣撳睘鎬ф煡鐪嬫簮鐮佹敞閲娿€?/p>
涓嬮潰鐢ㄤ竴涓叿浣撶殑渚嬪瓙浠嬬粛甯冨眬鍜屽叾浠栧彲鑳界敤鍒扮殑Widget锛?/strong>
涓婂浘鏄父瑙佺殑鑱婂ぉ鍒楄〃鏍峰紡锛岄鍏堟垜浠兘鎯冲埌鐨勬槸鏁翠釜鐣岄潰鏄竴涓狶istView锛屾牴鎹被鍨嬫湁宸﹁竟鍜屽彸杈逛袱绉嶆牱寮忋€傜敱浜巉lutter娌℃湁xml甯冨眬锛屾墍鏈夌晫闈㈤兘鏄€氳繃widget鎼Н鏈ㄤ竴鏍凤紝涓€灞備竴灞傚璧锋潵鐨勩€?/p>
宸︿晶鐨勬樉绀猴細鏈€澶栧眰搴旇鏄竴涓猂ow锛孯ow涓寘鍚簡涓€涓狢ircleAvatar锛堟病閿欙紝杩欎釜Widget瀹樻柟鐩存帴鎻愪緵浜嗭級鍜屼竴涓猅ext銆?br />
鎬庢牱鎺у埗Text鐨勮儗鏅牱寮忥細
棣栧厛鎯冲埌鐨勫氨鏄灞傚涓€涓彲浠ヨ缃牱寮忕殑Container锛岄€氳繃缁機ontainer鍔犱竴涓猟ecoration灞炴€э紝涓€鑸娇鐢˙oxDecoration锛屽彲浠ヤ负Container璁剧疆鑳屾櫙棰滆壊锛屽墠鏅鑹诧紝杈规锛屽渾瑙掞紝鍥剧墖绛夎兘婊¤冻澶ч儴鍒嗗満鏅殑鏍峰紡銆?br />
闂鍑虹幇浜?/strong>
Text鏈韩鏄敮鎸佹枃瀛楄嚜鍔ㄦ崲琛岀殑锛孋ontainer鏈韩濡傛灉娌℃湁鐖舵帶浠堕檺鍒朵篃鏄寘瑁圭殑锛屼絾鍥犱负澶栭潰鏀句簡涓€涓猂ow锛屽氨浼氬嚭鐜版孩鍑哄睆骞曠殑闂銆傜粡杩囧鐣煡鎵撅紝鎴戞壘鍒颁簡涓€涓猈idget鍙互瑙e喅闂——Flexible锛屽湪Container澶栭潰濂椾竴涓狥lexible灏辫兘瑙e喅闂锛屾鏃堕渶瑕佹敞鎰忕殑鏄紝Flexible锛孍xpanded绛夊彲浠ヨ嚜閫傚簲鐨勭户鎵夸簡Flex鐨勬帶浠讹紝鍏剁埗鎺т欢涔熷繀椤绘槸鍚岀被鍨嬨€?
鎺ヤ笅鏉ユ垜浠鎺у埗鏂囧瓧鐨勬渶闀挎樉绀哄搴︼紝Container鏈変竴涓睘鎬ф槸constraints锛屽畠鐨勭被鍨嬫槸BoxConstraints锛岃繖涓猈idget鍙互璁剧疆鏈€灏忔渶澶у楂橈紝涓嶉檺鍒剁殑璇濆氨鐢╠ouble.infinity(鏃犻檺)銆傚湪缁忚繃闄愬埗鍚庯紝鎴戜滑鍙戠幇Flexible宸茬粡涓嶉渶瑕佷簡锛屽洜涓哄搴﹀凡缁忛檺鍒朵綇浜?.=|||銆?/p>
//鑾峰彇灞忓箷瀹藉害鐨勬柟娉?
double width = MediaQuery.of(context).size.width;
鎺ヤ笅鏉ユ垜浠寜鐓ndroid涓殑鐞嗚В锛屾樉绀哄彸渚уご鍍忕殑娑堟伅锛屽氨鍦≧ow涓厛鍔犲叆涓€涓猅ext锛屽啀鍔犲叆涓€涓狢ircleAvatar銆傛病閿欙紝浣嗘槸鎬庢牱灞呭彸鏄剧ず鍛紵缁忚繃鏌ヨ璧勬枡鍙戠幇锛孯ow閫氳繃textDirection灞炴€у彲浠ヨ缃柟鍚戯紝鎴戜滑灏嗗睘鎬ц缃垚TextDirection.rtl锛屼篃灏辨槸rightToLeft锛屽彂鐜板挦锛熸€庝箞澶村儚璺戝埌鍓嶉潰鍘讳簡锛熼偅鎴戜滑鍐嶆妸澶村儚浠g爜绉诲埌鍓嶉潰锛岀珶鐒跺浜嗐€傘€備篃灏辫鏄庯紝Row鐨勭粯鍒舵祦绋嬮兘鏄牴鎹甤hildren涓渶鍏堝姞鍏ョ殑瀛恮idget鏉ョ粯鍒剁殑銆?/p>
杈撳叆妗嗗疄鐜帮細
杈撳叆妗嗛鍏堣淇濇寔鍦ㄧ晫闈㈠簳閮紝鎬庝箞瀹炵幇鍛紵浜嗚В鍒板畼鏂规彁渚涗簡涓€涓狟ottomAppBar锛屽皢鍏惰缃粰Scaffold涓殑bottomNavigationBar灞炴€с€侭ottomAppBar鐨刢hild缁欏埌涓€涓猂ow鎺т欢锛屾帓鍒楄闊虫寜閽甀conButton锛岃緭鍏ユTextField锛屾洿澶氭寜閽甀conButton銆俆extField澶栭儴瑕佸祵濂椾竴涓狢ontainer淇グ鏍峰紡銆傝繍琛屽悗鍙戠幇鏁翠釜鐣岄潰閮芥棤娉曟樉绀猴紝鑰屾敞閲婃帀TextField灏卞彲浠ユ樉绀猴紝鐢辨鎯冲埌搴旇鏄疶extField鐨勫搴︿笉姝e父瀵艰嚧鐨勶紝浣跨敤涓囪兘鎺т欢Flexible濂楀湪TextField鐨勭埗绾ontainer澶栧悗鏄剧ず姝e父銆?br />
鎺ヤ笅鏉ヨ瘯璇曡緭鍏ユ枃瀛楋紝鍙堝嚭鐜板潙浜?/strong>锛丅ottomAppBar鍦ㄨ緭鍏ユ硶寮瑰嚭鏃舵棤娉曡嚜鍔ㄤ笂绉伙紝纭畾浜唕esizeToAvoidBottomPadding璁剧疆涓簍rue鐨勬儏鍐典緷鐒舵棤娉曡В鍐抽棶棰樺悗锛屽彧濂芥壘鍏朵粬鏂瑰紡銆傚湪stackoverflow涓婃壘鍒颁簡鍙︿竴绉嶆柟妗堬細灏嗘渶涓嬮潰鐨勮緭鍏ュ竷灞€杩炲悓ListView閮芥斁鍏caffold鐨刡ody涓紝ListView澶栧姞涓奅xpanded浼哥缉锛屾渶澶栧眰涓€涓狢ontainer鍖呰9锛岃繍琛屽畬缇庯紝浠g爜濡備笅锛?/p>
@override
Widget build(BuildContext context) {
_getConversations();
return new Scaffold(
appBar: new AppBar(
title: new Text(mIsGroup
? mConversation.groupBean.groupName
: mConversation.contactBean.nickName != null
? mConversation.contactBean.nickName
: mConversation.contactBean.pin),
elevation: 0.5,
actions: <Widget>[
new IconButton(
icon: new Icon(
mIsGroup ? Icons.group : Icons.person,
size: 24,
color: Colors.black54,
),
onPressed: _goContactInfo),
],
),
body: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Expanded(
child: _buildConversations(),
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(icon: Icon(Icons.keyboard_voice), onPressed: null),
Flexible(
child: Container(
height: 40,
margin: EdgeInsets.fromLTRB(10, 6, 10, 6),
padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: Colors.black12,
width: 0.5,
style: BorderStyle.solid,
),
borderRadius: BorderRadius.circular(4),
),
child: TextField(
decoration: InputDecoration(
hintText: 鈥樿緭鍏ュ唴瀹光€?span class="token punctuation">, border: InputBorder.none),
)),
),
Container(
margin: EdgeInsets.fromLTRB(0, 0, 10, 0),
child: IconButton(icon: Icon(Icons.add_circle_outline),onPressed: null,),
)
],
)