码迷,mamicode.com
首页 > 其他好文 > 详细

跳转首页结构并且加载launch插件

时间:2020-01-22 12:34:23      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:轮播   总结   ping   代码   info   const   var   top   fan   

home 代码:

import ‘package:flutter/material.dart‘;
import ‘package:flutter_project/service/service_method.dart‘;
import ‘dart:convert‘;
import ‘swiper_demo.dart‘;
import ‘top_navigator.dart‘;
import ‘adbanner.dart‘;
import ‘callPhone.dart‘;
class HomePage extends StatefulWidget {
HomePage({Key key}) : super(key: key);

@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
 
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(‘百姓生活‘)),
body: Container(
child: FutureBuilder(//网络数据返回能很好的渲染控件
future: getHomePageContent(),//网络返回的数据
builder: (context,snapshot){
if (snapshot.hasData) {//snapshot 相当于返回的数据
var data = json.decode(snapshot.data.toString());

List<Map> swiper = (data[‘data‘][‘slides‘] as List).cast();

List<Map> navlist = (data[‘data‘][‘category‘] as List).cast();

String adPic = data[‘data‘][‘advertesPicture‘][‘PICTURE_ADDRESS‘];

String phoneBgImage = data[‘data‘][‘shopInfo‘][‘leaderImage‘];
 
String phoneNum = data[‘data‘][‘shopInfo‘][‘leaderPhone‘];
return Column(
children: <Widget>[//各个组件
SwiperDiy(swiperDataList: swiper),//轮播
TopNavigator(navigatorList: navlist),//导航引导
AdBanner(adPicture: adPic),//广告
CallPhone(backgroundImage: phoneBgImage,shopPhone:phoneNum,),//打电话
],
);
}else{
return Center(
child: Text(‘加载错误‘),
);
}
},
),
),
);
}
}
 
打电话代码:
import ‘package:flutter/material.dart‘;
import ‘package:url_launcher/url_launcher.dart‘;//打电话插件 也可以打开网页 邮件
class CallPhone extends StatelessWidget {

final String backgroundImage;
final String shopPhone;
const CallPhone({Key key,this.backgroundImage,this.shopPhone}) : super(key: key);

@override
Widget build(BuildContext context) {
return Container(
child: InkWell(//就是oc的手势
onTap: (){
_lanchURL();
},
child: Image.network(backgroundImage),
),
);
}


void _lanchURL() async{//需要真机测试
String url = ‘tel:‘ + shopPhone;
if (await canLaunch(url)) {
await launch(url);
 
}else{
throw ‘请检查是否是真机,URL不能访问‘;
}
}
}
总结:
 

//打电话 发邮件 打开网址 使用 url_launcher插件

Url 格式 https://pub.dev/packages/url_launcher 查看

if(await canlunch(url)){

await lunch(url);

}

 

InkWell(//类似于OC 的手势

onTap:(){

 

}

 

)






跳转首页结构并且加载launch插件

标签:轮播   总结   ping   代码   info   const   var   top   fan   

原文地址:https://www.cnblogs.com/pp-pping/p/12228200.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!