Skip to content

Instantly share code, notes, and snippets.

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
void main() => runApp(MaterialApp( home: DemoApp()));
class DemoApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final class WebViewWrapper : UIViewRepresentable {
@ObservedObject var webViewStateModel: WebViewStateModel //action two way binding
let action: ((_ navigationAction: WebView.NavigationAction) -> Void)? //delegates callback
let request: URLRequest
init(webViewStateModel: WebViewStateModel,
action: ((_ navigationAction: WebView.NavigationAction) -> Void)?,
request: URLRequest) {
self.action = action
final class WebViewWrapper : UIViewRepresentable {
...
final class Coordinator: NSObject {
@ObservedObject var webViewStateModel: WebViewStateModel
let action: ((_ navigationAction: WebView.NavigationAction) -> Void)?
init(action: ((_ navigationAction: WebView.NavigationAction) -> Void)?,
webViewStateModel: WebViewStateModel) {
self.action = action
self.webViewStateModel = webViewStateModel
class WebViewStateModel: ObservableObject {
@Published var pageTitle: String = "Web View"
@Published var loading: Bool = false
@Published var canGoBack: Bool = false
@Published var goBack: Bool = false
}
struct WebView: View {
enum NavigationAction {
case decidePolicy(WKNavigationAction, (WKNavigationActionPolicy) -> Void) //mendetory
struct ContentView: View {
@ObservedObject var webViewStateModel: WebViewStateModel = WebViewStateModel()
var body: some View {
NavigationView {
LoadingView(isShowing: .constant(webViewStateModel.loading)) { //loading logic taken from https://stackoverflow.com/a/56496896/9838937
//Add onNavigationAction if callback needed
WebView(url: URL.init(string: "https://www.google.com")!, webViewStateModel: self.webViewStateModel) // add
}
.navigationBarTitle(Text(webViewStateModel.pageTitle), displayMode: .inline)
import SwiftUI
import WebKit
struct ContentView: View {
@ObservedObject var webViewStateModel: WebViewStateModel = WebViewStateModel()
var body: some View {
NavigationView {
LoadingView(isShowing: .constant(webViewStateModel.loading)) { //loading logic taken from https://stackoverflow.com/a/56496896/9838937
//Add onNavigationAction if callback needed
import SwiftUI
import UIKit
struct Result: Identifiable {
var id = UUID()
var value: String
}
class RefreshableObject: ObservableObject {
class AdaptableText extends StatelessWidget {
final String text;
final TextStyle style;
final TextAlign textAlign;
final TextDirection textDirection;
final double minimumFontScale;
final TextOverflow textOverflow;
const AdaptableText(this.text,
{this.style,
this.textAlign = TextAlign.left,
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
MyApp({Key key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Title", textAlign: TextAlign.center),
content: Text("orem ipsum dolor sit amet, consectetur adipiscing elit. Aenean in congue nisi. Morbi tincidunt est id nibh dapibus, non pulvinar sem sollicitudin. Duis libero quam, posuere non justo non, facilisis sodales elit. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam sit amet dolor ut sem lobortis commodo id et nunc.",textAlign: TextAlign.center),
actions: <Widget>[
FlatButton(
child: Text("This is veary long Text"),
onPressed: () {