Skip to content

Commit

Permalink
feat: Added refresh-indicator refreshed listview json from the remote…
Browse files Browse the repository at this point in the history
… url
  • Loading branch information
i-asimkhan committed Jan 18, 2024
1 parent 90f5aa6 commit 6c8c9fd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 30 deletions.
12 changes: 6 additions & 6 deletions examples/mirai_gallery/assets/json/home_screen.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -668,7 +668,7 @@
"navigationStyle": "push",
"widgetJson": {
"type": "exampleScreen",
"assetPath": "assets/json/row_example.json"
"assetPath": "assets/json/refresh_indicator_example.json"
}
}
},
Expand All @@ -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
}
Expand All @@ -699,7 +699,7 @@
"navigationStyle": "push",
"widgetJson": {
"type": "exampleScreen",
"assetPath": "assets/json/refresh_indicator_example.json"
"assetPath": "assets/json/row_example.json"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:mirai/mirai.dart';
Expand Down Expand Up @@ -29,13 +31,13 @@ class _RefreshIndicatorWidget extends StatefulWidget {
}

class _RefreshIndicatorWidgetState extends State<_RefreshIndicatorWidget> {
dynamic childWidget;
Map<String, dynamic>? childWidgetJson;

@override
void initState() {
super.initState();

childWidget = widget.model.child;
childWidgetJson = widget.model.child;
}

@override
Expand All @@ -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<String, dynamic>) {
setState(() {
childWidget = Mirai.fromJson(result.data, context);
});
if (result.data != null) {
if (result.data is Map<String, dynamic>) {
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(),
);
}
}

0 comments on commit 6c8c9fd

Please sign in to comment.