Skip to content

Commit e5d004f

Browse files
committed
加入自动更新功能
1 parent dc3774f commit e5d004f

16 files changed

+506
-65
lines changed

android/app/src/main/AndroidManifest.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,35 @@
3636
<category android:name="android.intent.category.LAUNCHER"/>
3737
</intent-filter>
3838
</activity>
39+
40+
<!-- Flutterdownloader configuration -->
41+
<provider
42+
android:name="vn.hunghd.flutterdownloader.DownloadedFileProvider"
43+
android:authorities="${applicationId}.flutter_downloader.provider"
44+
android:exported="false"
45+
android:grantUriPermissions="true">
46+
<meta-data
47+
android:name="android.support.FILE_PROVIDER_PATHS"
48+
android:resource="@xml/provider_paths"/>
49+
</provider>
50+
51+
<provider
52+
android:name="androidx.work.impl.WorkManagerInitializer"
53+
android:authorities="${applicationId}.workmanager-init"
54+
android:enabled="false"
55+
android:exported="false" />
56+
57+
<provider
58+
android:name="vn.hunghd.flutterdownloader.FlutterDownloaderInitializer"
59+
android:authorities="${applicationId}.flutter-downloader-init"
60+
android:exported="false">
61+
<meta-data
62+
android:name="vn.hunghd.flutterdownloader.MAX_CONCURRENT_TASKS"
63+
android:value="5" />
64+
</provider>
65+
66+
<!-- Flutterdownloader configuration end -->
67+
3968
</application>
4069
</manifest>
4170

