当前位置: 首页 > news >正文

电脑做视频的网站/利尔化学股票股吧

电脑做视频的网站,利尔化学股票股吧,做影片的网站描述,河南商丘网站先上效果图;1.创建工程在Android Studio中,File -> New ->New Flutter Project -> Flutter Application创建完工程后,有三个目录android:Android工程的目录ios:iOS工程的目录lib: Flutter工程的目…

先上效果图;

1.创建工程

在Android Studio中,File -> New ->New Flutter Project -> Flutter Application

创建完工程后,有三个目录

android:Android工程的目录

ios:iOS工程的目录

lib: Flutter工程的目录

其中android、ios下的文件我们都不动,我们只改动lib目录下的dart文件。

2.运行Flutter工程

连接手机

这里不建议用模拟器,因为模拟器在用GPU渲染时可能会出问题,导致图片渲染不出来。

然后按Run 在手机上把程序跑起来。

3.天气API接口申请

用的请求URL如下:

https://free-api.heweather.com/s6/weather/now?location=广州&key=******

4.界面编写

在创建的工程里,有个main.dart里面有一段显示界面的代码如下:

class MyApp extends StatelessWidget {

// This widget is the root of your application.

@override

Widget build(BuildContext context) {

return MaterialApp(

title: 'Flutter Demo',

theme: ThemeData(

// This is the theme of your application.

//

// Try running your application with "flutter run". You'll see the

// application has a blue toolbar. Then, without quitting the app, try

// changing the primarySwatch below to Colors.green and then invoke

// "hot reload" (press "r" in the console where you ran "flutter run",

// or press Run > Flutter Hot Reload in a Flutter IDE). Notice that the

// counter didn't reset back to zero; the application is not restarted.

primarySwatch: Colors.blue,

),

home: MyHomePage(title: 'Flutter Demo Home Page'),

);

}

}

其中home 就是要显示的界面,这里我们要把MyHomePage换成我们自己的。

4.1 创建WeatherWidget

通过 new -> Dart File 在lib目录下创建WeatherWidget

class WeatherWidget extends StatefulWidget{

@override

State createState() {

// TODO: implement createState

return new WeatherState();

}

}

class WeatherState extends State{

@override

Widget build(BuildContext context) {

// TODO: implement build

return Scaffold(

);

}

}

创建完后,在main.dart中将home改为WeatherWidget,如下:

