Skip to content

Commit

Permalink
Merge pull request #114 from mylxsw/main
Browse files Browse the repository at this point in the history
merge from main
  • Loading branch information
mylxsw authored Jun 12, 2024
2 parents c57f645 + 66722c4 commit 25499cf
Show file tree
Hide file tree
Showing 10 changed files with 245 additions and 226 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release

Makefile.local
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ https://aidea.aicode.cc

- 微信技术交流群:

<img src="https://github.com/mylxsw/aidea/assets/2330911/50e400ec-3e8d-4e39-a08b-874a2c527b6d" width="400"/>
<img src="https://github.com/mylxsw/aidea/assets/2330911/0a697937-b357-4d88-bb16-c07c5517d13c" width="400"/>

如果无法加入,请添加微信号 `x-prometheus` 为好友,拉你进群。

Expand Down
2 changes: 1 addition & 1 deletion docker-build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

VERSION=1.0.13.1
VERSION=1.0.14

rm -fr build/web

Expand Down
85 changes: 44 additions & 41 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import 'package:askaide/page/admin/users.dart';
import 'package:askaide/page/balance/web_payment_proxy.dart';
import 'package:askaide/page/balance/web_payment_result.dart';
import 'package:askaide/page/creative_island/draw/artistic_wordart.dart';
import 'package:flutter_phoenix/flutter_phoenix.dart';
import 'package:path/path.dart';

import 'package:askaide/bloc/account_bloc.dart';
Expand Down Expand Up @@ -198,7 +199,7 @@ void main() async {
);

final creativeIslandRepo =
CreativeIslandRepository(CreativeIslandDataProvider(db));
CreativeIslandRepository(CreativeIslandDataProvider(db));

// 聊天状态加载器
final stateManager = MessageStateManager(cacheRepo);
Expand Down Expand Up @@ -247,13 +248,15 @@ void main() async {
);
});

