**Flutter匠人心得:《实用Flutter》源码库探秘**
warning:
这篇文章距离上次修改已过187天,其中的内容可能已经有所变动。
import 'package:flutter/material.dart';
class SourceCodeView extends StatelessWidget {
final String sourceCode;
const SourceCodeView({Key key, this.sourceCode}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(16.0),
decoration: BoxDecoration(
color: Colors.grey.shade900,
borderRadius: BorderRadius.circular(4.0),
),
child: SelectableText(
sourceCode,
style: TextStyle(
fontFamily: 'monospace',
fontSize: 12.0,
color: Colors.lime.shade500,
),
),
);
}
}
这段代码定义了一个SourceCodeView
的无状态小部件,它接收源代码作为字符串并展示在一个有着灰色背景和圆角边框的容器中。使用SelectableText
小部件来显示源代码,并且可以选中和复制文本。字体设置为等宽字体,以保持源代码的格式。通过这个小部件,开发者可以在Flutter应用中方便地展示和高亮源代码。
评论已关闭