企业网站建设方案书模板,python网站开发视频教程,c2c模式的优势和劣势,永久免费的手机ip代理自适应设计 效果视频实体数据实体类转为ListMap数据 宽度自适应宽布局释左列右列 窄布局释路由 高度自适应高布局释 低布局释 注 效果视频 Flutter——自适应设计 实体数据
实体类
class People{final String name;final String age;final String address;final String phone… 自适应设计 效果视频实体数据实体类转为ListMap数据 宽度自适应宽布局释左列右列 窄布局释路由 高度自适应高布局释 低布局释 注 效果视频 Flutter——自适应设计 实体数据
实体类
class People{final String name;final String age;final String address;final String phone;final String picture;const People(this.name,this.age,this.address,this.phone,this.picture);
}转为List
将集合Map中的数据转为List形式
final ListPeople peoples peopleMap.map((e) People(e[name].toString(),e[age].toString(),e[address].toString(),e[phone].toString(),e[picture].toString())).toList(growable: false);Map数据
下列一组Map数据是为啦实验这个Demo做的一组模拟数据
final ListMapString,Object peopleMap [{name: FranzLiszt,age: 21,sex: male,address: 湖南省xxxxxxxxxxxxxxx,phone: 17311112222,picture: https://puui.qpic.cn/vstar_pic/0/name_77904_688t1467970955.jpg/0?max_age7776000},{name: Jack,age: 19,sex: male,address: 湖北省xxxxxxxxxxxxxxx,phone: 1733334444,picture: https://puui.qpic.cn/vstar_pic/0/name_94722_688t1505976146.jpg/0?max_age7776000},{name: Peter,age: 35,sex: male,address: 北京市xxxxxxxxxxxxxxx,phone: 17344445555,picture: https://puui.qpic.cn/media_img/0/854561579417059/0?max_age7776000},{name: Smith,age: 45,sex: male,address: 河南xxxxxxxxxxxxxxx,phone: 17344556666,picture: https://puui.qpic.cn/media_img/0/932661658913960/0?max_age7776000},{name: Garcia,age: 21,sex: female,address: 天津市xxxxxxxxxxxxxxx,phone: 17366778899,picture: https://puui.qpic.cn/media_img/0/955481577176312/0?max_age7776000},{name: Rodriguez,age: 17,sex: male,address: 河北省xxxxxxxxxxxxxxx,phone: 17322334455,picture: https://puui.qpic.cn/media_img/0/1093271609034985/0?max_age7776000},{name: Wilson,age: 38,sex: male,address: 江苏省xxxxxxxxxxxxxxx,phone: 17311223344,picture: https://puui.qpic.cn/vstar_pic/0/name_77904_688t1467970955.jpg/0?max_age7776000},{name: Jones,age: 44,sex: male,address: 浙江省xxxxxxxxxxxxxxx,phone: 17377889900,picture: https://puui.qpic.cn/vstar_pic/0/name_77904_688t1467970955.jpg/0?max_age7776000},{name: Miller,age: 18,sex: female,address: 四川省xxxxxxxxxxxxxxx,phone: 17323233434,picture: https://puui.qpic.cn/vstar_pic/0/name_77904_688t1467970955.jpg/0?max_age7776000},{name: Davis,age: 55,sex: male,address: 重庆市xxxxxxxxxxxxxxx,phone: 17334345656,picture: https://puui.qpic.cn/vstar_pic/0/name_77904_688t1467970955.jpg/0?max_age7776000}];宽度自适应
通过LayoutBuilder组件构造两个布局通过获取当前屏幕宽度大小如果小于限定值则采用窄布局反之采用宽布局
class _MyHomePageState extends StateMyHomePage {overrideWidget build(BuildContext context) {return Scaffold(appBar: AppBar(title: Text(widget.title),),body: LayoutBuilder(builder: (context,constraints){//maxWidth 428.0if(constraints.maxWidth 500){return const NarrowLayout();}else{return const WidthLayout();}},),);}}宽布局 释
通过采用Row布局形成一个一行两列的排列然后通过Expanded去控制两列大小权重左列为一个ListView列表右列为点击左列Ietm回调的相关数据其中需要注意的时左列personCallBack为一个回调方法回调结果为当前被点击的Item实体类数据然后做了一个setState刷新行为将数据赋值给变量_person让其方便展示右列数据
/// 假如屏幕宽度大于限定值后采用此布局
/// 例如当屏幕旋转后此时宽度为之前的高度*/class WidthLayout extends StatefulWidget {const WidthLayout({Key? key}) : super(key: key);overrideStateWidthLayout createState() _WidthLayoutState();
}class _WidthLayoutState extends StateWidthLayout {People? _person;overrideWidget build(BuildContext context) {return Row(children: [Expanded(flex: 2,child: PeopleList(personCallBack: (person) setState(() { _person person;})),),Expanded(flex: 3,child: _person null ? const Placeholder():PeopleDetail(person: _person!))],);}
}左列
左边展示一个联系人列表并定义啦一个personCallBack接口然后在Item的点击方法内实现了此方法将此方法进行传递联系上文所描述的右列展示数据来源于此
class PeopleList extends StatelessWidget {final void Function(People) personCallBack;const PeopleList({Key? key,required this.personCallBack}) : super(key: key);overrideWidget build(BuildContext context) {return ListView.builder(itemCount: peoples.length,itemBuilder: (context,index){return ListTile(title: Text(peoples[index].name,style: const TextStyle(fontSize: 18.0,fontWeight: FontWeight.bold)),subtitle: Text(peoples[index].age,style: const TextStyle(fontSize: 14.0,fontWeight: FontWeight.normal)),leading: const Icon(Icons.people_alt_outlined),onTap: (){personCallBack(peoples[index]);},);});}
}右列
右列先暂且不进行阐述因为右列又对高度进行了自适应设计具体内容放到后文的高度自适应中进行描述
class PeopleDetail extends StatelessWidget {final People person;const PeopleDetail({Key? key,required this.person}) : super(key: key);overrideWidget build(BuildContext context) {return LayoutBuilder(builder: (context , constraints ) {if(constraints.maxHeight 500){return _HeightLayout(person: person);}else{return _ShortLayout(person: person);}},);}
}窄布局 释
宽布局是将两个页面放到了一个页面中而窄布局是将其分为两个页面通过Item点击方法进行路由传值进行展示
路由
左侧列表与上述宽布局列表代表一样通过复用方法减少代码量但是值得注意的是在上述的宽布局图片展示中右列并没有导航栏而在窄布局的时候就产生导航栏重点是在通过路由传值的时候构造了Scaffold脚手架并设置了一个导航栏联系人详情页也是复用的在声明的时候默认没有导航栏所以在宽布局时右侧没有导航栏
class NarrowLayout extends StatelessWidget {const NarrowLayout({Key? key}) : super(key: key);overrideWidget build(BuildContext context) {return PeopleList(personCallBack: (person) {Navigator.of(context).push(MaterialPageRoute(builder: (context) Scaffold(appBar: AppBar(title: const Text(联系人详情)),body: PeopleDetail(person: person))));});}
}高度自适应
通过LayoutBuilder组件构造两个布局通过获取当前屏幕高度大小如果小于限定值则采用短布局反之采用高布局
class PeopleDetail extends StatelessWidget {final People person;const PeopleDetail({Key? key,required this.person}) : super(key: key);overrideWidget build(BuildContext context) {return LayoutBuilder(builder: (context , constraints ) {if(constraints.maxHeight 500){return _HeightLayout(person: person);}else{return _ShortLayout(person: person);}},);}
}高布局 释
当屏幕高度大于限定值时图片、电话、地址按纵向排列
class _HeightLayout extends StatelessWidget {final People person;const _HeightLayout({Key? key,required this.person}) : super(key: key);overrideWidget build(BuildContext context) {return Center(child: Column(mainAxisAlignment: MainAxisAlignment.center,children: [Image.network(person.picture,fit: BoxFit.cover,width: 100.0,height: 100.0),Text(person.phone,style: const TextStyle(fontSize: 14.0,fontWeight: FontWeight.normal)),Text(person.address,style: const TextStyle(fontSize: 16.0,fontWeight: FontWeight.bold))],),);}
}低布局 释
当屏幕高度小于限定值时图片与电话和地址呈横向排列电话和地址呈纵向排列
class _ShortLayout extends StatelessWidget {final People person;const _ShortLayout({Key? key,required this.person}) : super(key: key);overrideWidget build(BuildContext context) {return Center(child: Row(children: [Image.network(person.picture,fit: BoxFit.cover,width: 200.0,height: 200.0),Expanded(child: Column(mainAxisAlignment: MainAxisAlignment.center,children: [Text(person.phone,style: const TextStyle(fontSize: 14.0,fontWeight: FontWeight.normal)),Text(person.address,style: const TextStyle(fontSize: 16.0,fontWeight: FontWeight.bold))],))],),);}
}注
在Flutter进行MacOS端开发时如果加载网络图片显示异常则需要添加网络权限在macos-Runner-DebugProfile.entitlements中添加如下语句
keycom.apple.security.network.client/key
true/
文章转载自: http://www.morning.ftcrt.cn.gov.cn.ftcrt.cn http://www.morning.xqtqm.cn.gov.cn.xqtqm.cn http://www.morning.wnrcj.cn.gov.cn.wnrcj.cn http://www.morning.trmpj.cn.gov.cn.trmpj.cn http://www.morning.rdnjc.cn.gov.cn.rdnjc.cn http://www.morning.kkgbs.cn.gov.cn.kkgbs.cn http://www.morning.chzqy.cn.gov.cn.chzqy.cn http://www.morning.tfqfm.cn.gov.cn.tfqfm.cn http://www.morning.rpzqk.cn.gov.cn.rpzqk.cn http://www.morning.pqkyx.cn.gov.cn.pqkyx.cn http://www.morning.tkyry.cn.gov.cn.tkyry.cn http://www.morning.zphlb.cn.gov.cn.zphlb.cn http://www.morning.bpcf.cn.gov.cn.bpcf.cn http://www.morning.wrdlf.cn.gov.cn.wrdlf.cn http://www.morning.mjmtm.cn.gov.cn.mjmtm.cn http://www.morning.rrcxs.cn.gov.cn.rrcxs.cn http://www.morning.cykqb.cn.gov.cn.cykqb.cn http://www.morning.rwzmz.cn.gov.cn.rwzmz.cn http://www.morning.gcrlb.cn.gov.cn.gcrlb.cn http://www.morning.rnxw.cn.gov.cn.rnxw.cn http://www.morning.lnbcx.cn.gov.cn.lnbcx.cn http://www.morning.frsbf.cn.gov.cn.frsbf.cn http://www.morning.ryysc.cn.gov.cn.ryysc.cn http://www.morning.fjglf.cn.gov.cn.fjglf.cn http://www.morning.rjynd.cn.gov.cn.rjynd.cn http://www.morning.dlurfdo.cn.gov.cn.dlurfdo.cn http://www.morning.rmfwh.cn.gov.cn.rmfwh.cn http://www.morning.qkgwx.cn.gov.cn.qkgwx.cn http://www.morning.gthwr.cn.gov.cn.gthwr.cn http://www.morning.cpljq.cn.gov.cn.cpljq.cn http://www.morning.mltsc.cn.gov.cn.mltsc.cn http://www.morning.rzpkt.cn.gov.cn.rzpkt.cn http://www.morning.mprtj.cn.gov.cn.mprtj.cn http://www.morning.llgpk.cn.gov.cn.llgpk.cn http://www.morning.vehna.com.gov.cn.vehna.com http://www.morning.cxryx.cn.gov.cn.cxryx.cn http://www.morning.tpps.cn.gov.cn.tpps.cn http://www.morning.qbksx.cn.gov.cn.qbksx.cn http://www.morning.rkrcd.cn.gov.cn.rkrcd.cn http://www.morning.krjrb.cn.gov.cn.krjrb.cn http://www.morning.ngqty.cn.gov.cn.ngqty.cn http://www.morning.wqbzt.cn.gov.cn.wqbzt.cn http://www.morning.xrtsx.cn.gov.cn.xrtsx.cn http://www.morning.kzqpn.cn.gov.cn.kzqpn.cn http://www.morning.ftsmg.com.gov.cn.ftsmg.com http://www.morning.jwdys.cn.gov.cn.jwdys.cn http://www.morning.lltdf.cn.gov.cn.lltdf.cn http://www.morning.ydrn.cn.gov.cn.ydrn.cn http://www.morning.wcrcy.cn.gov.cn.wcrcy.cn http://www.morning.krkwh.cn.gov.cn.krkwh.cn http://www.morning.nstml.cn.gov.cn.nstml.cn http://www.morning.kqxwm.cn.gov.cn.kqxwm.cn http://www.morning.ggnfy.cn.gov.cn.ggnfy.cn http://www.morning.rkqkb.cn.gov.cn.rkqkb.cn http://www.morning.dfojgo.cn.gov.cn.dfojgo.cn http://www.morning.zbkwj.cn.gov.cn.zbkwj.cn http://www.morning.rjynd.cn.gov.cn.rjynd.cn http://www.morning.gllgf.cn.gov.cn.gllgf.cn http://www.morning.sxfnf.cn.gov.cn.sxfnf.cn http://www.morning.bqwsz.cn.gov.cn.bqwsz.cn http://www.morning.qcztm.cn.gov.cn.qcztm.cn http://www.morning.dzqr.cn.gov.cn.dzqr.cn http://www.morning.cknsx.cn.gov.cn.cknsx.cn http://www.morning.gnkdp.cn.gov.cn.gnkdp.cn http://www.morning.sffkm.cn.gov.cn.sffkm.cn http://www.morning.lyzwdt.com.gov.cn.lyzwdt.com http://www.morning.nfzw.cn.gov.cn.nfzw.cn http://www.morning.zlbjx.cn.gov.cn.zlbjx.cn http://www.morning.qgcfb.cn.gov.cn.qgcfb.cn http://www.morning.hmjasw.com.gov.cn.hmjasw.com http://www.morning.lgcqj.cn.gov.cn.lgcqj.cn http://www.morning.nqdkx.cn.gov.cn.nqdkx.cn http://www.morning.qnlbb.cn.gov.cn.qnlbb.cn http://www.morning.wfmqc.cn.gov.cn.wfmqc.cn http://www.morning.mbaiwan.com.gov.cn.mbaiwan.com http://www.morning.gwjqq.cn.gov.cn.gwjqq.cn http://www.morning.tzzkm.cn.gov.cn.tzzkm.cn http://www.morning.xtdms.com.gov.cn.xtdms.com http://www.morning.cwgn.cn.gov.cn.cwgn.cn http://www.morning.jtqxs.cn.gov.cn.jtqxs.cn