From 6c8c9fdf69d7846051f0c19d6d43695ae877679d Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Thu, 18 Jan 2024 16:33:10 +0400 Subject: [PATCH] feat: Added refresh-indicator refreshed listview json from the remote url --- .../assets/json/home_screen.json | 12 +++---- .../json/refresh_indicator_example.json | 10 ++---- .../mirai_refresh_indicator_parser.dart | 32 +++++++++---------- 3 files changed, 24 insertions(+), 30 deletions(-) diff --git a/examples/mirai_gallery/assets/json/home_screen.json b/examples/mirai_gallery/assets/json/home_screen.json index 863c2cff..a299a946 100644 --- a/examples/mirai_gallery/assets/json/home_screen.json +++ b/examples/mirai_gallery/assets/json/home_screen.json @@ -650,14 +650,14 @@ }, "title": { "type": "text", - "data": "Mirai Row", + "data": "Mirai Refresh Indicator", "style": { "fontSize": 21 } }, "subtitle": { "type": "text", - "data": "Layout a list of child widgets in the horizontal direction", + "data": "A widget that supports the Material \"swipe to refresh\" idiom.", "style": { "fontSize": 12 } @@ -668,7 +668,7 @@ "navigationStyle": "push", "widgetJson": { "type": "exampleScreen", - "assetPath": "assets/json/row_example.json" + "assetPath": "assets/json/refresh_indicator_example.json" } } }, @@ -681,14 +681,14 @@ }, "title": { "type": "text", - "data": "Mirai Refresh Indicator", + "data": "Mirai Row", "style": { "fontSize": 21 } }, "subtitle": { "type": "text", - "data": "Refresh Indicator", + "data": "Layout a list of child widgets in the horizontal direction", "style": { "fontSize": 12 } @@ -699,7 +699,7 @@ "navigationStyle": "push", "widgetJson": { "type": "exampleScreen", - "assetPath": "assets/json/refresh_indicator_example.json" + "assetPath": "assets/json/row_example.json" } } }, diff --git a/examples/mirai_gallery/assets/json/refresh_indicator_example.json b/examples/mirai_gallery/assets/json/refresh_indicator_example.json index 55485178..478bc1d9 100644 --- a/examples/mirai_gallery/assets/json/refresh_indicator_example.json +++ b/examples/mirai_gallery/assets/json/refresh_indicator_example.json @@ -4,20 +4,16 @@ "type": "appBar", "title": { "type": "text", - "data": "Align" + "data": "Refresh Indicator" } }, "body": { "type": "refreshIndicator", "onRefresh": { "actionType": "request", - "url": "https://active-money-mirai-default-rtdb.firebaseio.com/screens/create_account.json", + "url": "https://raw.githubusercontent.com/Securrency-OSS/mirai/main/examples/mirai_gallery/assets/json/list_view_example.json", "method": "get", - "contentType": "application/json", - "data": { - "alt": "media", - "token": "9168291d-596a-4b6e-b337-3609781d9728" - } + "contentType": "application/json" }, "child": { "type": "listView", diff --git a/packages/mirai/lib/src/parsers/mirai_refresh_indicator/mirai_refresh_indicator_parser.dart b/packages/mirai/lib/src/parsers/mirai_refresh_indicator/mirai_refresh_indicator_parser.dart index deb085fc..142a617a 100644 --- a/packages/mirai/lib/src/parsers/mirai_refresh_indicator/mirai_refresh_indicator_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_refresh_indicator/mirai_refresh_indicator_parser.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:mirai/mirai.dart'; @@ -29,13 +31,13 @@ class _RefreshIndicatorWidget extends StatefulWidget { } class _RefreshIndicatorWidgetState extends State<_RefreshIndicatorWidget> { - dynamic childWidget; + Map? childWidgetJson; @override void initState() { super.initState(); - childWidget = widget.model.child; + childWidgetJson = widget.model.child; } @override @@ -47,24 +49,20 @@ class _RefreshIndicatorWidgetState extends State<_RefreshIndicatorWidget> { await Mirai.onCallFromJson(widget.model.onRefresh, context); if (context.mounted) { - if (result.data != null && result.data is Map) { - setState(() { - childWidget = Mirai.fromJson(result.data, context); - }); + if (result.data != null) { + if (result.data is Map) { + setState(() { + childWidgetJson = result.data; + }); + } else if (result.data is String) { + setState(() { + childWidgetJson = jsonDecode(result.data); + }); + } } } }, - child: Mirai.fromJson(childWidget, context) ?? const SizedBox(), - // child: ListView.builder( - // itemCount: 4, - // itemBuilder: (c, d) { - // return Text('data'); - // }, - // ), - // child: SingleChildScrollView( - // physics: AlwaysScrollableScrollPhysics(), - // child: Mirai.fromJson(model.child, context), - // ), + child: Mirai.fromJson(childWidgetJson, context) ?? const SizedBox(), ); } }