kraken 0.9.0-dev.4 copy "kraken: ^0.9.0-dev.4" to clipboard
kraken: ^0.9.0-dev.4 copied to clipboard

outdated

A high-performance, web standards-compliant rendering engine.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:kraken/kraken.dart';
import 'package:kraken/dom.dart' as dom;
import 'dart:ffi';
import 'package:kraken/bridge.dart';
// import 'package:kraken_websocket/kraken_websocket.dart';
// import 'package:kraken_devtools/kraken_devtools.dart';
import 'dart:ui';

void main() {
  defineKrakenCustomElements();
  // KrakenWebsocket.initialize();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Kraken Browser',
      // theme: ThemeData.dark(),
      home: MyBrowser(),
    );
  }
}


void defineKrakenCustomElements() {
  Kraken.defineCustomElement<dom.ElementCreator>('sample-element', (int targetId, Pointer<NativeEventTarget> nativeEventTarget, dom.ElementManager elementManager) {
    return SampleElement(targetId, nativeEventTarget, elementManager);
  });
}

class SampleElement extends dom.Element {
  SampleElement(int targetId, Pointer<NativeEventTarget> nativeEventTarget, dom.ElementManager elementManager)
      : super(targetId, nativeEventTarget, elementManager, tagName: 'sample-element');

  @override
  handleJSCall(String method, List argv) {

  }

  @override
  void setProperty(String key, value) {
    print('key: $key, value: $value');
    super.setProperty(key, value);
  }

  @override
  getProperty(String key) {
    switch(key) {
      case 'ping':
        return 'pong';
      case 'fn':
        return (List<dynamic> args) {
          return List.generate(args.length, (index) {
            return args[index] * 2;
          });
        };
    }

    return super.getProperty(key);
  }
}


class MyBrowser extends StatefulWidget {
  MyBrowser({Key? key, this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String? title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyBrowser> {

  OutlineInputBorder outlineBorder = OutlineInputBorder(
    borderSide: BorderSide(color: Colors.transparent, width: 0.0),
    borderRadius: const BorderRadius.all(
      Radius.circular(20.0),
    ),
  );

  @override
  Widget build(BuildContext context) {
    final MediaQueryData queryData = MediaQuery.of(context);
    final TextEditingController textEditingController = TextEditingController();

    Kraken? _kraken;
    AppBar appBar = AppBar(
        backgroundColor: Colors.black87,
        titleSpacing: 10.0,
        title: Container(
          height: 40.0,
          child: TextField(
            controller: textEditingController,
            onSubmitted: (value) {
              textEditingController.text = value;
              _kraken?.loadURL(value);
            },
            decoration: InputDecoration(
              hintText: 'Enter a app url',
              hintStyle: TextStyle(color: Colors.black54, fontSize: 16.0),
              contentPadding: const EdgeInsets.all(10.0),
              filled: true,
              fillColor: Colors.grey,
              border: outlineBorder,
              focusedBorder: outlineBorder,
              enabledBorder: outlineBorder,
            ),
            style: TextStyle(color: Colors.black, fontSize: 16.0),
          ),
        ),
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
      );

    final Size viewportSize = queryData.size;
    return Scaffold(
        appBar: appBar,
        body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: _kraken = Kraken(
          viewportWidth: viewportSize.width - queryData.padding.horizontal,
          viewportHeight: viewportSize.height - appBar.preferredSize.height - queryData.padding.vertical,
          bundleURL: 'assets/bundle.js',
        ),
    ));
  }
}
32
likes
0
pub points
39%
popularity

Publisher

verified publisheropenkraken.com

A high-performance, web standards-compliant rendering engine.

Homepage

License

unknown (license)

Dependencies

async, connectivity, device_info, ffi, flutter, meta, path, shared_preferences, vector_math

More

Packages that depend on kraken