写点什么

Flutter40(1)

用户头像
Android架构
关注
发布于: 21 小时前

'摇一摇': 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;


}


}


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:


《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
浏览器打开:qq.cn.hn/FTe 免费领取
复制代码


blocks[bolockIndex].length),


);


}


);


}


}


common_web_page.dart


import 'package:flutter/cupertino.dart';


import 'package:flutter/material.dart';


import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';


import 'package:flutterapp2/constants/Constants.dart';


class CommonWebPage extends StatefulWidget {


final String title;


final String url;


//构造函数


CommonWebPage({Key key, this.title, this.url})


: assert(title != null),


assert(url != null),


super(key: key);


@override


_CommonWebPageState createState() => _CommonWebPageState();


}


class _CommonWebPageState extends State<CommonWebPage> {


bool isLoading = true;


//展示 webview


FlutterWebviewPlugin _flutterWebviewPlugin = FlutterWebviewPlugin();


@override


void initState() {


// TODO: implement initState


super.initState();


//监听 url 变化


_flutterWebviewPlugin.onStateChanged.listen((state) {


if(state.type == WebViewState.finishLoad){


if (!mounted) return;


setState(() {


isLoading = false;


});


}else if(state.type == WebViewState.startLoad){


if (mounted) {


setState(() {


isLoading = true;


});


}


}

用户头像

Android架构

关注

还未添加个人签名 2021.10.31 加入

还未添加个人简介

评论

发布
暂无评论
Flutter40(1)