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

  • 相关阅读:
    LINUX 环境变量总结
    make的自动变量和预定义变量
    函数调用约定和堆栈
    如何查看linux命令源代码
    shell脚本中特定符合变量的含义
    【转载】Redhat5和6 YUM源配置的区别
    用路径分析法来编写测试用例
    linux ip 设置
    Mysql 的存储引擎,myisam和innodb的区别。
    一些编译php时的configure 参数
  • 原文地址:https://www.cnblogs.com/pp-pping/p/12240588.html
Copyright © 2011-2022 走看看