패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.0.4

shark

모바일 애플리케이션용 플러터 서버 렌더링 프레임워크, 서버 기반 UI, 실시간으로 인터페이스를 동적으로 변경

AndroidiOSmacOSWindowsLinux
30일 다운로드
58
좋아요
56
Pub 점수
130

패키지 설치

flutter pub add shark

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Shark은 모바일 애플리케이션을 위한 서버 기반 UI를 가능하게 하는 Flutter 서버 렌더링 프레임워크입니다. 서버에서 UI 컴포넌트를 동적으로 렌더링함으로써 실시간 인터페이스 업데이트를 가능하게 하며, 앱 재배포 없이도 원활한 변경이 가능합니다. Android, iOS, macOS, Windows, Linux용으로 설계되었으며, 백엔드 로직과 프론트엔드 표현 사이의 격차를 메웁니다. 개발자는 서버에서 UI 상태와 레이아웃을 관리하여 다양한 플랫폼에서 유연하고 반응성 있는 경험을 제공할 수 있습니다. 빠른 반복과 중앙 집중식 UI 제어가 필요한 팀에게 이상적입니다.

사용 사례

  • 실시간 UI 업데이트
  • 서버 기반 사용자 인터페이스
  • 동적 콘텐츠 전달
  • 크로스 플랫폼 모바일 앱
  • 빠른 UI 반복

주요 기능

  • 서버 렌더링된 UI
  • 실시간 인터페이스 변경
  • 다중 플랫폼 지원
  • 중앙 집중형 UI 관리
  • Flutter 통합

적합한 대상

  • 백엔드 중심 워크플로우를 갖춘 팀
  • 자주 UI 업데이트가 필요한 앱
  • 모바일용으로 플러터를 사용하는 개발자
  • 동적 콘텐츠를 가진 프로젝트
  • 서버 기반 디자인 패턴

고려 사항

  • 호환되는 서버 설정이 필요합니다
  • 안정적인 네트워크 연결에 의존합니다
  • 서버 기반 아키텍처의 학습 곡선
  • 제한된 오프라인 기능
  • 주의 깊은 상태 동기화가 필요합니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Shark Flutter 🦈 (Official)

pub package CodeFactor build

A Flutter server rendering framework

What it is

Shark is a server rendering framework, a server-driven UI framework.

Simple use case of shark

Let say you have a text widget, you specify it as json on the server return to the client, the client use shark to receive the text widget and show the UI successfully.

After a while, you want to change the text widget to a button, instead of modify it on the client code and go through all the mobile app store updating process, you only need to modify the text widget to a button widget on the server, and the shark client received it, showed the newest UI.

Project diagram
Guide

How to use

First, init Shark library on main method on your application

  void main() {
    WidgetsFlutterBinding.ensureInitialized();
    await Shark.init(hostUrl: 'http://yourhost.com');

    runApp(MyApp());
  }

Second, set up UI widget

  • To be noticed, every thing related to widget is controlled by SharkController
  • fromUrl method would send a REST api request to your server, which indicates the path from your current url.
  • get method is where we send the request
  late final SharkController _controller;

  /// init the shark controller
  @override
  void initState() {
    _controller = SharkController.fromUrl(path: '/container',)..get();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return SharkWidget(controller: _controller);
  }

To redirect to another page, call redirect

_controller.redirect('/your_new_path');

To refresh current page, call refresh

_controller.refresh();

If you want to create your own parser

class MyCustomParser extends SharkParser {}

Routing

shark auto handles your page routing, if you do not want it, set handleClickEvent to false

 _sharkController = SharkController('/your_path', handleClickEvent: false);
Click Event

Routing trigger by click event, which you can set it like this on your json widget file.

A sample event json format

    {
        "type": "container",
        "click_event": "route://your_path?xxx=xxx"
    }
  • schema: $yourschema://

  • path: your_path

  • argument: After the prefix '?' is the argument field. xxx=xxx, separate with &

sample:

"click_event": "route://second_page?name=hello&place=world"  
The schema represents the routing action

Currently, there are 4 routing action

route: prefix with route://, internally would call Navigator.pushName('new_path', args)

Push a new route to Navigator

** Please remember to specify route path on your route map

   MaterialApp(
     onGenerateRoute: (RouteSettings settings) {
        String routePath = settings.name?.toString() ?? '';
        if (baseRoute.containsKey(routePath)) {
          return MaterialPageRoute(
              settings: settings, builder: your_route_table[routeName]!);
        } else
          return null;
      },
     home: $yourhomepage,
   ),
  
  • pop: prefix with pop://, internally would call Navigator.pop(result)

  • redirect: prefix with redirect://, redirect current page with the following path

  • link: use url_launcher internally to open a url on browser, please visit url_launcher to configure the detail requirements for each platform

Caching

Shark use dio_cache_interceptor for caching purposes.

When you initialize the shark library, you can pass a cacheStrategy argument to config your caching setting.

Parsing

Note that Shark uses dynamic_widget for widget parsing,

If you want to create your own parser

class MyCustomParser extends SharkParser {}

Then add this new parser to shark widget

_sharkController.addParser(MyCustomParser());

To view the json format, go visit [documentation](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md) on dynamic_widget.

Localization

shark uses easy_localization for localization, follow the instructions to set up.

After setting up easy_localization package, next thing you need to do is to add a TranslatedTextParser to shark widget

TranslatedTextParser do all the localize work for you

_sharkController.addParse(TranslatedTextParser());

In your server json file, modify the text tag to translatedText

{
    "type": "Text",
    "data": "Redirect To next page"
}

To

{
    "type": "TranslatedText",
    "data": "Redirect To next page"
}

data value should be the value corresponds to your translations json file key

sample translations file zh.json

{
  "Navigate To next page":"push路由,转入下一页",
  "Redirect To next page": "转换至另一页",
  "To goog.gl": "去谷歌"
}

That's it ~~



OTHER

You can also view the express server sample, you can deploy to heroku fast

or you can test it on this temporary host =(little slow)

https://shark-sample-server.herokuapp.com/

Real world sample

(Promotion 😂)

My new meditation app had implemented shark recently, the profile page is handled by shark completely.

https://seasonnatural.netlify.app/



My work email : lauchuen94@gmail.com

카테고리

의존성

의존성 목록 7 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.