|
import 'package:auto_gpt_flutter_client/viewmodels/settings_viewmodel.dart'; |
|
import 'package:auto_gpt_flutter_client/viewmodels/skill_tree_viewmodel.dart'; |
|
import 'package:auto_gpt_flutter_client/viewmodels/task_viewmodel.dart'; |
|
import 'package:auto_gpt_flutter_client/viewmodels/chat_viewmodel.dart'; |
|
import 'package:auto_gpt_flutter_client/views/settings/settings_view.dart'; |
|
import 'package:auto_gpt_flutter_client/views/side_bar/side_bar_view.dart'; |
|
import 'package:auto_gpt_flutter_client/views/skill_tree/skill_tree_view.dart'; |
|
import 'package:auto_gpt_flutter_client/views/task/task_view.dart'; |
|
import 'package:auto_gpt_flutter_client/views/chat/chat_view.dart'; |
|
import 'package:auto_gpt_flutter_client/views/task_queue/task_queue_view.dart'; |
|
import 'package:flutter/cupertino.dart'; |
|
import 'package:provider/provider.dart'; |
|
|
|
class MainLayout extends StatelessWidget { |
|
final ValueNotifier<String> selectedViewNotifier = ValueNotifier('TaskView'); |
|
|
|
MainLayout({super.key}); |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
|
|
double width = MediaQuery.of(context).size.width; |
|
|
|
|
|
final taskViewModel = Provider.of<TaskViewModel>(context); |
|
final chatViewModel = Provider.of<ChatViewModel>(context); |
|
final settingsViewModel = Provider.of<SettingsViewModel>(context); |
|
|
|
|
|
double sideBarWidth = 60.0; |
|
|
|
|
|
double taskViewWidth = 280.0; |
|
|
|
|
|
double settingsViewWidth = 280.0; |
|
|
|
|
|
double remainingWidth = width - sideBarWidth; |
|
|
|
|
|
double skillTreeViewWidth = 0; |
|
double testQueueViewWidth = 0; |
|
double chatViewWidth = 0; |
|
|
|
if (width > 800) { |
|
return Row( |
|
children: [ |
|
SizedBox( |
|
width: sideBarWidth, |
|
child: SideBarView(selectedViewNotifier: selectedViewNotifier)), |
|
ValueListenableBuilder( |
|
valueListenable: selectedViewNotifier, |
|
builder: (context, String value, _) { |
|
return Consumer<SkillTreeViewModel>( |
|
builder: (context, skillTreeViewModel, _) { |
|
if (value == 'TaskView') { |
|
|
|
skillTreeViewModel.resetState(); |
|
chatViewWidth = remainingWidth - taskViewWidth; |
|
return Row( |
|
children: [ |
|
SizedBox( |
|
width: taskViewWidth, |
|
child: TaskView(viewModel: taskViewModel)), |
|
SizedBox( |
|
width: chatViewWidth, |
|
child: ChatView(viewModel: chatViewModel)) |
|
], |
|
); |
|
} else if (value == 'SettingsView') { |
|
|
|
skillTreeViewModel.resetState(); |
|
chatViewWidth = remainingWidth - settingsViewWidth; |
|
return Row( |
|
children: [ |
|
SizedBox( |
|
width: settingsViewWidth, |
|
|
|
child: SettingsView(viewModel: settingsViewModel)), |
|
SizedBox( |
|
width: chatViewWidth, |
|
|
|
child: ChatView(viewModel: chatViewModel)), |
|
], |
|
); |
|
} else { |
|
if (skillTreeViewModel.selectedNode != null) { |
|
|
|
testQueueViewWidth = remainingWidth * 0.25; |
|
skillTreeViewWidth = remainingWidth * 0.25; |
|
chatViewWidth = remainingWidth * 0.5; |
|
} else { |
|
|
|
skillTreeViewWidth = remainingWidth * 0.5; |
|
chatViewWidth = remainingWidth * 0.5; |
|
} |
|
|
|
return Row( |
|
children: [ |
|
SizedBox( |
|
width: skillTreeViewWidth, |
|
child: |
|
SkillTreeView(viewModel: skillTreeViewModel)), |
|
if (skillTreeViewModel.selectedNode != null) |
|
SizedBox( |
|
width: testQueueViewWidth, |
|
child: TaskQueueView()), |
|
SizedBox( |
|
width: chatViewWidth, |
|
child: ChatView(viewModel: chatViewModel)), |
|
], |
|
); |
|
} |
|
}, |
|
); |
|
}, |
|
), |
|
], |
|
); |
|
} else { |
|
|
|
|
|
return CupertinoTabScaffold( |
|
tabBar: CupertinoTabBar( |
|
items: const <BottomNavigationBarItem>[ |
|
BottomNavigationBarItem( |
|
icon: Icon(CupertinoIcons.person), |
|
label: 'Tasks', |
|
), |
|
BottomNavigationBarItem( |
|
icon: Icon(CupertinoIcons.chat_bubble), |
|
label: 'Chat', |
|
), |
|
], |
|
), |
|
tabBuilder: (BuildContext context, int index) { |
|
CupertinoTabView? returnValue; |
|
|
|
switch (index) { |
|
case 0: |
|
returnValue = CupertinoTabView(builder: (context) { |
|
return CupertinoPageScaffold( |
|
child: SafeArea(child: TaskView(viewModel: taskViewModel)), |
|
); |
|
}); |
|
break; |
|
case 1: |
|
returnValue = CupertinoTabView(builder: (context) { |
|
return CupertinoPageScaffold( |
|
child: SafeArea(child: ChatView(viewModel: chatViewModel)), |
|
); |
|
}); |
|
break; |
|
} |
|
|
|
return returnValue ?? |
|
CupertinoTabView(builder: (context) { |
|
return CupertinoPageScaffold( |
|
child: Container(), |
|
); |
|
}); |
|
}, |
|
); |
|
} |
|
} |
|
} |
|
|