lib/components/expansionTile.dart

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
7+
const Duration _kExpand = Duration(milliseconds: 200);
8+
9+
/// A single-line [ListTile] with a trailing button that expands or collapses
10+
/// the tile to reveal or hide the [children].
11+
///
12+
/// This widget is typically used with [ListView] to create an
13+
/// "expand / collapse" list entry. When used with scrolling widgets like
14+
/// [ListView], a unique [PageStorageKey] must be specified to enable the
15+
/// [ExpansionTile] to save and restore its expanded state when it is scrolled
16+
/// in and out of view.
17+
///
18+
/// See also:
19+
///
20+
/// * [ListTile], useful for creating expansion tile [children] when the
21+
/// expansion tile represents a sublist.
22+
/// * The "Expand/collapse" section of
23+
/// <https://material.io/guidelines/components/lists-controls.html>.
24+
class ExpansionTile extends StatefulWidget {
25+
/// Creates a single-line [ListTile] with a trailing button that expands or collapses
26+
/// the tile to reveal or hide the [children]. The [initiallyExpanded] property must
27+
/// be non-null.
28+
const ExpansionTile({
29+
Key key,
30+
this.headerBackgroundColor,
31+
this.leading,
32+
@required this.title,
33+
this.backgroundColor,
34+
this.iconColor,
35+
this.onExpansionChanged,
36+
this.children = const <Widget>[],
37+
this.trailing,
38+
this.initiallyExpanded = false,
39+
}) : assert(initiallyExpanded != null),
40+
super(key: key);
41+
42+
/// A widget to display before the title.
43+
///
44+
/// Typically a [CircleAvatar] widget.
45+
final Widget leading;
46+
47+
/// The primary content of the list item.
48+
///
49+
/// Typically a [Text] widget.
50+
final Widget title;
51+
52+
/// Called when the tile expands or collapses.
53+
///
54+
/// When the tile starts expanding, this function is called with the value
55+
/// true. When the tile starts collapsing, this function is called with
56+
/// the value false.
57+
final ValueChanged<bool> onExpansionChanged;
58+
59+
/// The widgets that are displayed when the tile expands.
60+
///
61+
/// Typically [ListTile] widgets.
62+
final List<Widget> children;
63+
64+
/// The color to display behind the sublist when expanded.
65+
final Color backgroundColor;
66+
67+
/// The color to display the background of the header.
68+
final Color headerBackgroundColor;
69+
70+
/// The color to display the icon of the header.
71+
final Color iconColor;
72+
73+
/// A widget to display instead of a rotating arrow icon.
74+
final Widget trailing;
75+
76+
/// Specifies if the list tile is initially expanded (true) or collapsed (false, the default).
77+
final bool initiallyExpanded;
78+
79+
@override
80+
_ExpansionTileState createState() => _ExpansionTileState();
81+
}
82+
83+
class _ExpansionTileState extends State<ExpansionTile>
84+
with SingleTickerProviderStateMixin {
85+
static final Animatable<double> _easeOutTween =
86+
CurveTween(curve: Curves.easeOut);
87+
static final Animatable<double> _easeInTween =
88+
CurveTween(curve: Curves.easeIn);
89+
static final Animatable<double> _halfTween =
90+
Tween<double>(begin: 0.0, end: 0.5);
91+
92+
final ColorTween _borderColorTween = ColorTween();
93+
final ColorTween _headerColorTween = ColorTween();
94+
final ColorTween _iconColorTween = ColorTween();
95+
final ColorTween _backgroundColorTween = ColorTween();
96+
97+
AnimationController _controller;
98+
Animation<double> _iconTurns;
99+
Animation<double> _heightFactor;
100+
Animation<Color> _borderColor;
101+
Animation<Color> _headerColor;
102+
Animation<Color> _iconColor;
103+
Animation<Color> _backgroundColor;
104+
105+
bool _isExpanded = false;
106+
107+
@override
108+
void initState() {
109+
super.initState();
110+
_controller = AnimationController(duration: _kExpand, vsync: this);
111+
_heightFactor = _controller.drive(_easeInTween);
112+
_iconTurns = _controller.drive(_halfTween.chain(_easeInTween));
113+
_borderColor = _controller.drive(_borderColorTween.chain(_easeOutTween));
114+
_headerColor = _controller.drive(_headerColorTween.chain(_easeInTween));
115+
_iconColor = _controller.drive(_iconColorTween.chain(_easeInTween));
116+
_backgroundColor =
117+
_controller.drive(_backgroundColorTween.chain(_easeOutTween));
118+
119+
_isExpanded =
120+
PageStorage.of(context)?.readState(context) ?? widget.initiallyExpanded;
121+
if (_isExpanded) _controller.value = 1.0;
122+
}
123+
124+
@override
125+
void dispose() {
126+
_controller.dispose();
127+
super.dispose();
128+
}
129+
130+
void _handleTap() {
131+
setState(() {
132+
_isExpanded = !_isExpanded;
133+
if (_isExpanded) {
134+
_controller.forward();
135+
} else {
136+
_controller.reverse().then<void>((void value) {
137+
if (!mounted) return;
138+
setState(() {
139+
// Rebuild without widget.children.
140+
});
141+
});
142+
}
143+
PageStorage.of(context)?.writeState(context, _isExpanded);
144+
});
145+
if (widget.onExpansionChanged != null)
146+
widget.onExpansionChanged(_isExpanded);
147+
}
148+
149+
Widget _buildChildren(BuildContext context, Widget child) {
150+
final Color borderSideColor = _borderColor.value ?? Colors.transparent;
151+
final Color titleColor = _headerColor.value;
152+
153+
return Container(
154+
decoration: BoxDecoration(
155+
color: _backgroundColor.value ?? Colors.transparent,
156+
border: Border(
157+
top: BorderSide(color: borderSideColor),
158+
bottom: BorderSide(color: borderSideColor),
159+
)),
160+
child: Column(
161+
mainAxisSize: MainAxisSize.min,
162+
children: <Widget>[
163+
IconTheme.merge(
164+
data: IconThemeData(color: _iconColor.value),
165+
child: Container(
166+
color: widget.headerBackgroundColor ?? Colors.black,
167+
child: ListTile(
168+
onTap: _handleTap,
169+
leading: widget.leading,
170+
title: DefaultTextStyle(
171+
style: Theme.of(context)
172+
.textTheme
173+
.subhead
174+
.copyWith(color: titleColor),
175+
child: widget.title,
176+
),
177+
trailing: widget.trailing ??
178+
RotationTransition(
179+
turns: _iconTurns,
180+
child: Icon(
181+
Icons.expand_more,
182+
color: widget.iconColor ?? Colors.grey,
183+
),
184+
),
185+
),
186+
),
187+
),
188+
ClipRect(
189+
child: Align(
190+
heightFactor: _heightFactor.value,
191+
child: child,
192+
),
193+
),
194+
],
195+
),
196+
);
197+
}
198+
199+
@override
200+
void didChangeDependencies() {
201+
final ThemeData theme = Theme.of(context);
202+
_borderColorTween..end = theme.dividerColor;
203+
_headerColorTween
204+
..begin = theme.textTheme.subhead.color
205+
..end = theme.accentColor;
206+
_iconColorTween
207+
..begin = theme.unselectedWidgetColor
208+
..end = theme.accentColor;
209+
_backgroundColorTween..end = widget.backgroundColor;
210+
super.didChangeDependencies();
211+
}
212+
213+
@override
214+
Widget build(BuildContext context) {
215+
final bool closed = !_isExpanded && _controller.isDismissed;
216+
return AnimatedBuilder(
217+
animation: _controller.view,
218+
builder: _buildChildren,
219+
child: closed ? null : Column(children: widget.children),
220+
);
221+
}
222+
}

