Flutter項(xiàng)目

一、 輪播圖

  1. 添加依賴:Add this to your package's pubspec.yaml file:
dependencies:
  flutter_swiper: ^1.1.6
  1. 獲取資源
$ flutter pub get
  1. 使用的時(shí)候?qū)?/li>
import 'package:flutter_swiper/flutter_swiper.dart';
  1. demo
class _KnowledgePage extends State<KnowledgePage> {
 List<String> imgs = [
    "http://ww4.sinaimg.cn/large/7a8aed7bjw1exp4h479xfj20hs0qoq6t.jpg",
    "http://ww1.sinaimg.cn/large/0065oQSqly1frepozc5taj30qp0yg7aq.jpg",
    "http://ww1.sinaimg.cn/large/0065oQSqly1frept5di16j30p010g0z9.jpg"
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        height: 180,
        child: Swiper(
          autoplay: true,
          pagination: SwiperPagination(),//添加indicator
          itemCount: imgs.length,
          itemBuilder: (BuildContext context, int index) {
            return Image.network(
              imgs[index],
              fit: BoxFit.cover,
            );
          },
        ),
      ),
    );
  }
}

二忆绰、 延遲

Future.delayed(Duration(seconds: 3), () {//操作});

三、 Flutter導(dǎo)航頁之intro_slider

  • intro_slider是Flutter一個(gè)應(yīng)用啟動(dòng)歡迎頁面的插件输拇,可以幫助你介紹你的應(yīng)用,以顯示你的應(yīng)用程序的主要功能烈和, 你可以更改圖像侨拦,按鈕,文本樣式稚茅,顏色等别惦,創(chuàng)建介紹屏幕從未如此簡單快捷弧可。
  • 目前官方版本是intro_slider ^2.3.1
  • intro_slider插件地址

①添加依賴intro_slider: ^2.3.1
②使用IntroSlider

class SplashScreen extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _SplashScreen();
  }
}

class _SplashScreen extends State<SplashScreen> {
  List<Slide> slides = new List();
 //完成方法
  void onDonePress() {
    Navigator.of(context).pushAndRemoveUntil(
        new MaterialPageRoute(builder: (context) => MainScreen()),
        (route) => route == null);
  }

//跳過方法
  void onSkipPress() {
    Navigator.of(context).pushAndRemoveUntil(
        new MaterialPageRoute(builder: (context) => MainScreen()),
        (route) => route == null);
  }

  @override
  Widget build(BuildContext context) {
    return IntroSlider(
      slides: slides,
      onDonePress: this.onDonePress,
      onSkipPress: this.onSkipPress,
      nameSkipBtn: "跳過",
      nameNextBtn: "下一頁",
      nameDoneBtn: "進(jìn)入",
    );
  }
}

③獲取slider集合

slides.add(
      new Slide(
        title: "Flutter",
        description:
            "Flutter是谷歌的移動(dòng)UI框架谷暮,可以快速在iOS和Android上構(gòu)建高質(zhì)量的原生用戶界面蒿往。 Flutter可以與現(xiàn)有的代碼一起工作。在全世界湿弦,F(xiàn)lutter正在被越來越多的開發(fā)者和組織使用瓤漏,并且Flutter是完全免費(fèi)、開源的颊埃。",
        styleDescription: TextStyle(
            color: Colors.white, fontSize: 20.0),
        marginDescription:
            EdgeInsets.only(left: 20.0, right: 20.0, top: 20.0, bottom: 70.0),
        colorBegin: Color(0xffFFDAB9),
        colorEnd: Color(0xff40E0D0),
        directionColorBegin: Alignment.topLeft,
        directionColorEnd: Alignment.bottomRight,
      ),
    );
    slides.add(
      new Slide(
        title: "Wanandroid",
        description:
            "這是一款使用Flutter寫的WanAndroid客戶端應(yīng)用蔬充,在Android和IOS都完美運(yùn)行,可以用來入門Flutter,簡單明了班利,適合初學(xué)者,項(xiàng)目完全開源饥漫,如果本項(xiàng)目確實(shí)能夠幫助到你學(xué)習(xí)Flutter,謝謝start罗标,有問題請(qǐng)?zhí)峤籌ssues,我會(huì)及時(shí)回復(fù)庸队。",
        styleDescription: TextStyle(
            color: Colors.white, fontSize: 20.0, fontFamily: 'Raleway'),
        marginDescription:
            EdgeInsets.only(left: 20.0, right: 20.0, top: 20.0, bottom: 70.0),
        colorBegin: Color(0xffFFFACD),
        colorEnd: Color(0xffFF6347),
        directionColorBegin: Alignment.topLeft,
        directionColorEnd: Alignment.bottomRight,
      ),
    );
    slides.add(
      new Slide(
        title: "Welcome",
        description: "贈(zèng)人玫瑰,手有余香闯割;\n分享技術(shù)彻消,傳遞快樂。",
        styleDescription: TextStyle(
            color: Colors.white, fontSize: 20.0, fontFamily: 'Raleway'),
        marginDescription:
            EdgeInsets.only(left: 20.0, right: 20.0, top: 20.0, bottom: 70.0),
        colorBegin: Color(0xffFFA500),
        colorEnd: Color(0xff7FFFD4),
        directionColorBegin: Alignment.topLeft,
        directionColorEnd: Alignment.bottomRight,
      ),
    );

四宙拉、獲取到數(shù)據(jù)前紅色報(bào)錯(cuò)界面處理

1证膨、思路

state生命周期setState -- 在網(wǎng)絡(luò)數(shù)據(jù)得到之前添加一個(gè)loading框即可

2、解決:

class LoadingUtil {
  static Widget loading() {
    return Center(
      child: CircularProgressIndicator(
        strokeWidth: 2.0,
      ),
    );
  }
}

五鼓黔、Flutter中webview

1. 添加依賴

flutter_webview_plugin: ^0.3.4

2.使用

class _WebViewScreen extends State<WebViewScreen> {
  @override
  Widget build(BuildContext context) {
    var title = widget.title;
    var url = widget.url;
    return WebviewScaffold(
      url: url,
      appBar: AppBar(
        title: title,
      ),
    );
  }
}

六央勒、列表刷新

1. 添加依賴

pull_to_refresh: ^1.5.4

2.獲取刷新控制器

initialRefresh: false首次是否刷新

RefreshController _refreshController =
      new RefreshController(initialRefresh: false);

3.獲取或者刷新文章列表

記得關(guān)閉刷新控件

void getArticleList() async {
    _page = 0;
    await ApiService().getSquareList(_page).then((value) {
      var data = json.decode(value.toString());
      _refreshController.refreshCompleted();
      setState(() {
        ArticleModel _articleModel = ArticleModel.fromJson(data);
        _articles = _articleModel.data.datas;
      });
    });
  }

4. 獲取更多文章列表

記得關(guān)閉加載更多控件

getMoreSquareList() async {
    _page++;
    await ApiService().getSquareList(_page).then((value) {
      var data = json.decode(value.toString());
      _refreshController.loadComplete();
      setState(() {
        ArticleModel _articleModel = ArticleModel.fromJson(data);
        _articles.addAll(_articleModel.data.datas);
      });
    });
  }

5.構(gòu)建頁面的時(shí)候添加刷新控件

@override
  Widget build(BuildContext context) {
    if (_articles.length <= 0) return LoadingUtil.loading();
    return SmartRefresher(
      enablePullDown: true,
      enablePullUp: true,
      header: MaterialClassicHeader(),
      footer: RefreshFooter(),
      controller: _refreshController,
      onRefresh: getArticleList,
      onLoading: getMoreSquareList,
      child: ListView.builder(
        itemBuilder: itemView,
        itemCount: _articles.length,
        controller: _scrollController,
      ),
    );
  }

6.自定義腳布局

/// 自定義 FooterView
class RefreshFooter extends CustomFooter {
  @override
  double get height => 40;

  @override
  FooterBuilder get builder => (context, mode) {
        Widget body;
        if (mode == LoadStatus.idle) {
          body = Text("上拉加載更多~");
        } else if (mode == LoadStatus.loading) {
          body = Wrap(
            spacing: 6,
            children: <Widget>[
              CupertinoActivityIndicator(),
              Text("加載中..."),
            ],
          );
        } else if (mode == LoadStatus.failed) {
          body = Text("加載失敗,點(diǎn)擊重試~");
        } else {
          body = Text("沒有更多數(shù)據(jù)了~");
        }
        return Container(
          height: 40,
          child: Center(child: body),
        );
      };
}

