主要四个页面的基础页面
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import 'package:chat/configs/themes.dart';
|
import 'package:chat/configs/themes.dart';
|
||||||
import 'package:chat/routes/app_router.dart';
|
import 'package:chat/routes/app_router.dart';
|
||||||
|
import 'package:chat/routes/app_routes.dart';
|
||||||
import 'package:chat/services/auth_service.dart';
|
import 'package:chat/services/auth_service.dart';
|
||||||
import 'package:chat/services/tabbar_service.dart';
|
import 'package:chat/services/tabbar_service.dart';
|
||||||
import 'package:chat/services/tim_service.dart';
|
import 'package:chat/services/tim_service.dart';
|
||||||
@@ -26,8 +27,7 @@ class MyApp extends StatelessWidget {
|
|||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
theme: Themes.light,
|
theme: Themes.light,
|
||||||
darkTheme: Themes.dark,
|
darkTheme: Themes.dark,
|
||||||
initialRoute: AppRouter.transitRoute,
|
initialRoute: AppRoutes.transit,
|
||||||
unknownRoute: AppRouter.unknownRoute,
|
|
||||||
defaultTransition: Transition.cupertino,
|
defaultTransition: Transition.cupertino,
|
||||||
getPages: AppRouter.getPages,
|
getPages: AppRouter.getPages,
|
||||||
builder: EasyLoading.init(),
|
builder: EasyLoading.init(),
|
||||||
|
|||||||
@@ -1,45 +1,11 @@
|
|||||||
import 'package:chat/routes/app_routes.dart';
|
import 'package:chat/routes/app_routes.dart';
|
||||||
import 'package:chat/routes/auth_routes.dart';
|
import 'package:chat/routes/auth_routes.dart';
|
||||||
import 'package:chat/views/home/index_page.dart';
|
|
||||||
import 'package:chat/views/public/app_page.dart';
|
|
||||||
import 'package:chat/views/public/scan_page.dart';
|
|
||||||
import 'package:chat/views/public/transit_page.dart';
|
|
||||||
import 'package:chat/views/public/unknown_page.dart';
|
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
class AppRouter {
|
class AppRouter {
|
||||||
// 引导页
|
|
||||||
static const String transitRoute = AppRoutes.transit;
|
|
||||||
// 未知页面,返回主页
|
|
||||||
static final GetPage unknownRoute = GetPage(
|
|
||||||
name: AppRoutes.notfound,
|
|
||||||
page: () => const UnknownPage(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// 路由页面
|
// 路由页面
|
||||||
static final List<GetPage<dynamic>> getPages = [
|
static final List<GetPage<dynamic>> getPages = [
|
||||||
/// 过渡页面
|
AppRoutes.router,
|
||||||
GetPage(
|
|
||||||
name: AppRoutes.transit,
|
|
||||||
page: () => const TransitPage(),
|
|
||||||
),
|
|
||||||
|
|
||||||
GetPage(
|
|
||||||
name: AppRoutes.app,
|
|
||||||
page: () => AppPage(),
|
|
||||||
),
|
|
||||||
|
|
||||||
/// 首页
|
|
||||||
GetPage(
|
|
||||||
name: AppRoutes.home,
|
|
||||||
page: () => const HomePage(),
|
|
||||||
),
|
|
||||||
|
|
||||||
GetPage(
|
|
||||||
name: AppRoutes.scan,
|
|
||||||
page: () => const ScanPage(),
|
|
||||||
),
|
|
||||||
|
|
||||||
AuthRoutes.router,
|
AuthRoutes.router,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,34 @@
|
|||||||
|
import 'package:chat/views/home/index_page.dart';
|
||||||
|
import 'package:chat/views/public/app_page.dart';
|
||||||
|
import 'package:chat/views/public/scan_page.dart';
|
||||||
|
import 'package:chat/views/public/transit_page.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
/// 这里是为了定义别名路由的名称,
|
/// 这里是为了定义别名路由的名称,
|
||||||
/// 具体映射关系,在app_router 的 getPages 中实现
|
/// 具体映射关系,在app_router 的 getPages 中实现
|
||||||
abstract class AppRoutes {
|
abstract class AppRoutes {
|
||||||
/// 过渡页
|
|
||||||
static const String transit = '/transit';
|
|
||||||
|
|
||||||
/// 找不到页面的时候
|
|
||||||
static const String notfound = '/notfound';
|
|
||||||
|
|
||||||
/// 根页面
|
|
||||||
static const String app = '/';
|
static const String app = '/';
|
||||||
|
static const String transit = '/transit';
|
||||||
/// 首页
|
static const String notfound = '/notfound';
|
||||||
static const String home = '/home';
|
static const String home = '/home';
|
||||||
|
|
||||||
static const String scan = '/scan';
|
static const String scan = '/scan';
|
||||||
|
|
||||||
|
static GetPage router = GetPage(
|
||||||
|
name: '/',
|
||||||
|
page: () => AppPage(),
|
||||||
|
children: [
|
||||||
|
GetPage(
|
||||||
|
name: AppRoutes.transit,
|
||||||
|
page: () => const TransitPage(),
|
||||||
|
),
|
||||||
|
GetPage(
|
||||||
|
name: AppRoutes.home,
|
||||||
|
page: () => const HomePage(),
|
||||||
|
),
|
||||||
|
GetPage(
|
||||||
|
name: AppRoutes.scan,
|
||||||
|
page: () => const ScanPage(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
24
lib/routes/contact_routes.dart
Normal file
24
lib/routes/contact_routes.dart
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import 'package:chat/middleware/auth_middleware.dart';
|
||||||
|
import 'package:chat/views/contact/group/index_page.dart';
|
||||||
|
import 'package:chat/views/contact/index/index_page.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
|
abstract class ContactRoutes {
|
||||||
|
/// 身份验证页面
|
||||||
|
static const String index = '/contact';
|
||||||
|
static const String group = '/contact/group';
|
||||||
|
|
||||||
|
static GetPage router = GetPage(
|
||||||
|
name: ContactRoutes.index,
|
||||||
|
middlewares: [
|
||||||
|
EnsureAuthMiddleware(),
|
||||||
|
],
|
||||||
|
page: () => const ContactPage(),
|
||||||
|
children: [
|
||||||
|
GetPage(
|
||||||
|
name: '/group',
|
||||||
|
page: () => const ContactGroupPage(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,11 +1,46 @@
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:get_storage/get_storage.dart';
|
||||||
|
|
||||||
class AuthService extends GetxService {
|
class AuthService extends GetxService {
|
||||||
static AuthService get to => Get.find<AuthService>();
|
static AuthService get to => Get.find<AuthService>();
|
||||||
|
|
||||||
|
final _box = GetStorage();
|
||||||
|
|
||||||
/// 供外部使用的,判断是否登录的状态
|
/// 供外部使用的,判断是否登录的状态
|
||||||
get isUserLogin => isLogin.value;
|
get isUserLogin => isLogin.value;
|
||||||
|
|
||||||
/// 登录状态记录,可监听的,这样ever才能监听到
|
/// 登录状态记录,可监听的,这样ever才能监听到
|
||||||
final RxBool isLogin = false.obs;
|
final RxBool isLogin = false.obs;
|
||||||
|
|
||||||
|
/// 登录的token,供请求时调用,载入内存,是为了每次使用的时候,不需要从磁盘获取
|
||||||
|
late String userToken = '';
|
||||||
|
|
||||||
|
/// 获取存储的token,这个可以做到持久化存储
|
||||||
|
String get _userToken => _box.read('userToken') ?? '';
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onInit() {
|
||||||
|
super.onInit();
|
||||||
|
|
||||||
|
if (_userToken.isNotEmpty) {
|
||||||
|
isLogin.value = true;
|
||||||
|
userToken = _userToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ever(_isLogin, (_) {
|
||||||
|
// if (_ == true) {
|
||||||
|
// Get.offAllNamed(AppRoutes.app);
|
||||||
|
// } else {
|
||||||
|
// Get.offAllNamed(AuthRoutes.index);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> login(String address) async {
|
||||||
|
_box.write('userToken', address);
|
||||||
|
userToken = address;
|
||||||
|
isLogin.value = true;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import 'package:chat/configs/app_colors.dart';
|
import 'package:chat/configs/app_colors.dart';
|
||||||
|
import 'package:chat/routes/app_routes.dart';
|
||||||
|
import 'package:chat/services/auth_service.dart';
|
||||||
import 'package:chat/utils/hd_wallet.dart';
|
import 'package:chat/utils/hd_wallet.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
class AuthImportPage extends StatefulWidget {
|
class AuthImportPage extends StatefulWidget {
|
||||||
const AuthImportPage({Key? key}) : super(key: key);
|
const AuthImportPage({Key? key}) : super(key: key);
|
||||||
@@ -47,7 +50,12 @@ class _AuthImportPageState extends State<AuthImportPage> {
|
|||||||
const Text('支持导入所有遵循BIP标准生成的助记词'),
|
const Text('支持导入所有遵循BIP标准生成的助记词'),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
HDWallet.mnemonicToAddress(_editingController.text);
|
String? address =
|
||||||
|
HDWallet.mnemonicToAddress(_editingController.text);
|
||||||
|
if (address != null) {
|
||||||
|
AuthService.to.login(address);
|
||||||
|
Get.offAllNamed(AppRoutes.app);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
child: const Text('开始导入'),
|
child: const Text('开始导入'),
|
||||||
),
|
),
|
||||||
|
|||||||
15
lib/views/contact/group/index_page.dart
Normal file
15
lib/views/contact/group/index_page.dart
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class ContactGroupPage extends StatefulWidget {
|
||||||
|
const ContactGroupPage({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_ContactGroupPageState createState() => _ContactGroupPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ContactGroupPageState extends State<ContactGroupPage> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container();
|
||||||
|
}
|
||||||
|
}
|
||||||
19
lib/views/contact/index/index_page.dart
Normal file
19
lib/views/contact/index/index_page.dart
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class ContactPage extends StatefulWidget {
|
||||||
|
const ContactPage({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_ContactPageState createState() => _ContactPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ContactPageState extends State<ContactPage> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('通讯录'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,10 @@ class HomePage extends StatefulWidget {
|
|||||||
class _HomePageState extends State<HomePage> {
|
class _HomePageState extends State<HomePage> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container();
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('消息'),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ class MomentsPage extends StatefulWidget {
|
|||||||
class _MomentsPageState extends State<MomentsPage> {
|
class _MomentsPageState extends State<MomentsPage> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container();
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('发现'),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:chat/configs/app_colors.dart';
|
import 'package:chat/configs/app_colors.dart';
|
||||||
import 'package:chat/services/tabbar_service.dart';
|
import 'package:chat/services/tabbar_service.dart';
|
||||||
|
import 'package:chat/views/contact/index/index_page.dart';
|
||||||
import 'package:chat/views/home/index_page.dart';
|
import 'package:chat/views/home/index_page.dart';
|
||||||
import 'package:chat/views/moments/index/index_page.dart';
|
import 'package:chat/views/moments/index/index_page.dart';
|
||||||
import 'package:chat/views/user/index/user_page.dart';
|
import 'package:chat/views/user/index/user_page.dart';
|
||||||
@@ -12,6 +13,7 @@ class AppPage extends StatelessWidget {
|
|||||||
|
|
||||||
final List<IndexedStackChild> _tabBarPageList = [
|
final List<IndexedStackChild> _tabBarPageList = [
|
||||||
IndexedStackChild(child: const HomePage()),
|
IndexedStackChild(child: const HomePage()),
|
||||||
|
IndexedStackChild(child: const ContactPage()),
|
||||||
IndexedStackChild(child: const MomentsPage()),
|
IndexedStackChild(child: const MomentsPage()),
|
||||||
IndexedStackChild(child: const UserPage()),
|
IndexedStackChild(child: const UserPage()),
|
||||||
];
|
];
|
||||||
@@ -19,15 +21,19 @@ class AppPage extends StatelessWidget {
|
|||||||
final List<Map> _tabBarList = [
|
final List<Map> _tabBarList = [
|
||||||
{
|
{
|
||||||
'icon': 'tabBar_03.png',
|
'icon': 'tabBar_03.png',
|
||||||
'label': '首页',
|
'label': '消息',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'icon': 'tabBar_03.png',
|
'icon': 'tabBar_03.png',
|
||||||
'label': '首页',
|
'label': '通讯录',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'icon': 'tabBar_03.png',
|
'icon': 'tabBar_03.png',
|
||||||
'label': '首页',
|
'label': '发现',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'icon': 'tabBar_03.png',
|
||||||
|
'label': '我的',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:get/get.dart';
|
|
||||||
|
|
||||||
class UnknownPage extends StatelessWidget {
|
|
||||||
const UnknownPage({Key? key}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: () {
|
|
||||||
Get.back();
|
|
||||||
},
|
|
||||||
child: const Text('未知的页面'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,6 +10,10 @@ class UserPage extends StatefulWidget {
|
|||||||
class _UserPageState extends State<UserPage> {
|
class _UserPageState extends State<UserPage> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container();
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('我的'),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user