提交 d9bb1748 authored 作者: yueweilu's avatar yueweilu

使用 ReadController 管理状态

上级 05b39a7a
...@@ -70,6 +70,6 @@ SPEC CHECKSUMS: ...@@ -70,6 +70,6 @@ SPEC CHECKSUMS:
permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6 permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126 shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126
PODFILE CHECKSUM: 0ad3cbdbfc252b10d3b4db129d4d399f42000f4b PODFILE CHECKSUM: d88b567994d32cfdf2f8417e66666d472921c85e
COCOAPODS: 1.11.2 COCOAPODS: 1.11.2
...@@ -51,12 +51,15 @@ class MyApp extends StatelessWidget { ...@@ -51,12 +51,15 @@ class MyApp extends StatelessWidget {
); );
}, },
), ),
// localizationsDelegates: const [ supportedLocales: const [
// GlobalMaterialLocalizations.delegate, Locale('zh', 'CN'), // Chinese
// GlobalWidgetsLocalizations.delegate, ],
// GlobalCupertinoLocalizations.delegate, localizationsDelegates: const [
// // S.delegate, GlobalMaterialLocalizations.delegate,
// ], GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
// S.delegate,
],
// locale: config.locale, // locale: config.locale,
// supportedLocales: S.delegate.supportedLocales, // supportedLocales: S.delegate.supportedLocales,
), ),
......
...@@ -2,6 +2,9 @@ library home; ...@@ -2,6 +2,9 @@ library home;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:go_router/go_router.dart';
import '../../routes/index.dart';
part 'view.dart'; part 'view.dart';
part 'controller.dart'; part 'controller.dart';
\ No newline at end of file
...@@ -12,9 +12,20 @@ class _HomePageState extends State<HomePage> { ...@@ -12,9 +12,20 @@ class _HomePageState extends State<HomePage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light); SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
return Scaffold( return Scaffold(
body: Container( appBar: AppBar(title: const Text('首页'),),
color: Colors.cyan, body: Column(
), mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ElevatedButton(
onPressed: (){
context.pushNamed(Routes.web);
},
child: const Text('web'),
)
],
)
); );
} }
} }
...@@ -39,7 +39,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver{ ...@@ -39,7 +39,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver{
controller: controller.pageController, controller: controller.pageController,
onPageChanged: controller.onPageChanged, onPageChanged: controller.onPageChanged,
children: const [ children: const [
WebPage(), HomePage(),
LibraryPage(), LibraryPage(),
TestTTSPage(), TestTTSPage(),
RecordPage(), RecordPage(),
......
part of web;
class ReadController extends GetxController with GetSingleTickerProviderStateMixin{
late AnimationController _controller;
bool _show = false;
bool get show => _show;
void setShow(bool value) {
_show = !value;
if (_show) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
_controller.forward();
}
else {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
_controller.reverse();
}
update();
}
AnimationController get controller => _controller;
@override
void onInit() {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
_controller = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 100),
);
super.onInit();
}
@override
void onClose() {
_controller.dispose();
super.onClose();
}
}
\ No newline at end of file
...@@ -2,7 +2,10 @@ library web; ...@@ -2,7 +2,10 @@ library web;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_book/utils/index.dart'; import 'package:flutter_book/utils/index.dart';
import 'package:get/get.dart';
part 'view.dart'; part 'view.dart';
part 'controller.dart';
\ No newline at end of file
...@@ -8,10 +8,20 @@ class WebPage extends StatefulWidget { ...@@ -8,10 +8,20 @@ class WebPage extends StatefulWidget {
} }
class _WebPageState extends State<WebPage> { class _WebPageState extends State<WebPage> {
@override
void initState() {
super.initState();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return GetBuilder<ReadController>(
body: InAppWebView( init: ReadController(),
builder: (readController) => Scaffold(
body: Stack(
children: [
InAppWebView(
initialUrlRequest: URLRequest( initialUrlRequest: URLRequest(
url: Uri.parse('http://192.168.11.39:5500/'), url: Uri.parse('http://192.168.11.39:5500/'),
), ),
...@@ -23,9 +33,14 @@ class _WebPageState extends State<WebPage> { ...@@ -23,9 +33,14 @@ class _WebPageState extends State<WebPage> {
ContextMenuItem(title: '划线',androidId: 1,iosId: '1'), ContextMenuItem(title: '划线',androidId: 1,iosId: '1'),
ContextMenuItem(title: '提问',androidId: 2,iosId: '2'), ContextMenuItem(title: '提问',androidId: 2,iosId: '2'),
ContextMenuItem(title: '笔记',androidId: 3,iosId: '3'), ContextMenuItem(title: '笔记',androidId: 3,iosId: '3'),
ContextMenuItem(title: '划线1',androidId: 1,iosId: '1'),
ContextMenuItem(title: '划线2',androidId: 1,iosId: '1'),
ContextMenuItem(title: '划线3',androidId: 1,iosId: '1'),
ContextMenuItem(title: '划线4',androidId: 1,iosId: '1'),
], ],
options: ContextMenuOptions( options: ContextMenuOptions(
hideDefaultSystemContextMenuItems: true, hideDefaultSystemContextMenuItems: false,
), ),
onContextMenuActionItemClicked: (ContextMenuItem item) async { onContextMenuActionItemClicked: (ContextMenuItem item) async {
switch (item.title){ switch (item.title){
...@@ -43,6 +58,47 @@ class _WebPageState extends State<WebPage> { ...@@ -43,6 +58,47 @@ class _WebPageState extends State<WebPage> {
} }
), ),
onLoadStop: (controller, url) {
controller.addJavaScriptHandler(handlerName: 'onTap', callback: (args){
readController.setShow(readController.show);
});
controller.evaluateJavascript(source: '''
document.addEventListener('click', function() {
window.flutter_inappwebview.callHandler('onTap');
});
''');
},
),
AnimatedPositioned(
duration: readController.controller.duration!,
curve: Curves.easeInOut,
top: readController.show ? 0 : -100, // 负值隐藏,0 显示
left: 0,
right: 0,
height: 100,
child: Container(
color: Colors.limeAccent,
alignment: Alignment.center,
child: Text('top View'),
),
),
AnimatedPositioned(
duration: readController.controller.duration!,
curve: Curves.easeInOut,
bottom: readController.show ? 0 : -100, // 负值隐藏,0 显示
left: 0,
right: 0,
height: 100,
child: Container(
color: Colors.limeAccent,
alignment: Alignment.center,
child: Text('Bottom View'),
),
),
],
),
), ),
); );
......
...@@ -6,6 +6,7 @@ import 'package:flutter_book/pages/ad/index.dart'; ...@@ -6,6 +6,7 @@ import 'package:flutter_book/pages/ad/index.dart';
import 'package:flutter_book/pages/login/index.dart'; import 'package:flutter_book/pages/login/index.dart';
import 'package:flutter_book/pages/main/index.dart'; import 'package:flutter_book/pages/main/index.dart';
import 'package:flutter_book/pages/splash/index.dart'; import 'package:flutter_book/pages/splash/index.dart';
import 'package:flutter_book/pages/web/index.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
......
...@@ -8,6 +8,7 @@ abstract class Routes { ...@@ -8,6 +8,7 @@ abstract class Routes {
static const main = 'main'; static const main = 'main';
static const ad = 'ad'; static const ad = 'ad';
static const login = 'login'; static const login = 'login';
static const web = 'web';
static final GoRouter config = GoRouter( static final GoRouter config = GoRouter(
// initialLocation: '/$splash', // initialLocation: '/$splash',
...@@ -49,6 +50,15 @@ abstract class Routes { ...@@ -49,6 +50,15 @@ abstract class Routes {
key: state.pageKey, key: state.pageKey,
child: const LoginPage() child: const LoginPage()
) )
),
GoRoute(
path: '/$web',
name: web,
pageBuilder: (context, state) =>CupertinoPage(
name: state.uri.toString(),
key: state.pageKey,
child: const WebPage()
)
) )
] ]
); );
......
...@@ -50,7 +50,7 @@ dependencies: ...@@ -50,7 +50,7 @@ dependencies:
crypto: 3.0.3 crypto: 3.0.3
convert: 3.0.1 convert: 3.0.1
flutter_tts: 3.8.5 flutter_tts: 3.8.5
flutter_inappwebview: ^5.6.0 flutter_inappwebview: ^5.8.0
intl: 0.18.0 intl: 0.18.0
flutter_sound: ^9.2.13 flutter_sound: ^9.2.13
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论