zoukankan      html  css  js  c++  java
  • flutter 刷新和初始化

    代码:

    import 'package:flutter/material.dart';
    import 'package:flutter_screenutil/flutter_screenutil.dart';



    import 'package:flutter_project/model/category_model.dart';
    import 'dart:convert';
    import 'package:flutter_project/service/service_method.dart';

    class LeftCategory extends StatefulWidget {
     
    LeftCategory({Key key}) : super(key: key);

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

    class _LeftCategoryState extends State<LeftCategory> {
    List leftData;
    @override
    void initState() {
    _getCategoryData();
    super.initState();
    }
    @override
    Widget build(BuildContext context) {
    return Container(
    ScreenUtil().setWidth(180),
    child: ListView.builder(
    itemBuilder: (context,index){
    return _leftInkwell(index);
    },
    itemCount: leftData.length,
    )
    );
    }

    Widget _leftInkwell(int leftIndex){
    return InkWell(
    onTap: (){

    },
    child: Container(
    height: ScreenUtil().setHeight(100),
    padding: EdgeInsets.only(top: 20.0,left: 10.0),
    decoration: BoxDecoration(
    border: Border(
    bottom: BorderSide( 1,color: Colors.black12),
    ),
    color: Colors.white
    ),
    child: Text(
    leftData[leftIndex].mallCategoryName,style: TextStyle(fontSize: ScreenUtil().setSp(28)),
    ),
    ),
    );
    }
    //请求分类数据
    void _getCategoryData() {
    getCategoryContent().then((val){
    var data = json.decode(val);
    CategoryListModel categoryListModel = CategoryListModel.fromJson(data);
    setState(() {//刷新整个UI
    leftData = categoryListModel.data;
    });
     
    });
    }

    }
    总结:

    //初始化在

    void initState() {

     

        super.initState();

      }

    相当于OC 的init

    刷新整个UI 是

     setState(() {

       

          });

    相当于OC的reload

  • 相关阅读:
    C# 多线程详解 Part.02(UI 线程和子线程的互动、ProgressBar 的异步调用)
    ubuntu 18.04安装ftp服务器
    ubuntu 18.04设置开机自动挂载移动硬盘
    使用apache commons net进行ftp传输
    Navicat连接MySQL 8出现2059
    Eclipse配置tomcat
    MySQL从.ibd文件中恢复数据
    MySQL建表时添加备注以及查看某一张表的备注信息
    在node.js中使用Set
    Java测试当前应用所占用的内存示例
  • 原文地址:https://www.cnblogs.com/pp-pping/p/12240588.html
Copyright © 2011-2022 走看看