lib/components/headerComp.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class Index extends StatelessWidget {
88
return Text(
99
this.text,
1010
style: TextStyle(
11-
color: Theme.of(context).primaryTextTheme.title.color
12-
),
11+
//color: Theme.of(context).primaryTextTheme.title.color
12+
),
1313
);
1414
}
1515
}

lib/components/markdownComp.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import 'package:flutter/material.dart';
22
import 'package:flutter_markdown/flutter_markdown.dart' as md;
33
import 'package:efox_flutter/utils/syntaxHighlighter.dart'
44
show DartSyntaxHighlighter;
5+
import 'package:efox_flutter/config/color.dart' show materialColor;
6+
import 'package:efox_flutter/config/theme.dart' show AppTheme;
7+
import 'package:efox_flutter/store/index.dart' show model;
58

69
class Index extends StatelessWidget {
710
final String data;

lib/components/webviewComp.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Index extends StatelessWidget {
2121
url: this.url,
2222
enableAppScheme: false,
2323
appBar: AppBar(
24+
elevation: 0,
2425
title: Text(
2526
this.title,
2627
),

lib/components/widgetComp.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,16 @@ class IndexState extends State<Index> {
8484
this.model = model;
8585
return Scaffold(
8686
appBar: AppBar(
87-
title: Text(this.title),
87+
//title: Text(this.title),
8888
elevation: 0,
89+
backgroundColor: Color(AppTheme.secondColor),
8990
actions: this.getActions(
9091
context,
9192
),
9293
leading: IconButton(
9394
icon: Icon(Icons.arrow_back),
94-
color: Theme.of(context).primaryTextTheme.title.color,
95+
//color: Theme.of(context).primaryTextTheme.title.color,
96+
color: Color(AppTheme.blackColor),
9597
onPressed: () => Navigator.pop(context),
9698
),
9799
),
@@ -130,7 +132,8 @@ class IndexState extends State<Index> {
130132
getActions(context) {
131133
return [
132134
IconButton(
133-
color: Theme.of(context).primaryTextTheme.title.color,
135+
//color: Theme.of(context).primaryTextTheme.title.color,
136+
color: Color(AppTheme.blackColor),
134137
icon: Icon(
135138
Icons.insert_link,
136139
),
@@ -151,7 +154,8 @@ class IndexState extends State<Index> {
151154
), */
152155
IconButton(
153156
icon: Icon(Icons.share),
154-
color: Theme.of(context).primaryTextTheme.title.color,
157+
//color: Theme.of(context).primaryTextTheme.title.color,
158+
color: Color(AppTheme.blackColor),
155159
onPressed: () {
156160
final String msg =
157161
this.model.config.state.env.githubAssetOrigin + this.mdUrl;

lib/config/color.dart

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
21
Map materialColor = {
3-
'yellow':0xFFFFEB3B,
4-
'orange':0xFFFF9800,
5-
'amber':0xFFFFC107,
6-
'lime':0xFFCDDC39,
7-
'lightGreen':0xFF8BC34A,
8-
'red':0xFFF44336,
9-
'deepOrange':0xFFFF5722,
10-
'blue':0xFF2196F3,
11-
'pink':0xFFE91E63
2+
'red': 0xFFF44336,
3+
'pink': 0xFFE91E63,
4+
'purple': 0xFF9C27B0,
5+
'deepPurple': 0xFF673AB7,
6+
'indigo': 0xFF3F51B5,
7+
//
8+
9+
'blue': 0xFF2196F3,
10+
'lightBlue': 0xFF03A9F4,
11+
'cyan': 0xFF00BCD4,
12+
'teal': 0xFF009688,
13+
'green': 0xFF4CAF50,
14+
//
15+
'lightGreen': 0xFF8BC34A,
16+
'lime': 0xFFCDDC39,
17+
'yellow': 0xFFFFEB3B,
18+
'amber': 0xFFFFC107,
19+
'orange': 0xFFFF9800,
20+
//
21+
'deepOrange': 0xFFFF5722,
22+
'brown': 0xFF795548,
23+
'grey': 0xFF9E9E9E,
24+
'blueGrey': 0xFF607D8B,
25+
'black': 0xFF222222,
1226
};

0 commit comments

Comments
 (0)