原型Dart页

import  'package:flutter/material.dart' ;

class BoldText extends StatelessWidget {
  @ override //override 的方法 build
  Widget build(BuildContext context) {
    // TODO: implement build
    throw UnimplementedError();
  }

}

  

import 'package:flutter/material.dart';
class testname extends StatelessWidget{
  @override //override 的方法 build
  Widget build(BuildContext context) {
    // TODO: implement build
    //throw UnimplementedError();
    return null;
  }
}

  

import 'package:flutter/material.dart';
class testname extends StatelessWidget{
  @override //override 的方法 build,实现对应的 Widget,返回的 Widget 来替换 null 即可
  Widget build(BuildContext context) {
    // TODO: implement build
    //throw UnimplementedError();
    return null;
  }
}

  静态Widget 

import 'package:flutter/material.dart';

class BoldText extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return _buildWidget();
  }

  Widget _buildWidget() {
    return Text(
      'Hello, world!',
      textDirection: TextDirection.ltr,
      textAlign: TextAlign.center,
      overflow: TextOverflow.ellipsis,
      style: TextStyle(fontWeight: FontWeight.bold),
    );
  }

}

  动态Widget 

import 'package:flutter/material.dart';

class BoldText extends StatelessWidget {
  final String data;
  BoldText(this.data);
  @override
  Widget build(BuildContext context) {
    return _buildWidget();
  }

  Widget _buildWidget() {
    return Text(
      //'Hello, world!',
      data,
      textDirection: TextDirection.ltr,
      textAlign: TextAlign.center,
      overflow: TextOverflow.ellipsis,
      style: TextStyle(fontWeight: FontWeight.bold),
    );
  }

}

  

posted @ 2024-08-28 09:26  飞雪飘鸿  阅读(6)  评论(0编辑  收藏  举报
https://damo.alibaba.com/ https://tianchi.aliyun.com/course?spm=5176.21206777.J_3941670930.5.87dc17c9BZNvLL