Giter Club home page Giter Club logo

local_assets_server's Introduction

local_assets_server

lesnitsky.dev GitHub stars Twitter Follow

HTTP Server which serves local assets

Installation

pubspec.yaml:

dependencies:
  local_assets_server: ^2.0.2+10

Example

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:local_assets_server/local_assets_server.dart';
import 'package:webview_flutter/webview_flutter.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Local Assets Server Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Local Assets Server Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  final String title;

  MyHomePage({Key? key, required this.title}) : super(key: key);

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

class _MyHomePageState extends State<MyHomePage> {
  bool isListening = false;
  String? address;
  int? port;
  WebViewController? controller;

  void _incrementCounter() {
    controller?.evaluateJavascript('window.increment()');
  }

  @override
  initState() {
    _initServer();
    super.initState();
  }

  _initServer() async {
    final server = new LocalAssetsServer(
      address: InternetAddress.loopbackIPv4,
      assetsBasePath: 'web',
      logger: DebugLogger(),
    );

    final address = await server.serve();

    setState(() {
      this.address = address.address;
      port = server.boundPort!;
      isListening = true;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: isListening
          ? WebView(
              debuggingEnabled: true,
              initialUrl: 'http://$address:$port',
              javascriptMode: JavascriptMode.unrestricted,
              onWebViewCreated: (c) {
                controller = c;
              },
            )
          : Center(child: CircularProgressIndicator()),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

License

MIT

local_assets_server's People

Contributors

junglerobba avatar lesnitsky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

local_assets_server's Issues

example not working under windows

the example is not working under windows,
due to the unexpected behaviour of join()

workaround: change
assetsBasePath: 'web',
to
assetsBasePath: 'web/',

I suggest to not use join() in local_assets_server.dart (i.e. line 128)

Logging?

Hi,
I'm just wondering if there is some option to get some logging in the debug console, mostly about what resources are being requested and which response code was sent? So maybe something like this:
GET /index.html 200
GET /folder-i-forgot-to-include-in-assets/picture.jpg 404

That would be a tremendous help in getting past some of the first hurdles using this :)

host flutter web locally from mobile

Hey , can we host our flutter web App by this plugin from Android , so that we can start a local server from mobile , and devices under my wifi can open that hosted flutter web app ??
basically whole idea is to share mobiles videos and photos by using local server , and flutter web for a userInterface of transferring data

Security

First, I like to thank you, it's a very handy plugin, thanks a lot !

I found out that when the app is running, you can open the Android browser, go to http://127.0.0.1:xxx/ and you can see the page.
Fortunately the port changes everytime, but isn't this a security breach ?

local_assets_server.dart is legacy

Hello
I've got a warning in my IDE :

The library 'package:local_assets_server/local_assets_server.dart' is legacy, and should not be imported into a null safe library.

any plans to support null safe ?

Web Page not available

Please Help me-

IMG_20200706_012511

First Error-
Launching lib\main.dart on Redmi Note 7 in debug mode...
โˆš Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk... 10.1s
W/Looper ( 2110): Slow Looper main: Activity com.example.web_test/.MainActivity is 2121ms late (wall=2470ms running=0ms ClientTransaction{ callbacks=[android.app.servertransaction.LaunchActivityItem] lifecycleRequest=android.app.servertransaction.ResumeActivityItem }) because of 1 msg, msg 1 took 2217ms (late=1ms h=android.app.ActivityThread$H w=110)
I/OpenGLRenderer( 2110): Initialized EGL, version 1.4
D/OpenGLRenderer( 2110): Swap behavior 2
Connecting to VM Service at ws://127.0.0.1:61689/esN3ST4Q62g=/ws
I/xample.web_tes( 2110): ProcessProfilingInfo new_methods=519 is saved saved_to_disk=1 resolve_classes_delay=8000
W/xample.web_tes( 2110): Verification of void io.flutter.plugin.platform.VirtualDisplayController.(android.content.Context, io.flutter.plugin.platform.AccessibilityEventsDelegate, android.hardware.display.VirtualDisplay, io.flutter.plugin.platform.PlatformViewFactory, android.view.Surface, io.flutter.view.TextureRegistry$SurfaceTextureEntry, android.view.View$OnFocusChangeListener, int, java.lang.Object) took 117.399ms
I/WebViewFactory( 2110): Loading com.android.chrome version 83.0.4103.106 (code 410410673)
W/xample.web_tes( 2110): Verification of void mn.(android.webkit.WebViewDelegate) took 106.393ms
I/xample.web_tes( 2110): Background concurrent copying GC freed 16067(928KB) AllocSpace objects, 2(40KB) LOS objects, 49% free, 2MB/4MB, paused 2.659ms total 135.141ms
I/cr_LibraryLoader( 2110): Loaded native library version number "83.0.4103.106"
I/cr_CachingUmaRecorder( 2110): Flushed 3 samples from 3 histograms.
W/xample.web_tes( 2110): Accessing hidden field Ljava/nio/Buffer;->address:J (light greylist, reflection)
W/xample.web_tes( 2110): Accessing hidden method Landroid/content/Context;->bindServiceAsUser(Landroid/content/Intent;Landroid/content/ServiceConnection;ILandroid/os/Handler;Landroid/os/UserHandle;)Z (light greylist, reflection)
W/chromium( 2110): [WARNING:dns_config_service_posix.cc(341)] Failed to read DnsConfig.
D/EgretLoader( 2110): EgretLoader(Context context)
D/EgretLoader( 2110): The context is not activity
W/xample.web_tes( 2110): Accessing hidden method Landroid/media/AudioManager;->getOutputLatency(I)I (light greylist, reflection)
W/cr_media( 2110): Requires BLUETOOTH permission
W/ContentCatcher( 2110): Failed to notify a WebView
W/VideoCapabilities( 2110): Unsupported mime video/divx
W/VideoCapabilities( 2110): Unsupported mime video/divx311
W/VideoCapabilities( 2110): Unsupported mime video/divx4
W/VideoCapabilities( 2110): Unrecognized profile 4 for video/hevc
W/VideoCapabilities( 2110): Unrecognized profile/level 0/3 for video/mpeg2
W/VideoCapabilities( 2110): Unrecognized profile/level 0/3 for video/mpeg2
I/VideoCapabilities( 2110): Unsupported profile 4 for video/mp4v-es
W/Utils ( 2110): could not parse long range '175-174'
D/NetworkSecurityConfig( 2110): No Network Security Config specified, using platform default
W/Looper ( 2110): Slow Looper main: doFrame is 391ms late because of 6 msg, msg 1 took 318ms (late=1ms h=android.view.Choreographer$FrameHandler c=android.view.Choreographer$FrameDisplayEventReceiver)

Second Error-
W/ContentCatcher(29962): Failed to notify a WebView
E/chromium(29962): [ERROR:aw_browser_terminator.cc(125)] Renderer process (30308) crash detected (code -1).
Restarted application in 1,886ms.
D/EgretLoader(29962): EgretLoader(Context context)
D/EgretLoader(29962): The context is not activity
W/ContentCatcher(29962): Failed to notify a WebView
W/System (29962): A resource failed to call release.
W/Looper (29962): Slow Looper main: Activity com.example.web_test/.MainActivity is 353ms late (wall=369ms running=0ms ClientTransaction{ lifecycleRequest=android.app.servertransaction.ResumeActivityItem }) because of 2 msg, msg 1 took 253ms (late=2ms h=android.view.Choreographer$FrameHandler c=android.view.Choreographer$FrameDisplayEventReceiver)

Help me to solve this

Does not work on Windows (404 error)

Hi,

I tried to use this amazing package on a Android/iOS/Windows app, and while I didn't encounter any issues for Android/iOS, this does not seems to work on Windows. I always get a 404 http error.

I tried with a simple http GET query in the app and and via the webview_windows plugin, both end up with the same 404 error.

Do you have any idea? Is it a known issue?

possible to load assets from outside of the assets dir?

Is it possible to serve local assets that have been saved to the app's temp directory rather than through the asset bundle?

Here's the scenario: basically, I'm trying to take advantage of an existing Javascript library to be able to annotate images taken through the app. I basically need to be able to take a photo in the app and then "inject" that into a webview so I can utilize this javascript library to make annotations.

Would this be possible with your package?

Thank you in advance ๐Ÿ™Œ

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.