runApp(MyApp(
settingRepo: settingRepo,
chatMsgRepo: chatMsgRepo,
openAIRepo: openAIRepo,
cacheRepo: cacheRepo,
creativeIslandRepo: creativeIslandRepo,
messageStateManager: stateManager,
runApp(Phoenix(
child: MyApp(
settingRepo: settingRepo,
chatMsgRepo: chatMsgRepo,
openAIRepo: openAIRepo,
cacheRepo: cacheRepo,
creativeIslandRepo: creativeIslandRepo,
messageStateManager: stateManager,
),
));
}

Expand Down Expand Up @@ -293,11 +296,11 @@ class MyApp extends StatefulWidget {
var usingGuestMode = settingRepo.boolDefault(settingUsingGuestMode, false);

final openAISelfHosted =
settingRepo.boolDefault(settingOpenAISelfHosted, false);
settingRepo.boolDefault(settingOpenAISelfHosted, false);
final deepAISelfHosted =
settingRepo.boolDefault(settingDeepAISelfHosted, false);
settingRepo.boolDefault(settingDeepAISelfHosted, false);
final stabilityAISelfHosted =
settingRepo.boolDefault(settingStabilityAISelfHosted, false);
settingRepo.boolDefault(settingStabilityAISelfHosted, false);

final shouldLogin = (apiServerToken == null || apiServerToken == '') &&
!usingGuestMode &&
Expand All @@ -316,10 +319,10 @@ class MyApp extends StatefulWidget {
// navigatorKey: _shellNavigatorKey,
//parentNavigatorKey: _rootNavigatorKey,
builder: (
BuildContext context,
GoRouterState state,
StatefulNavigationShell navigationShell,
) {
BuildContext context,
GoRouterState state,
StatefulNavigationShell navigationShell,
) {
return AppScaffold(
settingRepo: settingRepo,
navigationShell: navigationShell,
Expand All @@ -340,10 +343,10 @@ class MyApp extends StatefulWidget {
child: HomePage(
setting: settingRepo,
showInitialDialog:
state.queryParameters['show_initial_dialog'] ==
'true',
state.queryParameters['show_initial_dialog'] ==
'true',
reward:
int.tryParse(state.queryParameters['reward'] ?? '0'),
int.tryParse(state.queryParameters['reward'] ?? '0'),
),
),
),
Expand Down Expand Up @@ -481,7 +484,7 @@ class MyApp extends StatefulWidget {
value: ChatBlocManager().getBloc(
chatAnywhereRoomId,
chatHistoryId:
int.tryParse(state.queryParameters['chat_id'] ?? ''),
int.tryParse(state.queryParameters['chat_id'] ?? ''),
),
),
BlocProvider.value(value: chatRoomBloc),
Expand Down Expand Up @@ -610,7 +613,7 @@ class MyApp extends StatefulWidget {
CreativeIslandBloc(creativeIslandRepo)),
],
child:
UserCenterScreen(settings: context.read<SettingRepository>()),
UserCenterScreen(settings: context.read<SettingRepository>()),
),
),
),
Expand Down Expand Up @@ -1345,7 +1348,7 @@ class _MyAppState extends State<MyApp> {
create: (context) => widget.cacheRepo),
],
child: ChangeNotifierProvider(
create: (context) => AppTheme.instance
create: (context) => AppTheme.get()
..mode = AppTheme.themeModeFormString(
widget.settingRepo.stringDefault(settingThemeMode, 'system')),
builder: (context, _) {
Expand All @@ -1363,25 +1366,25 @@ class _MyAppState extends State<MyApp> {
// TODO 后面要增加一个设置项,允许用户自定义字体大小
return MediaQuery(
data:
MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: BotToastInit()(context, child),
);
},
routerConfig: widget._router,
supportedLocales: widget.localization.supportedLocales,
localizationsDelegates:
widget.localization.localizationsDelegates,
widget.localization.localizationsDelegates,
scrollBehavior:
PlatformTool.isAndroid() || PlatformTool.isIOS()
? null
: const MaterialScrollBehavior().copyWith(
dragDevices: {
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
PointerDeviceKind.stylus,
PointerDeviceKind.trackpad,
},
),
PlatformTool.isAndroid() || PlatformTool.isIOS()
? null
: const MaterialScrollBehavior().copyWith(
dragDevices: {
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
PointerDeviceKind.stylus,
PointerDeviceKind.trackpad,
},
),
);
},
);
Expand All @@ -1401,10 +1404,10 @@ ThemeData createLightThemeData() {
),
iconButtonTheme: PlatformTool.isMacOS()
? IconButtonThemeData(
style: ButtonStyle(
overlayColor: MaterialStateProperty.all(Colors.transparent),
),
)
style: ButtonStyle(
overlayColor: MaterialStateProperty.all(Colors.transparent),
),
)
: null,
dividerColor: Colors.transparent,
dialogBackgroundColor: Colors.white,
Expand Down Expand Up @@ -1434,10 +1437,10 @@ ThemeData createDarkThemeData() {
),
iconButtonTheme: PlatformTool.isMacOS()
? IconButtonThemeData(
style: ButtonStyle(
overlayColor: MaterialStateProperty.all(Colors.transparent),
),
)
style: ButtonStyle(
overlayColor: MaterialStateProperty.all(Colors.transparent),
),
)
: null,
dividerColor: Colors.transparent,
dialogBackgroundColor: const Color.fromARGB(255, 48, 48, 48),
Expand Down
75 changes: 33 additions & 42 deletions lib/page/app_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class AppScaffold extends StatefulWidget {
final StatefulNavigationShell navigationShell;
const AppScaffold({
Key? key,
required this.settingRepo, required this.navigationShell,
required this.settingRepo,
required this.navigationShell,
}) : super(key: key);
@override
State<AppScaffold> createState() => _AppScaffoldState();
Expand All @@ -38,21 +39,21 @@ class _AppScaffoldState extends State<AppScaffold> {
void initState() {
cancelHideBottomNavigatorBarEventListener =
GlobalEvent().on("hideBottomNavigatorBar", (data) {
if (mounted) {
setState(() {
_showBottomNavigatorBar = false;
});
}
if (mounted) {
setState(() {
_showBottomNavigatorBar = false;
});
}
});

cancelShowBottomNavigatorBarEventListener =
GlobalEvent().on("showBottomNavigatorBar", (data) {
if (mounted) {
setState(() {
_showBottomNavigatorBar = true;
});
}
if (mounted) {
setState(() {
_showBottomNavigatorBar = true;
});
}
});

super.initState();
}
Expand Down Expand Up @@ -132,24 +133,24 @@ class _AppScaffoldState extends State<AppScaffold> {
extendBody: false,
bottomNavigationBar: currentIndex > -1 && _showBottomNavigatorBar
? BottomNavigationBar(
landscapeLayout: BottomNavigationBarLandscapeLayout.centered,
showSelectedLabels: true,
showUnselectedLabels: true,
currentIndex: _calculateSelectedIndex(context),
onTap: (int index) => _onTap(context, index),
selectedItemColor: customColors.linkColor,
unselectedItemColor: Colors.grey,
selectedFontSize: 10,
unselectedFontSize: 10,
type: BottomNavigationBarType.fixed,
enableFeedback: true,
backgroundColor: customColors.backgroundColor,
elevation: 0,
items: [
for (var i = 0; i < barItems.length; i++)
barItems[i].builder(i, customColors),
],
)
landscapeLayout: BottomNavigationBarLandscapeLayout.centered,
showSelectedLabels: true,
showUnselectedLabels: true,
currentIndex: _calculateSelectedIndex(context),
onTap: (int index) => _onTap(context, index),
selectedItemColor: customColors.linkColor,
unselectedItemColor: Colors.grey,
selectedFontSize: 10,
unselectedFontSize: 10,
type: BottomNavigationBarType.fixed,
enableFeedback: true,
backgroundColor: customColors.backgroundColor,
elevation: 0,
items: [
for (var i = 0; i < barItems.length; i++)
barItems[i].builder(i, customColors),
],
)
: null,
);
}
Expand All @@ -166,19 +167,9 @@ class _AppScaffoldState extends State<AppScaffold> {
return -1;
}

