Flutter實戰視頻-移動電商-36.FlutterToast插件使用

36.FlutterToast插件使用

 

https://github.com/PonnamKarthik/FlutterToastgit

fluttertoast: ^3.0.1

 

category_page.dart頁面添加引用github

import 'package:fluttertoast/fluttertoast.dart';

 

 

 

 

 

 

小類跳轉到所有,沒有數據的問題

 

 

本節課代碼

provide/child_category.dartjson

import 'package:flutter/material.dart';
import '../model/category.dart';

class ChildCategory with ChangeNotifier{
 List<BxMallSubDto> childCategoryList=[];
 int childIndex=0;//子類高亮索引
 String categoryId='4';//大類ID 白酒的id 默認爲4
 String subId='';//小類ID
 int page=1;
 String noMoreText='';//顯示沒有數據的文字
  //大類切換邏輯
  getChildCategory(List<BxMallSubDto> list,String id){
    page=1;
    noMoreText='';
    childIndex=0;//每次點擊大類,小類的索引都要清空掉
    categoryId=id;
    BxMallSubDto all=BxMallSubDto();
    all.mallSubId="";
    all.mallCategoryId="00";
    all.comments="null";
    all.mallSubName='所有';
    childCategoryList=[all];
    //childCategoryList=list;
    childCategoryList.addAll(list);
    notifyListeners();//監聽
  }
  //改變子類索引,indexs是從哪裏來的呢?從咱們具體的類中進行傳遞
  changeChildIndex(index,String id){
    page=1;
    noMoreText='';
    childIndex=index;//把傳遞過來的index賦值給咱們的childIndex
    subId=id;
    notifyListeners();//通知
  }
  //增長Page的方法
  addPage(){
    page++;
    //notifyListeners();//這裏不須要通知,由於咱們只是page+1了並無頁面數據上的變化
  }
  //改變noMore的方法
  changeNoMore(String text){
    noMoreText=text;
    notifyListeners();//通知
  }
}

 

 

category_page.dart主要代碼ide

void _getMoreList() {
     Provide.value<ChildCategory>(context).addPage();
      var data={
        'categoryId':Provide.value<ChildCategory>(context).categoryId,//大類ID
        'categorySubId':Provide.value<ChildCategory>(context).subId,
        'page':Provide.value<ChildCategory>(context).page
      };
      request('getMallGoods',formData: data).then((val){
        var data=json.decode(val.toString());
        CategoryGoodsListModel goodsList=CategoryGoodsListModel.fromJson(data);//這樣就從json'轉換成了model類
        if(goodsList.data==null){
          Fluttertoast.showToast(
            msg:'已經到底了',
            toastLength: Toast.LENGTH_SHORT,//適應短的提示
            gravity: ToastGravity.CENTER,//中間提示
            backgroundColor: Colors.pink,
            textColor: Colors.white,
            fontSize: 16.0
          );
          Provide.value<ChildCategory>(context).changeNoMore('沒有更多了');
        }else{
          Provide.value<CategoryGoodsListProvide>(context).getMoreList(goodsList.data);
        }
        
      });
    }
相關文章
相關標籤/搜索