Pārlūkot izejas kodu

添加引导页显示

tags/0.0.2+8
杨华轩 pirms 4 gadiem
vecāks
revīzija
410bd41a78
3 mainītis faili ar 103 papildinājumiem un 19 dzēšanām
  1. +58
    -18
      lib/pages/guide_page/guide_page.dart
  2. +42
    -1
      lib/pages/launch_page/launch_page.dart
  3. +3
    -0
      lib/utils/contants.dart

+ 58
- 18
lib/pages/guide_page/guide_page.dart Parādīt failu

@@ -1,12 +1,16 @@
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:zhiying_base_widget/models/app_config_model.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:zhiying_base_widget/widgets/home/home_quick_entry/cached_network_image_util.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

class GuidePage extends StatefulWidget {
final AppConfigGuideModel model;
final List<Uint8List> imageDatas;

const GuidePage(this.model, {Key key}) : super(key: key);
const GuidePage(this.model, this.imageDatas, {Key key}) : super(key: key);

@override
State<StatefulWidget> createState() => _GuidePageState();
@@ -15,23 +19,59 @@ class GuidePage extends StatefulWidget {
class _GuidePageState extends State<GuidePage> {
@override
Widget build(BuildContext context) {
return Swiper(
itemBuilder: (BuildContext context, int index) {
return new Image.network(
widget.model?.images[index],
fit: BoxFit.fill,
);
},
loop: false,
itemCount: widget.model?.images?.length ?? 0,
pagination: new SwiperPagination(),
control: new SwiperControl(),
onIndexChanged: (index) {
Logger.debug(index);
},
onTap: (index) {
Logger.debug('点击');
},
bool isShowIndicator = (widget.model?.isShowIndicator ?? '0') == '1';
List<int> list = List.generate(widget.imageDatas?.length, (index) => index);
return WillPopScope(
onWillPop: () async => false,// 拦截Android返回键
child: Material(
child: Swiper(
itemBuilder: (BuildContext context, int index) {
// return CachedNetworkImage(imageUrl: widget.model.images[index],fit: BoxFit.cover,);
return Image.memory(widget.imageDatas[index], fit: BoxFit.cover,);
},

loop: false,
itemCount: widget.imageDatas?.length ?? 0,
pagination: isShowIndicator ? SwiperCustomPagination(builder: (BuildContext context, SwiperPluginConfig config) {
return Align(
alignment: Alignment(0.0, 1),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: list.map((index) {
var borderRadius;
if (index == 0) {
borderRadius = BorderRadius.only(topLeft: Radius.circular(2), bottomLeft: Radius.circular(2));
}
if (index == list.length - 1) {
borderRadius = BorderRadius.only(topRight: Radius.circular(2), bottomRight: Radius.circular(2));
}

if (index == config.activeIndex) {
borderRadius = BorderRadius.all(Radius.circular(2));
}

return SafeArea(
child: Container(
margin: EdgeInsets.only(bottom: 40),
height: 4,
width: 25,
decoration: BoxDecoration(borderRadius: borderRadius, color: index == config.activeIndex ? HexColor.fromHex('#FF4242') : HexColor.fromHex('#FFFFFF')),
),
);
}).toList() ,
),
);
}) : null,
onIndexChanged: (index) {
},
onTap: (index) {
if (index == widget.model.images.length - 1) {
Navigator.pop(context, true);
}
},
),
),
);
}
}

+ 42
- 1
lib/pages/launch_page/launch_page.dart Parādīt failu

@@ -1,9 +1,18 @@
import 'dart:typed_data';

import 'package:connectivity/connectivity.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:zhiying_base_widget/models/app_config_model.dart';
import 'package:zhiying_base_widget/pages/guide_page/guide_page.dart';
import 'package:zhiying_base_widget/pages/home_page/home_page.dart';
import 'package:zhiying_comm/util/application.dart';
import 'package:zhiying_comm/zhiying_comm.dart';
import 'package:dio/dio.dart';
import 'package:zhiying_base_widget/utils/contants.dart';
import 'package:zhiying_comm/util/shared_prefe_util.dart';
import 'package:package_info/package_info.dart';

// 启动页,页面初始化等操作~跟原生启动页保持一致,防止白屏问题
class LaunchPage extends StatefulWidget {
@@ -24,7 +33,18 @@ class _LaunchPageState extends State<LaunchPage> {
// I am connected to a wifi network.
Logger.debug('ConnectivityResult.wifi');
print('ConnectivityResult.wifi');
Application.init().then((_) {
Application.init().then((_) async {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
String versionNumber =
await SharedPreferencesUtil.getStringValue(Constants.versionNumber);
String currentVersionCode =
packageInfo.buildNumber?.toString() ?? '';
if (versionNumber == null || versionNumber == '' || versionNumber != currentVersionCode) {
await _showGuideImage();
SharedPreferencesUtil.setStringValue(Constants.versionNumber, currentVersionCode);
}


if (widget.builder != null) {
Navigator.of(context)
.pushReplacement(CupertinoPageRoute(builder: widget.builder));
@@ -44,6 +64,27 @@ class _LaunchPageState extends State<LaunchPage> {
super.initState();
}

Future _showGuideImage() async {
// 引导页
AppConfigGuideModel guide = AppConfigModel.getConfig()?.guideImage;
if (guide != null && guide.images.length > 0) {
Dio dio = Dio();

List<Uint8List> guideImages = List();
for (int i = 0; i < guide.images.length; i++) {
Response response = await dio.get(guide.images[i], options: Options(responseType: ResponseType.bytes));
if (response.statusCode == 200) {
Uint8List data = Uint8List.fromList(response.data);
guideImages.add(data);
}
}

await Navigator.of(context).push(
CupertinoPageRoute(builder: (context) => GuidePage(guide, guideImages)));
}

}

@override
Widget build(BuildContext context) {
return Image.asset(


+ 3
- 0
lib/utils/contants.dart Parādīt failu

@@ -25,4 +25,7 @@ class Constants {
static String isShowNotiPermission = "isShowNotiPermission";
//==============================弹窗===================================end

//==============================版本号,控制引导页显示===================================
static String versionNumber = "versionNumber";

}

Notiek ielāde…
Atcelt
Saglabāt