Flutter 2进阶(七):BaseWidget的封装

Flutter 2进阶(七):BaseWidget的封装,第1张

为了方便后面开发,简单了封装一下 BaseWidget  ,将一些重复内容可以放进去。

BaseWidget:

import 'package:flutter/material.dart';

abstract class BaseWidget extends StatefulWidget {
  @override
  BaseWidgetState createState() => getState();

  BaseWidgetState getState();
}

abstract class BaseWidgetState extends State {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {}
  
  @override
  void dispose() {
    super.dispose();
  }
}

使用:

import 'package:flutter/material.dart';
import 'package:flutter_blbl/model/base/stateful_widget_base.dart';
import 'package:flutter_blbl/model/video_model.dart';

class VideoDetailPage extends BaseWidget {
  final VideoModel videoModel;

  VideoDetailPage({this.videoModel});

  @override
  _VideoDetailPageState createState() => _VideoDetailPageState();

  @override
  BaseWidgetState getState() {
    return _VideoDetailPageState();
  }
}

class _VideoDetailPageState extends BaseWidgetState {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Container(
        child: Text('视频详情页-vid:' + widget.videoModel.vid.toString()),
      ),
    );
  }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/996512.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存