最后:總結(jié)

  1. Flutter簡介澳化、環(huán)境搭建崔步、Dart語法基礎(chǔ)
  2. FLutter項(xiàng)目框架搭建:側(cè)滑、底部導(dǎo)航
  3. Flutter項(xiàng)目:首頁輪播+列表實(shí)現(xiàn)多布局缎谷,刷新
  4. Flutter項(xiàng)目廣場:列表展示網(wǎng)絡(luò)數(shù)據(jù)井濒、復(fù)雜布局
  5. Flutter項(xiàng)目首頁:列表、多布局
  6. FLutter項(xiàng)目公眾號(hào):網(wǎng)絡(luò)獲取公眾號(hào)數(shù)據(jù)列林,使用TabBar與TabBarView實(shí)現(xiàn)頁面切換瑞你、Widget復(fù)用
  7. Flutter項(xiàng)目體系:完成體系功能,webview展示詳情頁希痴、流式布局
  8. Flutter項(xiàng)目導(dǎo)航頁(實(shí)現(xiàn)頁面跳轉(zhuǎn)者甲、傳值、回傳值)砌创、歡迎頁實(shí)現(xiàn)
  9. 紅屏處理
  10. 倒計(jì)時(shí)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末虏缸,一起剝皮案震驚了整個(gè)濱河市鲫懒,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌刽辙,老刑警劉巖窥岩,帶你破解...
    沈念sama閱讀 222,104評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異宰缤,居然都是意外死亡颂翼,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,816評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門慨灭,熙熙樓的掌柜王于貴愁眉苦臉地迎上來疚鲤,“玉大人,你說我怎么就攤上這事缘挑〖” “怎么了?”我有些...
    開封第一講書人閱讀 168,697評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵语淘,是天一觀的道長诲宇。 經(jīng)常有香客問我,道長惶翻,這世上最難降的妖魔是什么姑蓝? 我笑而不...
    開封第一講書人閱讀 59,836評(píng)論 1 298
  • 正文 為了忘掉前任,我火速辦了婚禮吕粗,結(jié)果婚禮上纺荧,老公的妹妹穿的比我還像新娘。我一直安慰自己颅筋,他們只是感情好宙暇,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,851評(píng)論 6 397
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著议泵,像睡著了一般占贫。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上先口,一...
    開封第一講書人閱讀 52,441評(píng)論 1 310
  • 那天型奥,我揣著相機(jī)與錄音,去河邊找鬼碉京。 笑死厢汹,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的谐宙。 我是一名探鬼主播烫葬,決...
    沈念sama閱讀 40,992評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢(mèng)啊……” “哼卧惜!你這毒婦竟也來了厘灼?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,899評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤咽瓷,失蹤者是張志新(化名)和其女友劉穎设凹,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體茅姜,經(jīng)...
    沈念sama閱讀 46,457評(píng)論 1 318
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡闪朱,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,529評(píng)論 3 341
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了钻洒。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片奋姿。...
    茶點(diǎn)故事閱讀 40,664評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖素标,靈堂內(nèi)的尸體忽然破棺而出称诗,到底是詐尸還是另有隱情,我是刑警寧澤头遭,帶...
    沈念sama閱讀 36,346評(píng)論 5 350
  • 正文 年R本政府宣布寓免,位于F島的核電站,受9級(jí)特大地震影響计维,放射性物質(zhì)發(fā)生泄漏袜香。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,025評(píng)論 3 334
  • 文/蒙蒙 一鲫惶、第九天 我趴在偏房一處隱蔽的房頂上張望蜈首。 院中可真熱鬧,春花似錦欠母、人聲如沸欢策。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,511評(píng)論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽猬腰。三九已至,卻和暖如春猜敢,著一層夾襖步出監(jiān)牢的瞬間姑荷,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,611評(píng)論 1 272
  • 我被黑心中介騙來泰國打工缩擂, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留鼠冕,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 49,081評(píng)論 3 377
  • 正文 我出身青樓胯盯,卻偏偏與公主長得像懈费,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子博脑,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,675評(píng)論 2 359