搜索插件、代码仓与 APP 分类

GitHub 代码仓hsbijarniya/ssr

ssr

SSR

ssr 项目封面
星标
11
复刻
2
最近推送(UTC)
2022年3月3日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

Server Side Rendering

A Backend-Driven UI toolkit, build your dynamic UI with json, and the json format is very similar with flutter widget code.

Install

1. Depend on it

Add this to your package's pubspec.yaml file:

dependencies:
  ssr: any
2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:ssr/ssr.dart';

Get started

You should use ServerSideRendering.build method to covert a json string into flutter widget. It will be time-consuming. so you'd better using FutureBuilder to build the UI.

import 'package:ssr/ssr.dart';

class PreviewPage extends StatelessWidget {
  final Map jsonMap;

  PreviewPage(this.jsonMap);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Preview"),
      ),
      body: ServerSideRendering.build(jsonMap, context),
    );
  }
}

How to implement for custom widgets

This is a RaisedButton widget parser.

import 'package:ssr/ssr.dart';
import 'package:flutter/material.dart';

ServerSideRendering.register('Alignment', {
  'bottomCenter': Alignment.bottomCenter,
  'bottomLeft': Alignment.bottomLeft,
  'bottomRight': Alignment.bottomRight,
  'center': Alignment.center,
  'centerLeft': Alignment.centerLeft,
  'centerRight': Alignment.centerRight,
  'topCenter': Alignment.topCenter,
  'topLeft': Alignment.topLeft,
  'topRight': Alignment.topRight,
});

ServerSideRendering.register('RaisedButton', ({Map args = const {}}) {
    return RaisedButton(
      color: args['color'],
      disabledColor: args['disabledColor'],
      disabledElevation: args['disabledElevation'],
      disabledTextColor: args['disabledTextColor'],
      elevation: args['elevation'],
      padding: args['padding'],
      splashColor: args['splashColor'],
      textColor: args['textColor'],
      child: args['child'],
      onPressed: () {
      },
    );
});

How to add a click listener

Add "click_event" property to your widget json definition. for example:

var raisedButton_json = {
    'Container': {
        'alignment': 'Alignment.center',
        'child': {
            'RaisedButton' : {
                'color': {
                    'Color': [0xFF00FF],
                },
                'textColor': {
                    'Color': [0x00FF00],
                },
                'splashColor' : {
                    'Color': [0x00FF00],
                },
                'click_event' : 'route://productDetail?goods_id=123',
                'child' : {
                    'Text': ['I am a button']
                }
            }
        }
    }
};

Widget Documents

Already completed widget/registery:

  • Alignment
  • AppBar
  • Color
  • Column
  • Container
  • Row
  • Scaffold
  • Text
  • TextOverflow
  • TextStyle
hsbijarniya GitHub avatar
GitHub 作者

hsbijarniya ↗

语言Dart

使用的依赖

依赖清单 3 项

  • flutter{"sdk":"flutter"}
  • flutter_test开发依赖{"sdk":"flutter"}
  • flutter_lints开发依赖^1.0.0

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