91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何使用Flutter開發抖音國際版

發布時間:2020-07-22 17:17:11 來源:億速云 閱讀:605 作者:小豬 欄目:移動開發

這篇文章主要為大家展示了如何使用Flutter開發抖音國際版,內容簡而易懂,希望大家可以學習一下,學習完之后肯定會有收獲的,下面讓小編帶大家一起來看看吧。

如何使用Flutter開發抖音國際版

主要項目架構

詳細說明一下,開發主要在lib文件夾

  • pubspec.yaml是配置插件的位置,如http: ^0.12.0+4,類似依賴組件.
  • common文件夾存放的是重寫的網絡組件,以及圖標組件icons.dart
  • config文件夾存放的api.dart,wei調用的api配置文件
  • models文件存放的實體層
  • screen文件夾存放的頁面view層
  • tabs存放的底部切換文件夾層
  • widgets存放的組件,包含視頻播放組件player.dart以及左右等描述組件

功能介紹

主要的依賴組件,請使用國內鏡像下載,切記切記!!!!

flutter:
  sdk: flutter
 flutter_svg: ^0.17.4

 # The following adds the Cupertino Icons font to your application.
 # Use with the CupertinoIcons class for iOS style icons.
 cupertino_icons: ^0.1.3
 cached_network_image: ^2.2.0
 json_annotation: ^3.0.1
 font_awesome_flutter: ^8.8.1
 http: ^0.12.0+4
 provider: ^4.0.4
 avatar_glow: any
 getflutter: ^1.0.11
 flutter_money_formatter: ^0.8.3
 video_player: ^0.10.8+1
 dio: ^3.0.9
 dio_cookie_manager: ^1.0.0

包含字體文件,主要為抖音自帶的字體文件

import 'package:flutter/widgets.dart';
 
class DouyinIcons {
 DouyinIcons._();
 
 static const _kFontFam = 'DouyinIcons';
 static const IconData chat_bubble =
   const IconData(0xe808, fontFamily: _kFontFam);
 static const IconData create = const IconData(0xe809, fontFamily: _kFontFam);
 static const IconData heart = const IconData(0xe80a, fontFamily: _kFontFam);
 static const IconData home = const IconData(0xe80b, fontFamily: _kFontFam);
 static const IconData messages =
   const IconData(0xe80c, fontFamily: _kFontFam);
 static const IconData profile = const IconData(0xe80d, fontFamily: _kFontFam);
 static const IconData reply = const IconData(0xe80e, fontFamily: _kFontFam);
 static const IconData search = const IconData(0xe80f, fontFamily: _kFontFam);
}

此次采用Flutter開發安卓、IOS等 app確實方便,主要為將tiktok的數據使用http下載下來.

import 'package:http/http.dart' as http;
 
class RequestController {
 static String host = "https://www.tiktok.com/";
 String url = host +
   "/share/item/list?secUid=&id=&type=5&count=30&minCursor=0&maxCursor=0&shareUid=&lang=en&_signature=pKb.ogAgEB9ImoSQahoqJKSm.rAAPox";
 
 Future<String> getCookie() async {
  try {
   var response = await http.get(host + "/share/item/");
   return response.headers["set-cookie"];
  } catch (e) {
   return "error";
  }
 }

Model層

主要為實體層,解析json后綁定數據以及傳遞數據

class Tiktok {
 int statueCode;
 Body body;
 Object errMsg;
 
 Tiktok({this.statueCode, this.body, this.errMsg});
 
 Tiktok.fromJson(Map<String, dynamic> json) {
  statueCode = json['statusCode'];
  body = json['body'] != null &#63; new Body.fromJson(json['body']) : null;
  errMsg = json['errMsg'];
 }
 
 Map<String, dynamic> toJson() {
  final Map<String, dynamic> data = new Map<String, dynamic>();
  data['statusCode'] = this.statueCode;
  if (this.body != null) {
   data['body'] = this.body.toJson();
  }
  data['errMsg'] = this.errMsg;
  return data;
 }
}

視圖層

另外屏幕層主要包含三個,homescreen,trendingscreen,以及顯示videoscreen

import 'package:flutter/material.dart';
import 'package:flutter_app/Screens/trendingScreen.dart';
import 'package:flutter_app/widgets/bottom_toolbar.dart';
 
class Home extends StatefulWidget {
 @override
 HomeState createState() => HomeState();
}
 
class HomeState extends State<Home> {
 int currentIndex = 0;
 PageController pageController;
 
 @override
 Widget build(BuildContext context) {
  return Scaffold(
   body: PageView(
    controller: pageController,
    children: <Widget>[
     Trending(),
    ],
    onPageChanged: (int index) {
     setState(() {
      currentIndex = index;
     });
    },
   ),
   bottomNavigationBar: bottomItems(currentIndex, pageController),
  );
 }
}

Tending層,主要包含讀取抖音的api,將api轉化成實體對象,綁定數據到videoscreen頁面

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:getflutter/getflutter.dart';
import 'package:flutter_app/config/api.dart';
import 'package:flutter_app/models/Tiktok.dart';
import 'package:http/http.dart' as http;
import 'package:flutter_app/Screens/videoScreen.dart';
class Trending extends StatefulWidget {
 _TrendingState createState() => _TrendingState();
}
class _TrendingState extends State<Trending> {
 PageController pageController;
 BuildContext context;
 RequestController api = RequestController();
 List<Widget> videos = [];
 getTrending() async {
  var cookies = await api.getCookie();
  api.setCookie(cookies);
  try {
   var response = await http.get(
    api.url,
    headers: api.headers,
   );
   Tiktok tiktok = Tiktok.fromJson(jsonDecode(response.body));
   tiktok.body.itemListData.forEach(
    (item) {
     setState(() {
      videos.add(VideoItem(data: item));
     });
    },
   );
  } catch (ex) {
   SimpleDialog(
    title: Text('Hot videos list is empty'),
   );
   print(ex);
  }
 }
 @override
 void initState() {
  super.initState();
  getTrending();
 }
 @override
 Widget build(BuildContext context) {
  context = context;
  return PageView(
   scrollDirection: Axis.vertical,
   controller: pageController,
   children: videos.length == 0
     &#63; <Widget>[
       Container(
        color: Colors.black,
        child: Center(
         child: GFLoader(
          type: GFLoaderType.circle,
          loaderColorOne: Colors.blueAccent,
          loaderColorTwo: Colors.white,
          loaderColorThree: Colors.pink,
         ),
        ),
       )
      ]
     : videos,
  );
 }
}

VideoScreen主要為綁定數據. 展示抖音的視頻

import 'package:flutter/material.dart';
import 'package:flutter_app/models/Tiktok.dart';
import 'package:flutter_app/widgets/video_description.dart';
import 'package:flutter_app/widgets/actions_toolbar.dart';
import 'package:flutter_app/widgets/player.dart';
class VideoItem extends StatelessWidget {
 final ItemListData data;
 const VideoItem({@required this.data});
 @override
 Widget build(BuildContext context) {
  return Scaffold(
   body: Stack(
    children: <Widget>[
     DouyinVideoPlayer(
      url: data.itemInfos.video.urls[0],
     ),
     title(),
     VideoDescription(
      description: data.itemInfos.text,
      musicName: data.musicInfos.musicName,
      authorName: data.musicInfos.authorName,
      userName: data.authorInfos.uniqueId,
     ),
     ActionsToolbar(
      comments: data.itemInfos.commentCount.toString(),
      userImg: data.authorInfos.covers[0],
      favorite: data.itemInfos.diggCount,
      coverImg: data.musicInfos.covers[0],
     ),
    ],
   ),
  );
 }
 Widget title() => Align(
    alignment: Alignment.topCenter,
    child: Padding(
     padding: EdgeInsets.symmetric(vertical: 28.0),
     child: Text(
      "Trending | For You",
      style: TextStyle(color: Colors.white, fontSize: 19.0),
     ),
    ),
   );
}

以上就是關于如何使用Flutter開發抖音國際版的內容,如果你們有學習到知識或者技能,可以把它分享出去讓更多的人看到。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

连城县| 潢川县| 奉贤区| 沙湾县| 睢宁县| 上栗县| 格尔木市| 平塘县| 文昌市| 太仓市| 岢岚县| 南江县| 邳州市| 浏阳市| 乌什县| 五河县| 屏南县| 卫辉市| 德保县| 阿瓦提县| 南昌县| 京山县| 正安县| 蓝田县| 健康| 天祝| 长治县| 津南区| 高邑县| 镇巴县| 湘乡市| 平阴县| 本溪市| 肃北| 鸡泽县| 白水县| 黄梅县| 饶河县| 南投市| 东安县| 丁青县|