Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: 增加background参数; 优化循环体 #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions .idea/libraries/Dart_SDK.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 20 additions & 20 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,42 @@ packages:
name: async
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.4.2"
version: "2.5.0-nullsafety.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.0"
version: "2.1.0-nullsafety.1"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.0"
version: "1.1.0-nullsafety.3"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.3"
version: "1.2.0-nullsafety.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.1"
version: "1.1.0-nullsafety.1"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.14.13"
version: "1.15.0-nullsafety.3"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -56,7 +56,7 @@ packages:
name: fake_async
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
version: "1.2.0-nullsafety.1"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -73,28 +73,28 @@ packages:
path: ".."
relative: true
source: path
version: "2.8.0"
version: "2.8.2"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.8"
version: "0.12.10-nullsafety.1"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.8"
version: "1.3.0-nullsafety.3"
path:
dependency: transitive
description:
name: path
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.7.0"
version: "1.8.0-nullsafety.1"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -106,56 +106,56 @@ packages:
name: source_span
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.7.0"
version: "1.8.0-nullsafety.2"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.9.5"
version: "1.10.0-nullsafety.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.0"
version: "2.1.0-nullsafety.1"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.5"
version: "1.1.0-nullsafety.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
version: "1.2.0-nullsafety.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.17"
version: "0.2.19-nullsafety.2"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0"
version: "1.3.0-nullsafety.3"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.8"
version: "2.1.0-nullsafety.3"
sdks:
dart: ">=2.9.0-14.0.dev <3.0.0"
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.20.0 <2.0.0"
75 changes: 31 additions & 44 deletions lib/bg/weather_bg.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ class WeatherBg extends StatefulWidget {
final WeatherType weatherType;
final double width;
final double height;
final Widget background;

WeatherBg(
{Key key, this.weatherType, @required this.width, @required this.height})
: super(key: key);
WeatherBg({
Key key,
this.weatherType,
@required this.width,
@required this.height,
this.background,
}) : super(key: key);

@override
_WeatherBgState createState() => _WeatherBgState();
Expand Down Expand Up @@ -46,12 +51,14 @@ class _WeatherBgState extends State<WeatherBg>
weatherType: _oldWeatherType,
width: widget.width,
height: widget.height,
background: widget.background,
);
}
var currentBgWidget = WeatherItemBg(
weatherType: widget.weatherType,
width: widget.width,
height: widget.height,
background: widget.background,
);
if (oldBgWidget == null) {
oldBgWidget = currentBgWidget;
Expand Down Expand Up @@ -86,41 +93,15 @@ class WeatherItemBg extends StatelessWidget {
final WeatherType weatherType;
final width;
final height;
final Widget background;

WeatherItemBg({Key key, this.weatherType, this.width, this.height})
: super(key: key);

/// 构建晴晚背景效果
Widget _buildNightStarBg() {
if (weatherType == WeatherType.sunnyNight) {
return WeatherNightStarBg(
weatherType: weatherType,
);
}
return Container();
}

/// 构建雷暴效果
Widget _buildThunderBg() {
if (weatherType == WeatherType.thunder) {
return WeatherThunderBg(
weatherType: weatherType,
);
}
return Container();
}

/// 构建雨雪背景效果
Widget _buildRainSnowBg() {
if (WeatherUtil.isSnowRain(weatherType)) {
return WeatherRainSnowBg(
weatherType: weatherType,
viewWidth: width,
viewHeight: height,
);
}
return Container();
}
WeatherItemBg({
Key key,
this.weatherType,
this.width,
this.height,
this.background,
}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand All @@ -130,13 +111,19 @@ class WeatherItemBg extends StatelessWidget {
child: ClipRect(
child: Stack(
children: [
WeatherColorBg(weatherType: weatherType),
WeatherCloudBg(
weatherType: weatherType,
),
_buildRainSnowBg(),
_buildThunderBg(),
_buildNightStarBg(),
background ?? WeatherColorBg(weatherType: weatherType),
WeatherCloudBg(weatherType: weatherType),
if (WeatherUtil.isSnowRain(weatherType))
WeatherRainSnowBg(
weatherType: weatherType,
viewWidth: width,
viewHeight: height,
),
if (weatherType == WeatherType.thunder)
WeatherThunderBg(weatherType: weatherType),
// 构建晴晚背景效果
if (weatherType == WeatherType.sunnyNight)
WeatherNightStarBg(weatherType: weatherType),
],
),
),
Expand Down
Loading