class MyApp extends StatelessWidget {

// This widget is the root of your application.

@override

Widget build(BuildContext context) {

return MaterialApp(

title: 'Flutter Demo',

theme: ThemeData(

primarySwatch: Colors.blue,

),

home: WeatherWidget(),

);

}

4.2 HotReload

在写UI的工程中,我们可以用到Flutter的hot reload的特性,写布局的时候,按ctrl+s或cmd+s就可以在手机上实时看到界面的变化。

这个功能很好用。

4.3添加图片资源

Flutter可以添加不同的资源,例如图片、文本、配置文件、静态数据等。

添加资源时,需要在pubspec.yaml文件中的flutter属性下添加assets,并标明要添加资源的路径,例如,我们要加入指定的图片时,可以这么写:

flutter:

assets:

- assets/my_icon.png

- assets/background.png

如果要添加的资源太多,也可以添加文件夹,例如:

flutter:

assets:

- assets/

在本demo中,要添加一个背景图,我们在工程的根目录下创建images目录,将背景图放在images目录下,然后在pubspec.yaml中添加:

flutter:

# The following line ensures that the Material Icons font is

# included with your application, so that you can use the icons in

# the material Icons class.

uses-material-design: true

assets:

- images/

4.4 写WeatherWidget的UI布局

在Scaffold中添加body的属性,来写UI的布局,如下:

class WeatherState extends State{

@override

Widget build(BuildContext context) {

// TODO: implement build

return Scaffold(

body: new Stack(

fit: StackFit.expand,

children: [

new Image.asset("images/weather_bg.jpg",fit: BoxFit.fitHeight,),

new Column(

mainAxisAlignment: MainAxisAlignment.start,

crossAxisAlignment: CrossAxisAlignment.center,

children: [

new Container(

width: double.infinity,

margin: EdgeInsets.only(top: 40.0),

child: new Text(

"广州市",

textAlign: TextAlign.center,

style: new TextStyle(

color: Colors.white,

fontSize: 30.0,

),

),

),

new Container(

width: double.infinity,

margin: EdgeInsets.only(top: 100.0),

child: new Column(

children: [

new Text(

"20 °",

style: new TextStyle(

color: Colors.white,

fontSize: 80.0

)),

new Text(

"晴",

style: new TextStyle(

color: Colors.white,

fontSize: 45.0

)),

new Text(

"湿度 80%",

style: new TextStyle(

color: Colors.white,

fontSize: 30.0

),

)

],

),

)

],

)

],

),

);

}

}

按ctrl+s,在手机上就可以看到写好的UI,但这时候的数据是写死的,下来看如何通过http获取数据。

5.通过http获取数据

要通过http数据,我们首先要添加http的依赖库,在pubspec.yaml中的dependencies添加如下:

dependencies:

flutter:

sdk: flutter

# The following adds the Cupertino Icons font to your application.

# Use with the CupertinoIcons class for iOS style icons.

cupertino_icons: ^0.1.2

http: ^0.12.0

然后在当前工程目录下运行以下命令行:

$ flutter packages get

或者在Android Stuido 打开pubspec.yaml 文件,点击上面的packages get

这里操作的意义是,拉取http的库。

5.1 创建WeatherData类

通过 new -> Dart File 在lib目录下创建WeatherData

class WeatherData{

String cond; //天气

String tmp; //温度

String hum; //湿度

WeatherData({this.cond, this.tmp, this.hum});

factory WeatherData.fromJson(Map json) {

return WeatherData(

cond: json['HeWeather6'][0]['now']['cond_txt'],

tmp: json['HeWeather6'][0]['now']['tmp']+"°",

hum: "湿度 "+json['HeWeather6'][0]['now']['hum']+"%",

);

}

factory WeatherData.empty() {

return WeatherData(

cond: "",

tmp: "",

hum: "",

);

}

}

5.2 数据获取

class WeatherState extends State{

WeatherData weather = WeatherData.empty();

WeatherState(){

_getWeather();

}

void _getWeather() async{

WeatherData data = await _fetchWeather();

setState((){

weather = data;

});

}

Future _fetchWeather() async{

final response = await http.get('https://free-api.heweather.com/s6/weather/now?location=广州&key=ebb698e9bb6844199e6fd23cbb9a77c5');

if(response.statusCode == 200){

return WeatherData.fromJson(json.decode(response.body));

}else{

return WeatherData.empty();

}

}

@override

Widget build(BuildContext context) {

...

}

}

5.3 将之前写死的数据换成WeatherData

...

child: new Column(

children: [

new Text(

weather?.tmp,

style: new TextStyle(

color: Colors.white,

fontSize: 80.0

)),

new Text(

weather?.cond,

style: new TextStyle(

color: Colors.white,

fontSize: 45.0

)),

new Text(

weather?.hum,

style: new TextStyle(

color: Colors.white,

fontSize: 30.0

),

)

],

),

...

至此这款天气查询的APP实现了一个显示城市、温度、天气、湿度的界面,但是这个界面只有一个显示的功能,没有任何可交互的地方,写下篇文章继续完善查询天气的APP的功能。

http://www.lbrq.cn/news/799129.html

相关文章:

  • html 网站 模板/收录查询
  • 网站建设标准/搜索引擎大全网址
  • 网站录入/关键词完整版
  • 株洲做网站 省心磐石网络/域名查询ip138
  • 解析到网站怎样做/灰色seo关键词排名
  • python 做网站合适吗/全网网站快速排名推广软件
  • 安徽省建设干部学校网站/长春seo关键词排名
  • 网站技术介绍/百度智能云
  • 陕西交通建设集团网站体检/企业建站流程
  • 一个完整网站制作的实例/我要软文网
  • wordpress trac/深圳网站seo公司
  • 南京做信息登记公司网站/怎么去做推广
  • 动画设计师培训/百度seo查询收录查询
  • 济宁做网站多少钱/北京网络推广有哪些公司
  • 个人养老金/百度seo和sem的区别
  • 个人电子邮箱怎么填写格式/seo第三方点击软件
  • 北京建网站价格/搜狗关键词排名此会zjkwlgs
  • 连云港网站关键词优化/最好的搜索引擎排名
  • 网站运作流程/怎么创建一个网址
  • 做外贸要开通哪个网站/专业seo站长工具全面查询网站
  • 国家知识产权局是干什么的/河南网站推广优化排名
  • 用来做视频连接的网站/个人网站设计毕业论文
  • 山东兴华建设集团网站/无锡网站建设优化公司
  • 建设工程资质录入是在那个网站/产品设计公司
  • 学做网站教程/创建个人网站的流程
  • 网站模板绑定域名/最新的国际新闻
  • 天津网站建设信息/微信群发软件
  • c2b做的好的网站/google官方版下载
  • 读经典做临床报名网站/网站seo在线诊断
  • 网站建设平台推广/网站快速收录软件
  • 系统性学习数据结构-第一讲-算法复杂度
  • 【MySQL】增删改查操作 —— CRUD
  • Docker 的网络模式
  • 初始C语言---第四讲(数组)
  • p5.js 3D模型(model)入门指南
  • 什么是数据集成?和数据融合有什么区别?