栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

将屏幕分成两个相等的部分

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

将屏幕分成两个相等的部分

您可以使用- 获得屏幕的大小,然后将其除以2得到前一半。

MediaQuery

@override  Widget build(BuildContext context) {    return MaterialApp(        title: title,//        theme: ThemeData.light().copyWith(//          platform: _platform ?? Theme.of(context).platform,//        ),        home: DefaultTabController( length: 3, child: Scaffold(//     appBar: AppBar(//       title: Text(title),//     ),     body: SafeArea(         child: Column(children: <Widget>[       Container(         color: Colors.greenAccent,         height: MediaQuery.of(context).size.height / 2.2,  // Also Including Tab-bar height.//  child: Chewie(//    controller: _chewieController,//  ),       ),       PreferredSize(         preferredSize: Size.fromHeight(50.0),         child: TabBar(labelColor: Colors.black,tabs: [  Tab(    text: 'One',  ),  Tab(    text: 'Two',  ),  Tab(    text: 'Three',  )], // list of tabs         ),       ),       //TabBarView(children: [ImageList(),])       Expanded(         child: TabBarView(children: [  Container(    color: Colors.deepOrange,    child: Center(child: Text('Tab1')),  ),  Container(    color: Colors.red,    child: Center(child: Text('Tab2')),  ),  Container(    color: Colors.yellowAccent,    child: Center(child: Text('Tab3')),  ) // class name],         ),       ),     ])))));  }

Output:

with AppBar -

height: MediaQuery.of(context).size.height / 2.5,

with

GridView.builder
in -
TabBarView

Expanded(         child: TabBarView(children: [  GridView.builder(    itemBuilder: (context, int) {      return CircleAvatar(        backgroundImage: NetworkImage( 'https://placeimg.com/640/480/any'),      );    },    itemCount: 20,    gridDelegate:        SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 3),    shrinkWrap: true,  ),  Container(    color: Colors.red,    child: Center(child: Text('Tab2')),  ),  Container(    color: Colors.yellowAccent,    child: Center(child: Text('Tab3')),  ) // class name],         ),       ),

to fetch async data - use -

FutureBuilder

    @override  Widget build(BuildContext context) {    return FutureBuilder(      builder: (context,snap){        if(snap.hasData){          return Expanded( child: GridView.count(   shrinkWrap: true,   childAspectRatio: 2,   scrollDirection: Axis.vertical,   crossAxisCount: 2,   children: new List<Widget>.generate(images.length, (index) {     return buildImage(images[index], context, index);   },   ).toList(), ),          );        }        return Center(child: CircularProgressIndicator())      },      future: fetchSubCategoryContentlist(context, 20),    );


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/449418.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号