void onTap(int value) {
if (context.canPop()) {
context.pop();
}

void _onTap(BuildContext context, int index) {
HapticFeedbackHelper.lightImpact();

final barItems = _bottomNavigationBarList();
if (value >= barItems.length) return context.go(Ability().homeRoute);

return context.go(barItems[value].route);
}
void _onTap(BuildContext context, int index) {
widget.navigationShell.goBranch(
index,
initialLocation: index == widget.navigationShell.currentIndex,
Expand All @@ -199,15 +190,15 @@ BottomNavigationBarItem createAnimatedNavBarItem({
firstChild: Icon(icon),
secondChild: Icon(activatedIcon, color: activatedColor ?? Colors.green),
crossFadeState:
activated ? CrossFadeState.showSecond : CrossFadeState.showFirst,
activated ? CrossFadeState.showSecond : CrossFadeState.showFirst,
duration: const Duration(milliseconds: 300),
),
);
}

class BottomNavigationBarConfig {
final BottomNavigationBarItem Function(int index, CustomColors customColors)
builder;
builder;
final String route;

BottomNavigationBarConfig({
Expand Down
8 changes: 4 additions & 4 deletions lib/page/component/model_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class _ModelItemState extends State<ModelItem> {
children: [
if (item.avatarUrl != null) ...[
_buildAvatar(
avatarUrl: item.avatarUrl, size: 45),
avatarUrl: item.avatarUrl, size: 50),
const SizedBox(width: 10),
],
Expanded(
Expand All @@ -170,7 +170,7 @@ class _ModelItemState extends State<ModelItem> {
overflow:
TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 14),
fontSize: 15),
),
),
),
Expand Down Expand Up @@ -211,7 +211,7 @@ class _ModelItemState extends State<ModelItem> {
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 10,
fontSize: 12,
color: customColors.weakTextColor,
),
),
Expand Down Expand Up @@ -259,7 +259,7 @@ class _ModelItemState extends State<ModelItem> {
category,
style: TextStyle(
color: customColors.dialogDefaultTextColor,
fontSize: 12,
fontSize: 14,
),
),
);
Expand Down
17 changes: 17 additions & 0 deletions lib/page/component/theme/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ class AppTheme extends ChangeNotifier {

static AppTheme instance = AppTheme('system');

static AppTheme get() {
if (!instance.mounted) {
instance = AppTheme('system');
}

return instance;
}

static ThemeMode themeModeFormString(String mode) {
switch (mode) {
case 'light':
Expand All @@ -34,4 +42,13 @@ class AppTheme extends ChangeNotifier {
_mode = mode;
notifyListeners();
}

bool _mounted = false;
bool get mounted => _mounted;

@override
void dispose() {
super.dispose();
_mounted = true;
}
}
Loading

0 comments on commit 25499cf

Please sign in to comment.