Flutter41,2021新一波程序员跳槽季

@override

Widget build(BuildContext context) {

return Scaffold(

appBar: AppBar(

title: Text(‘摇一摇’),

),

body: Center(

child: Column(

mainAxisAlignment: MainAxisAlignment.center,

children: [

Image.asset(

‘assets/images/shake.png’,

width:120.0,

height: 120.0,

),

SizedBox(

height: 10.0,

),

Text(isShaked?‘活动结束’:‘摇一摇获取礼品’),

],

),

),

//底层的导航栏,2个导航栏

bottomNavigationBar: BottomNavigationBar(

//2个条目

items: [

BottomNavigationBarItem(icon: Icon(Icons.folder), title: Text(‘礼品’)),

BottomNavigationBarItem(

icon: Icon(Icons.assignment), title: Text(‘资讯’))

],

currentIndex: _curentIndex,

onTap: (index) {

if (!mounted) return;

setState(() {

_curentIndex = index;

});

},

),

);

}

}

discovery_page.dart

import ‘package:barcode_scan/barcode_scan.dart’;

import ‘package:flutter/material.dart’;

import ‘package:flutterapp2/pages/shake_page.dart’;

import ‘common_web_page.dart’;

/**

  • 主界面find

*/

class DiscoveryPage extends StatefulWidget {

@override

_DiscoveryPageState createState() => _DiscoveryPageState();

}

class _DiscoveryPageState extends State {

List<Map<String, IconData>> blocks = [

{

‘开源众包’: Icons.pageview,

‘开源软件’: Icons.speaker_notes_off,

‘码云推荐’: Icons.screen_share,

‘代码骗贷’: Icons.assignment,

},

{

‘扫一扫’: Icons.camera_alt,

‘摇一摇’: Icons.camera,

},

{

‘码云封面人物’: Icons.person,

‘线下活动’: Icons.android,

}

];

void _handleItemClick(String title) {

switch (title) {

case ‘开源众包’:

_navToWebPage(title, ‘https://zb.oschina.net/’);

break;

case ‘扫一扫’:

scan();

break;

case ‘摇一摇’:

Navigator.of(context)

.push(MaterialPageRoute(builder: (context) => ShakePage()));

break;

}

}

Future scan() async {

String barcode = await BarcodeScanner.scan();

print(“Debug barcode==” + barcode);

}

void _navToWebPage(String title, String url) {

if (title != null && url != null) {

Navigator.of(context).push(MaterialPageRoute(

builder: (context) => CommonWebPage(

title: title,

url: url,

)));

}

}

@override

Widget build(BuildContext context) {

return ListView.builder(

itemCount: blocks.length,

itemBuilder: (context, bolockIndex) {

return Container(

margin: const EdgeInsets.symmetric(vertical: 10.0),

//线条边框设置

decoration: BoxDecoration(

border: Border(

top: BorderSide(

width: 1.0,

color: Color(0xffaaaaaa),

),

bottom: BorderSide(

width: 1.0,

color: Color(0xffaaaaaa),

),

),

),

//listview嵌套,自带分割线。3个子模块

child: ListView.separated(

physics: NeverScrollableScrollPhysics(),//滑动冲突

shrinkWrap: true,//显示完全

itemBuilder: (context, mapIndex) {

//InkWell有点击效果

return InkWell(

//点击事件

onTap: (){

_handleItemClick(

blocks[bolockIndex].keys.elementAt(mapIndex));

},

//listview单个条目的布局

child: Container(

height: 60.0,

child: ListTile(

leading: Icon(

blocks[bolockIndex].values.elementAt(mapIndex)),

title:

Text(blocks[bolockIndex].keys.elementAt(mapIndex)),

trailing: Icon(Icons.arrow_forward_ios),

),

),

);

},

//子listview的分隔线

separatorBuilder: (context, mapIndex) {

return Divider(

height: 2.0,

color: Color(0xffff0000),

);

},

/
/子listview的数量是各个block的

itemCount: blocks[bolockIndex].length),

);

}

);

}

}
ling: Icon(Icons.arrow_forward_ios),

),

),

);

},

//子listview的分隔线

separatorBuilder: (context, mapIndex) {

return Divider(

height: 2.0,

color: Color(0xffff0000),

);

},

/[外链图片转存中…(img-d8HZiYLk-1642654597227)]
/子listview的数量是各个block的

itemCount: blocks[bolockIndex].length),

);

}

);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值