{"id":72,"date":"2026-04-26T08:43:26","date_gmt":"2026-04-25T23:43:26","guid":{"rendered":"https:\/\/tate.stars.ne.jp\/wpb\/?p=72"},"modified":"2026-04-26T08:43:53","modified_gmt":"2026-04-25T23:43:53","slug":"inappweb2","status":"publish","type":"post","link":"https:\/\/tate.stars.ne.jp\/wpb\/inappweb2.html","title":{"rendered":"Inappweb2"},"content":{"rendered":"<pre><code class=\"swift\">\nmain.dart\nimport 'package:flutter\/material.dart';\nimport 'package:flutter_inappwebview\/flutter_inappwebview.dart';\nimport 'package:flutter_riverpod\/flutter_riverpod.dart';\nimport 'package:flutter_riverpod\/legacy.dart';\nimport 'package:flutter\/services.dart'; \n\nfinal navIndexProvider = StateProvider<int>((ref) => 0);\n\/\/ \u30ed\u30fc\u30ab\u30eb\u30b5\u30fc\u30d0\u30fc\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\uff08\u30b7\u30f3\u30b0\u30eb\u30c8\u30f3\u63a8\u5968\uff09\nfinal localhostServerProvider = Provider((ref) => InAppLocalhostServer());\n\nvoid main() async {\n WidgetsFlutterBinding.ensureInitialized();\n  \/\/ \u753b\u9762\u306e\u5411\u304d\u3092\u6a2a\u5411\u304d\u306b\u56fa\u5b9a\nSystemChrome.setPreferredOrientations([\n DeviceOrientation.landscapeLeft, \/\/ \u6a2a\u5411\u304d\uff08\u5de6\uff09\n\/\/ DeviceOrientation.landscapeRight, \/\/ \u6a2a\u5411\u304d\uff08\u53f3\uff09\n ]).then((_) {\n   runApp(ProviderScope(child: MaterialApp(\n   debugShowCheckedModeBanner: false, \n   home: MainScreen()\n    )));\n  });\n}\n\nclass MainScreen extends ConsumerStatefulWidget {\n @override\n _MainScreenState createState() => _MainScreenState();\n}\nclass _MainScreenState extends ConsumerState<MainScreen> {\n InAppWebViewController? webViewController;\n final List<String> pages = [\"index1.html\", \"index2.html\", \"index3.html\"];\n @override\n  void initState() {\n  super.initState();\n  \/\/ \u30ed\u30fc\u30ab\u30eb\u30b5\u30fc\u30d0\u30fc\u306e\u8d77\u52d5\n  ref.read(localhostServerProvider).start();\n }\n@override\n Widget build(BuildContext context) {\n final selectedIndex = ref.watch(navIndexProvider);\n return Scaffold(\n  body: Row(\n  children: [\n   NavigationRail(\n   selectedIndex: selectedIndex,\n   onDestinationSelected: (index) {\n   ref.read(navIndexProvider.notifier).state = index;\n   webViewController?.loadUrl(\n   urlRequest: URLRequest(\n   url: WebUri(\"http:\/\/localhost:8080\/html\/${pages[index]}\"),\n   ),\n );\n},\n labelType: NavigationRailLabelType.all,\n backgroundColor: Colors.transparent, \n destinations: const [\n NavigationRailDestination(icon: Icon(Icons.home), label: Text('Home')),\n NavigationRailDestination(icon: Icon(Icons.settings), label: Text('Settings')),\n NavigationRailDestination(icon: Icon(Icons.favorite), label: Text('Category C')),\n ],\n),\n const VerticalDivider(thickness: 1, width: 1),\n   \/\/ \u30e1\u30a4\u30f3\u30b3\u30f3\u30c6\u30f3\u30c4 (WebView)\n Expanded(\n  child: InAppWebView(\n  initialUrlRequest: URLRequest(\n\/\/ url: WebUri(\"http:\/\/localhost:8080\/html\/index1.html\")\n  url: WebUri(\"http:\/\/localhost:8080\/html\/${pages[selectedIndex]}\"),\n ),\n onWebViewCreated: (controller) {\n   webViewController = controller;\n  },\n  ),\n  ),\n  ],\n ),\n );\n}\n@override\n void dispose() {\n  \/\/ \u30b5\u30fc\u30d0\u30fc\u306e\u505c\u6b62\n ref.read(localhostServerProvider).close();\n super.dispose();\n }\n}\n\n\/\/<application>\u30bf\u30b0\u306e\u5c5e\u6027\u306b\n\/\/android:usesCleartextTraffic=\"true\"\n\/\/\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002\u3053\u3046\u3059\u308b\u3068\u3001\n\/\/Android\u30a2\u30d7\u30ea\u304b\u3089\u306e\u3059\u3079\u3066\u306e\u901a\u4fe1\u3067HTTP\u304c\u8a31\u53ef\u3055\u308c\u307e\u3059\u3002\n \/\/flutter_inappwebview: ^6.1.5\n \/\/ assets:\n \/\/   - html\/index2.html\n \/\/   - html\/joy\/assets\/\n \/\/   - html\/joy\/index.html\n \/\/   - html\/index1.html\n \/\/   - html\/css\/\n \/\/   - html\/js\/\n\/\/    - html\/index3.html  \n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>main.dart import &#8216;package <a href=\"https:\/\/tate.stars.ne.jp\/wpb\/inappweb2.html\" class=\"btn btn-link continue-link\">\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":53,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"saved_in_kubio":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-72","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dart"],"_links":{"self":[{"href":"https:\/\/tate.stars.ne.jp\/wpb\/wp-json\/wp\/v2\/posts\/72","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tate.stars.ne.jp\/wpb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tate.stars.ne.jp\/wpb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tate.stars.ne.jp\/wpb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tate.stars.ne.jp\/wpb\/wp-json\/wp\/v2\/comments?post=72"}],"version-history":[{"count":1,"href":"https:\/\/tate.stars.ne.jp\/wpb\/wp-json\/wp\/v2\/posts\/72\/revisions"}],"predecessor-version":[{"id":73,"href":"https:\/\/tate.stars.ne.jp\/wpb\/wp-json\/wp\/v2\/posts\/72\/revisions\/73"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tate.stars.ne.jp\/wpb\/wp-json\/wp\/v2\/media\/53"}],"wp:attachment":[{"href":"https:\/\/tate.stars.ne.jp\/wpb\/wp-json\/wp\/v2\/media?parent=72"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tate.stars.ne.jp\/wpb\/wp-json\/wp\/v2\/categories?post=72"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tate.stars.ne.jp\/wpb\/wp-json\/wp\/v2\/tags?post=72"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}