-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,002 additions
and
478 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,7 @@ | ||
# dart_star_pattern | ||
# Star Patterns in Dart | ||
|
||
A new Flutter project. | ||
My senior given this task. | ||
|
||
## Getting Started | ||
## Resources | ||
|
||
This project is a starting point for a Flutter application. | ||
|
||
A few resources to get you started if this is your first Flutter project: | ||
|
||
- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab) | ||
- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook) | ||
|
||
For help getting started with Flutter, view our | ||
[online documentation](https://flutter.dev/docs), which offers tutorials, | ||
samples, guidance on mobile development, and a full API reference. | ||
- [Widget with codeview by X-Wei](https://github.com/X-Wei/widget_with_codeview) - I modified some code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
|
||
import 'syntax_highlighter.dart'; | ||
|
||
class SourceCodeView extends StatefulWidget { | ||
final String filePath; | ||
|
||
const SourceCodeView({ | ||
Key key, | ||
@required this.filePath, | ||
}) : super(key: key); | ||
|
||
@override | ||
_SourceCodeViewState createState() { | ||
return _SourceCodeViewState(); | ||
} | ||
} | ||
|
||
class _SourceCodeViewState extends State<SourceCodeView> { | ||
double _textScaleFactor = 1.0; | ||
Widget _getCodeView(String codeContent, BuildContext context) { | ||
final SyntaxHighlighterStyle style = | ||
Theme.of(context).brightness == Brightness.dark | ||
? SyntaxHighlighterStyle.darkThemeStyle() | ||
: SyntaxHighlighterStyle.lightThemeStyle(); | ||
return Container( | ||
constraints: BoxConstraints.expand(), | ||
child: SingleChildScrollView( | ||
padding: EdgeInsets.only(left: 6, top: 8), | ||
child: SelectableText.rich( | ||
TextSpan( | ||
style: TextStyle(fontFamily: 'monospace', fontSize: 12.0) | ||
.apply(fontSizeFactor: this._textScaleFactor), | ||
children: <TextSpan>[ | ||
DartSyntaxHighlighter(style).format(codeContent) | ||
], | ||
), | ||
style: DefaultTextStyle.of(context) | ||
.style | ||
.apply(fontSizeFactor: this._textScaleFactor), | ||
), | ||
), | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return FutureBuilder( | ||
future: DefaultAssetBundle.of(context).loadString(widget.filePath) ?? | ||
'Error loading source code from $this.filePath', | ||
builder: (BuildContext context, AsyncSnapshot<String> snapshot) { | ||
if (snapshot.hasData) { | ||
return Scaffold( | ||
body: Padding( | ||
padding: EdgeInsets.all(4.0), | ||
child: _getCodeView(snapshot.data, context), | ||
), | ||
); | ||
} else { | ||
return Center(child: CircularProgressIndicator()); | ||
} | ||
}, | ||
); | ||
} | ||
} |
Oops, something went wrong.