Commit 5f368f69 authored by skeyboy's avatar skeyboy

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

parent 04afb450
...@@ -9,7 +9,7 @@ class AssistantPage extends GetView<AssistantController> { ...@@ -9,7 +9,7 @@ class AssistantPage extends GetView<AssistantController> {
// 主视图 // 主视图
Widget _buildView() { Widget _buildView() {
return GridWidget(); return _AssistantPage();
} }
@override @override
...@@ -29,3 +29,20 @@ class AssistantPage extends GetView<AssistantController> { ...@@ -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> { ...@@ -9,7 +9,7 @@ class CreationPage extends GetView<CreationController> {
// 主视图 // 主视图
Widget _buildView() { Widget _buildView() {
return GridWidget(); return const _InnerCreationPage();
// return Obx(() => Center( // return Obx(() => Center(
// child: InkWell( // child: InkWell(
// onTap: () => controller.increment(), // onTap: () => controller.increment(),
...@@ -40,3 +40,23 @@ class CreationPage extends GetView<CreationController> { ...@@ -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> { ...@@ -23,201 +23,224 @@ class HomePage extends GetView<HomeController> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final cc = Get.put(HomeController());
return WillPopScope( return WillPopScope(
onWillPop: () async { onWillPop: () async {
return false; return false;
}, },
child: Obx(() => Scaffold( child: const _HomePage());
resizeToAvoidBottomInset: false, }
backgroundColor: Color.fromARGB(0, 0, 0, 0), }
appBar: transparentAppBar(
actions: [ class _HomePage extends StatefulWidget {
RotationTransition( const _HomePage({Key? key}) : super(key: key);
turns: controller.animation,
child: IconButton( @override
tooltip: '重置', State<_HomePage> createState() => _HomePageState();
icon: const Icon( }
Icons.settings_backup_restore_sharp,
color: AppColors.primaryElementText, class _HomePageState extends State<_HomePage>
), with AutomaticKeepAliveClientMixin {
onPressed: () { @override
controller.reset(); // 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( onPressed: () {
tooltip: '设置', controller.reset();
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()),
), ),
body: SizedBox( IconButton(
width: double.infinity, tooltip: '设置',
height: double.infinity, icon: const Icon(
// color: Color.fromARGB(0, 255, 255, 0), Icons.settings,
// color: Colors.red, color: AppColors.primaryElementText,
// Color.argb(255, 29, 33, 60) ),
// color: Color.fromARGB(0, 29, 33, 60), onPressed: () {
// color: Color.fromARGB(255, 26, 27, 46), controller.share();
child: Chat.DashChat( },
// readOnly: cc.state.readOnly, )
inputOptions: Chat.InputOptions( ],
onLongPressStart: cc.onLongPressStart, title: RichText(
onLongPressEnd: cc.onLongPressEnd, textAlign: TextAlign.center,
textInputAction: TextInputAction.send, text: TextSpan(children: [
inputDisabled: cc.state.isLoading, TextSpan(
sendOnEnter: true, text: "${controller.state.page}",
leading: [ style: const TextStyle(
// GradientCircularProgressIndicator( color: AppColors.primaryElementText,
// radius: 100, fontFamily: 'Montserrat',
// ), fontSize: 18,
// GradientRotation(1.0,), fontWeight: FontWeight.w600,
// GradientButton( )),
// child: Icon(Icons.text_fields_sharp), callback: () {}), TextSpan(
/*Android语音转换文字有问题暂时屏蔽掉*/ text: "${controller.state.messageList.length}",
(Platform.isAndroid ? Container(): Container( style: const TextStyle(fontSize: 0)),
margin: const EdgeInsets.only(right: 10), ])),
child: InkWell( leading: GradientButton(
borderRadius: BorderRadius.circular(100), increaseHeightBy: -5,
onTap: cc.changeInput, // increaseWidthBy: 5,
child: Container( elevation: 0,
decoration: const BoxDecoration( shadowColor: Colors.black,
shape: BoxShape.circle, gradient: const LinearGradient(
border: GradientBoxBorder( colors: [
gradient: LinearGradient(colors: [ Color.fromARGB(255, 223, 188, 134),
Color(0xFFbe6afb), Color.fromARGB(255, 244, 218, 129),
// Color(0xFF9c67f6), Color.fromARGB(255, 248, 228, 127)
Color(0xFF7965f8) ],
]), begin: Alignment.topLeft,
width: 2, end: Alignment.bottomRight,
), ),
), child: Row(children: const [
padding: const EdgeInsets.all(10), Icon(
child: Icon( Icons.add_circle,
!cc.state.isInputText color: Colors.black,
? Icons.keyboard size: 30,
: Icons.keyboard_voice, ),
), SizedBox(
))) width: 10,
// 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, Text("订阅",
onSend: cc.sendMessage, style: TextStyle(
messages: cc.state.messageList, color: Color.fromARGB(255, 95, 54, 0),
messageOptions: Chat.MessageOptions( fontSize: 16)),
onPressMessage: cc.tabMessage, ]),
onLongPressMessage: (mes) => {}, callback: () => controller.virtualPay()),
shareMenuBuilder: cc.shareMenuBuilder ),
// containerColor: Colors.black, 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