原型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), ); } }