2022-06-29 19:02:01 +00:00
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:app_links/app_links.dart';
|
2021-09-29 23:57:09 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2021-11-11 09:05:48 +00:00
|
|
|
import 'package:pikapika/basic/config/Version.dart';
|
|
|
|
import 'package:pikapika/screens/components/Badge.dart';
|
2022-06-29 19:02:01 +00:00
|
|
|
import 'package:uri_to_file/uri_to_file.dart';
|
2021-09-29 23:57:09 +00:00
|
|
|
|
|
|
|
import 'CategoriesScreen.dart';
|
2022-06-29 19:02:01 +00:00
|
|
|
import 'PkzArchiveScreen.dart';
|
2021-09-29 23:57:09 +00:00
|
|
|
import 'SpaceScreen.dart';
|
|
|
|
|
|
|
|
// MAIN UI 底部导航栏
|
|
|
|
class AppScreen extends StatefulWidget {
|
|
|
|
const AppScreen({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<AppScreen> createState() => _AppScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AppScreenState extends State<AppScreen> {
|
2022-06-29 19:02:01 +00:00
|
|
|
late StreamSubscription<Uri> _linkSubscription;
|
|
|
|
|
2021-11-11 09:05:48 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
versionEvent.subscribe(_onVersion);
|
2022-06-29 19:02:01 +00:00
|
|
|
final appLinks = AppLinks();
|
|
|
|
// todo 不必要cancel 随机监听就好了, APP关闭时销毁, 考虑移动到APP里
|
|
|
|
_linkSubscription = appLinks.uriLinkStream.listen((uri) async {
|
|
|
|
RegExp regExp = RegExp(r"^.*\.pkz$");
|
|
|
|
final matches = regExp.allMatches(uri.toString());
|
|
|
|
if (matches.isNotEmpty) {
|
|
|
|
File file = await toFile(uri.toString());
|
|
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
builder: (BuildContext context) =>
|
|
|
|
PkzArchiveScreen(pkzPath: file.path),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-11-11 09:05:48 +00:00
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
versionEvent.unsubscribe(_onVersion);
|
2022-06-29 19:02:01 +00:00
|
|
|
_linkSubscription.cancel();
|
2021-11-11 09:05:48 +00:00
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _onVersion(dynamic a) {
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
|
2021-11-29 03:26:30 +00:00
|
|
|
static const List<Widget> _widgetOptions = <Widget>[
|
2022-03-17 03:31:25 +00:00
|
|
|
CategoriesScreen(),
|
|
|
|
SpaceScreen(),
|
2021-09-29 23:57:09 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
late int _selectedIndex = 0;
|
|
|
|
|
|
|
|
void _onItemTapped(int index) {
|
|
|
|
setState(() {
|
2021-11-29 03:26:30 +00:00
|
|
|
_selectedIndex = index;
|
2021-09-29 23:57:09 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2021-11-29 03:26:30 +00:00
|
|
|
body: IndexedStack(
|
|
|
|
index: _selectedIndex,
|
2021-09-29 23:57:09 +00:00
|
|
|
children: _widgetOptions,
|
|
|
|
),
|
|
|
|
bottomNavigationBar: BottomNavigationBar(
|
2021-11-11 09:05:48 +00:00
|
|
|
items: <BottomNavigationBarItem>[
|
2022-03-19 04:12:27 +00:00
|
|
|
const BottomNavigationBarItem(
|
2021-11-11 09:05:48 +00:00
|
|
|
icon: Icon(Icons.public),
|
|
|
|
label: '浏览',
|
|
|
|
),
|
|
|
|
BottomNavigationBarItem(
|
|
|
|
icon: Badged(
|
2022-03-19 04:12:27 +00:00
|
|
|
child: const Icon(Icons.face),
|
2021-11-11 09:05:48 +00:00
|
|
|
badge: latestVersion() == null ? null : "1",
|
|
|
|
),
|
|
|
|
label: '我的',
|
|
|
|
),
|
|
|
|
],
|
2021-09-29 23:57:09 +00:00
|
|
|
currentIndex: _selectedIndex,
|
|
|
|
iconSize: 20,
|
|
|
|
selectedFontSize: 12,
|
|
|
|
unselectedFontSize: 12,
|
|
|
|
onTap: _onItemTapped,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|