Commit 5f368f69 authored by skeyboy's avatar skeyboy

修复切换tabbar导致用户状态丢失的问题

parent 04afb450
......@@ -9,7 +9,7 @@ class AssistantPage extends GetView<AssistantController> {
// 主视图
Widget _buildView() {
return GridWidget();
return _AssistantPage();
}
@override
......@@ -29,3 +29,20 @@ class AssistantPage extends GetView<AssistantController> {
);
}
}
class _AssistantPage extends StatefulWidget {
const _AssistantPage({Key? key}) : super(key: key);
@override
State<_AssistantPage> createState() => _AssistantPageState();
}
class _AssistantPageState extends State<_AssistantPage> with AutomaticKeepAliveClientMixin{
@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;
@override
Widget build(BuildContext context) {
return GridWidget();
}
}
......@@ -9,7 +9,7 @@ class CreationPage extends GetView<CreationController> {
// 主视图
Widget _buildView() {
return GridWidget();
return const _InnerCreationPage();
// return Obx(() => Center(
// child: InkWell(
// onTap: () => controller.increment(),
......@@ -40,3 +40,23 @@ class CreationPage extends GetView<CreationController> {
);
}
}
class _InnerCreationPage extends StatefulWidget {
const _InnerCreationPage({Key? key}) : super(key: key);
@override
State<_InnerCreationPage> createState() => _InnerCreationPageState();
}
class _InnerCreationPageState extends State<_InnerCreationPage>
with AutomaticKeepAliveClientMixin {
/// 防止每次切换之后自动滑动到顶部
@override
bool get wantKeepAlive => true;
@override
Widget build(BuildContext context) {
return GridWidget();
}
}
......@@ -23,201 +23,224 @@ class HomePage extends GetView<HomeController> {
@override
Widget build(BuildContext context) {
final cc = Get.put(HomeController());
return WillPopScope(
onWillPop: () async {
return false;
},
child: Obx(() => Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: Color.fromARGB(0, 0, 0, 0),
appBar: transparentAppBar(
actions: [
RotationTransition(
turns: controller.animation,
child: IconButton(
tooltip: '重置',
icon: const Icon(
Icons.settings_backup_restore_sharp,
color: AppColors.primaryElementText,
),
onPressed: () {
controller.reset();
},
),
child: const _HomePage());
}
}
class _HomePage extends StatefulWidget {
const _HomePage({Key? key}) : super(key: key);
@override
State<_HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<_HomePage>
with AutomaticKeepAliveClientMixin {
@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;
HomeController get controller => Get.find();
@override
Widget build(BuildContext context) {
final cc = Get.put(HomeController());
return Obx(() =>
Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: Color.fromARGB(0, 0, 0, 0),
appBar: transparentAppBar(
actions: [
RotationTransition(
turns: controller.animation,
child: IconButton(
tooltip: '重置',
icon: const Icon(
Icons.settings_backup_restore_sharp,
color: AppColors.primaryElementText,
),
IconButton(
tooltip: '设置',
icon: const Icon(
Icons.settings,
color: AppColors.primaryElementText,
),
onPressed: () {
controller.share();
},
)
],
title: RichText(
textAlign: TextAlign.center,
text: TextSpan(children: [
TextSpan(
text: "${controller.state.page}",
style: const TextStyle(
color: AppColors.primaryElementText,
fontFamily: 'Montserrat',
fontSize: 18,
fontWeight: FontWeight.w600,
)),
TextSpan(
text: "${controller.state.messageList.length}",
style: const TextStyle(fontSize: 0)),
])),
leading: GradientButton(
increaseHeightBy: -5,
// increaseWidthBy: 5,
elevation: 0,
shadowColor: Colors.black,
gradient: const LinearGradient(
colors: [
Color.fromARGB(255, 223, 188, 134),
Color.fromARGB(255, 244, 218, 129),
Color.fromARGB(255, 248, 228, 127)
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
child: Row(children: const [
Icon(
Icons.add_circle,
color: Colors.black,
size: 30,
),
SizedBox(
width: 10,
),
Text("订阅",
style: TextStyle(
color: Color.fromARGB(255, 95, 54, 0),
fontSize: 16)),
]),
callback: () => controller.virtualPay()),
onPressed: () {
controller.reset();
},
),
),
body: SizedBox(
width: double.infinity,
height: double.infinity,
// color: Color.fromARGB(0, 255, 255, 0),
// color: Colors.red,
// Color.argb(255, 29, 33, 60)
// color: Color.fromARGB(0, 29, 33, 60),
// color: Color.fromARGB(255, 26, 27, 46),
child: Chat.DashChat(
// readOnly: cc.state.readOnly,
inputOptions: Chat.InputOptions(
onLongPressStart: cc.onLongPressStart,
onLongPressEnd: cc.onLongPressEnd,
textInputAction: TextInputAction.send,
inputDisabled: cc.state.isLoading,
sendOnEnter: true,
leading: [
// GradientCircularProgressIndicator(
// radius: 100,
// ),
// GradientRotation(1.0,),
// GradientButton(
// child: Icon(Icons.text_fields_sharp), callback: () {}),
/*Android语音转换文字有问题暂时屏蔽掉*/
(Platform.isAndroid ? Container(): Container(
margin: const EdgeInsets.only(right: 10),
child: InkWell(
borderRadius: BorderRadius.circular(100),
onTap: cc.changeInput,
child: Container(
decoration: const BoxDecoration(
shape: BoxShape.circle,
border: GradientBoxBorder(
gradient: LinearGradient(colors: [
Color(0xFFbe6afb),
// Color(0xFF9c67f6),
Color(0xFF7965f8)
]),
width: 2,
),
),
padding: const EdgeInsets.all(10),
child: Icon(
!cc.state.isInputText
? Icons.keyboard
: Icons.keyboard_voice,
),
)))
// padding: EdgeInsets.all(10),
// margin: EdgeInsets.only(right: 10),
// child: Icon(Icons.text_fields_sharp),
// decoration: const BoxDecoration(
// shape: BoxShape.circle,
// border: GradientBoxBorder(
// gradient: LinearGradient(
// colors: [Colors.pink, Colors.orange]),
// width: 2,
// ),
// ),
),
// Container(
// padding: EdgeInsets.all(10),
// margin: EdgeInsets.only(right: 10),
// decoration: const BoxDecoration(
// // color: Colors.red,
// borderRadius: BorderRadius.all(Radius.circular(54)),
// border: Border(
// top: BorderSide(
// width: 2.0,
// color: Colors.red,
// ),
// bottom: BorderSide(
// width: 2.0,
// color: Colors.red,
// ),
// right: BorderSide(
// width: 2.0,
// color: Colors.red,
// ),
// left: BorderSide(
// width: 2.0,
// color: Colors.red,
// ),
// ),
// ),
// child: Icon(Icons.text_fields_sharp),
// )
],
// showTraillingBeforeSend: true,
isTextInput: cc.state.isInputText,
inputTextStyle: TextStyle(color: Colors.white),
inputToolbarStyle: BoxDecoration(
color: Color.fromARGB(120, 0, 0, 0),
// Color.fromARGB(0, 54, 59, 72),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16),
topRight: Radius.circular(16)),
),
inputToolbarMargin: EdgeInsets.all(0),
sendButtonBuilder: null,
inputToolbarPadding: EdgeInsets.only(
top: 15, right: 15, left: 15, bottom: 10),
IconButton(
tooltip: '设置',
icon: const Icon(
Icons.settings,
color: AppColors.primaryElementText,
),
onPressed: () {
controller.share();
},
)
],
title: RichText(
textAlign: TextAlign.center,
text: TextSpan(children: [
TextSpan(
text: "${controller.state.page}",
style: const TextStyle(
color: AppColors.primaryElementText,
fontFamily: 'Montserrat',
fontSize: 18,
fontWeight: FontWeight.w600,
)),
TextSpan(
text: "${controller.state.messageList.length}",
style: const TextStyle(fontSize: 0)),
])),
leading: GradientButton(
increaseHeightBy: -5,
// increaseWidthBy: 5,
elevation: 0,
shadowColor: Colors.black,
gradient: const LinearGradient(
colors: [
Color.fromARGB(255, 223, 188, 134),
Color.fromARGB(255, 244, 218, 129),
Color.fromARGB(255, 248, 228, 127)
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
child: Row(children: const [
Icon(
Icons.add_circle,
color: Colors.black,
size: 30,
),
SizedBox(
width: 10,
),
currentUser: _user,
onSend: cc.sendMessage,
messages: cc.state.messageList,
messageOptions: Chat.MessageOptions(
onPressMessage: cc.tabMessage,
onLongPressMessage: (mes) => {},
shareMenuBuilder: cc.shareMenuBuilder
// containerColor: Colors.black,
Text("订阅",
style: TextStyle(
color: Color.fromARGB(255, 95, 54, 0),
fontSize: 16)),
]),
callback: () => controller.virtualPay()),
),
body: SizedBox(
width: double.infinity,
height: double.infinity,
// color: Color.fromARGB(0, 255, 255, 0),
// color: Colors.red,
// Color.argb(255, 29, 33, 60)
// color: Color.fromARGB(0, 29, 33, 60),
// color: Color.fromARGB(255, 26, 27, 46),
child: Chat.DashChat(
// readOnly: cc.state.readOnly,
inputOptions: Chat.InputOptions(
onLongPressStart: cc.onLongPressStart,
onLongPressEnd: cc.onLongPressEnd,
textInputAction: TextInputAction.send,
inputDisabled: cc.state.isLoading,
sendOnEnter: true,
leading: [
// GradientCircularProgressIndicator(
// radius: 100,
// ),
// GradientRotation(1.0,),
// GradientButton(
// child: Icon(Icons.text_fields_sharp), callback: () {}),
/*Android语音转换文字有问题暂时屏蔽掉*/
(Platform.isAndroid ? Container() : Container(
margin: const EdgeInsets.only(right: 10),
child: InkWell(
borderRadius: BorderRadius.circular(100),
onTap: cc.changeInput,
child: Container(
decoration: const BoxDecoration(
shape: BoxShape.circle,
border: GradientBoxBorder(
gradient: LinearGradient(colors: [
Color(0xFFbe6afb),
// Color(0xFF9c67f6),
Color(0xFF7965f8)
]),
width: 2,
),
),
padding: const EdgeInsets.all(10),
child: Icon(
!cc.state.isInputText
? Icons.keyboard
: Icons.keyboard_voice,
),
)))
// padding: EdgeInsets.all(10),
// margin: EdgeInsets.only(right: 10),
// child: Icon(Icons.text_fields_sharp),
// decoration: const BoxDecoration(
// shape: BoxShape.circle,
// border: GradientBoxBorder(
// gradient: LinearGradient(
// colors: [Colors.pink, Colors.orange]),
// width: 2,
// ),
// ),
),
// Container(
// padding: EdgeInsets.all(10),
// margin: EdgeInsets.only(right: 10),
// decoration: const BoxDecoration(
// // color: Colors.red,
// borderRadius: BorderRadius.all(Radius.circular(54)),
// border: Border(
// top: BorderSide(
// width: 2.0,
// color: Colors.red,
// ),
// bottom: BorderSide(
// width: 2.0,
// color: Colors.red,
// ),
// right: BorderSide(
// width: 2.0,
// color: Colors.red,
// ),
// left: BorderSide(
// width: 2.0,
// color: Colors.red,
// ),
// ),
// ),
// child: Icon(Icons.text_fields_sharp),
// )
],
// showTraillingBeforeSend: true,
isTextInput: cc.state.isInputText,
inputTextStyle: TextStyle(color: Colors.white),
inputToolbarStyle: BoxDecoration(
color: Color.fromARGB(120, 0, 0, 0),
// Color.fromARGB(0, 54, 59, 72),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16),
topRight: Radius.circular(16)),
),
inputToolbarMargin: EdgeInsets.all(0),
sendButtonBuilder: null,
inputToolbarPadding: EdgeInsets.only(
top: 15, right: 15, left: 15, bottom: 10),
),
currentUser: _user,
onSend: cc.sendMessage,
messages: cc.state.messageList,
messageOptions: Chat.MessageOptions(
onPressMessage: cc.tabMessage,
onLongPressMessage: (mes) => {},
shareMenuBuilder: cc.shareMenuBuilder
// containerColor: Colors.black,
),
)));
),
),
)
);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment