forked from lxm_flutter/FlutterUnit
初步优化项目结构
This commit is contained in:
55
lib/components/permanent/code/code_widget.dart
Normal file
55
lib/components/permanent/code/code_widget.dart
Normal file
@@ -0,0 +1,55 @@
|
||||
|
||||
/// create by 张风捷特烈 on 2020-04-15
|
||||
/// contact me by email 1981462002@qq.com
|
||||
/// 说明:
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'language/dart_languge.dart';
|
||||
|
||||
import 'high_light_code.dart';
|
||||
import 'highlighter_style.dart';
|
||||
|
||||
class CodeWidget extends StatelessWidget {
|
||||
CodeWidget({Key? key, required this.code,required this.style, this.fontSize = 13,this.fontFamily})
|
||||
: super(key: key);
|
||||
|
||||
final String code;
|
||||
final HighlighterStyle style;
|
||||
final double fontSize;
|
||||
final String? fontFamily;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget body;
|
||||
if (code == null) {
|
||||
return Container();
|
||||
} else {
|
||||
Widget _codeWidget;
|
||||
try {
|
||||
_codeWidget = RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(fontSize: fontSize,fontFamily: fontFamily),
|
||||
children: <TextSpan>[
|
||||
CodeHighlighter(
|
||||
style: style,
|
||||
language: const DartLanguage()
|
||||
).format(code)],
|
||||
),
|
||||
);
|
||||
} catch (err) {
|
||||
print(err);
|
||||
_codeWidget = Text(code);
|
||||
}
|
||||
body = SingleChildScrollView(
|
||||
child: Container(
|
||||
child: _codeWidget,
|
||||
padding: EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: style.backgroundColor ?? Color(0xffF6F8FA),
|
||||
borderRadius: BorderRadius.all(Radius.circular(5.0))),
|
||||
),
|
||||
);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user