-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build WebView and add preserve state on switching
- Loading branch information
Showing
6 changed files
with
149 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,79 @@ | ||
import 'dart:io'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; | ||
import 'package:webview_flutter/webview_flutter.dart'; | ||
|
||
class WebView extends StatefulWidget { | ||
const WebView({Key? key}) : super(key: key); | ||
import '../HomeScreen.dart'; | ||
|
||
import './newsList.dart'; | ||
|
||
class WebViewPage extends StatefulWidget { | ||
// const WebViewPage({Key? key}) : super(key: key); | ||
var jsonData; | ||
WebViewPage(this.jsonData); | ||
|
||
@override | ||
State<WebView> createState() => _WebViewState(); | ||
State<WebViewPage> createState() => _WebViewPageState(jsonData); | ||
} | ||
|
||
class _WebViewState extends State<WebView> { | ||
class _WebViewPageState extends State<WebViewPage> { | ||
var jsonData; | ||
_WebViewPageState(this.jsonData); | ||
|
||
void action(String choice) { | ||
print('Working...'); | ||
} | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
if (Platform.isAndroid) WebView.platform = AndroidWebView(); | ||
} | ||
|
||
Widget TopBar() { | ||
return Container( | ||
color: Colors.black, | ||
width: MediaQuery.of(context).size.width, | ||
height: 35, | ||
child: Align( | ||
alignment: Alignment.centerRight, | ||
child: PopupMenuButton<String>( | ||
onSelected: action, | ||
itemBuilder: (context) { | ||
return PopUpMenuData.Menu.map((String choice) { | ||
return PopupMenuItem<String>( | ||
value: choice, | ||
child: Text(choice), | ||
); | ||
}).toList(); | ||
}), | ||
)); | ||
} | ||
|
||
Widget build(BuildContext context) { | ||
return Center(child: Text('WebView'),); | ||
return Scaffold( | ||
body: Column( | ||
children: [ | ||
TopBar(), | ||
Expanded( | ||
child: WebView( | ||
// initialUrl: jsonData["articles"][0]["url"], | ||
initialUrl: jsonData["articles"][HomeScreen.newsIndex]["url"], | ||
javascriptMode: JavascriptMode.unrestricted, | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} | ||
} | ||
|
||
class PopUpMenuData { | ||
static const String copyLink = 'Copy link'; | ||
static const String browser = 'Open in browser'; | ||
|
||
static const List<String> Menu = <String>[ | ||
copyLink, | ||
browser, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters