| { | |||||
| "id" : 1, | |||||
| "name" : "name", | |||||
| "description": "description", | |||||
| "isSelected": true | |||||
| } |
| import 'package:json_annotation/json_annotation.dart'; | |||||
| part 'ResourceHelper.g.dart'; | |||||
| @JsonSerializable() | |||||
| class ResourceHelper { | |||||
| ResourceHelper(); | |||||
| num id; | |||||
| String name; | |||||
| String description; | |||||
| bool isSelected; | |||||
| factory ResourceHelper.fromJson(Map<String,dynamic> json) => _$ResourceHelperFromJson(json); | |||||
| Map<String, dynamic> toJson() => _$ResourceHelperToJson(this); | |||||
| } |
| // GENERATED CODE - DO NOT MODIFY BY HAND | |||||
| part of 'ResourceHelper.dart'; | |||||
| // ************************************************************************** | |||||
| // JsonSerializableGenerator | |||||
| // ************************************************************************** | |||||
| ResourceHelper _$ResourceHelperFromJson(Map<String, dynamic> json) { | |||||
| return ResourceHelper() | |||||
| ..id = json['id'] as num | |||||
| ..name = json['name'] as String | |||||
| ..description = json['description'] as String | |||||
| ..isSelected = json['isSelected'] as bool; | |||||
| } | |||||
| Map<String, dynamic> _$ResourceHelperToJson(ResourceHelper instance) => | |||||
| <String, dynamic>{ | |||||
| 'id': instance.id, | |||||
| 'name': instance.name, | |||||
| 'description': instance.description, | |||||
| 'isSelected': instance.isSelected | |||||
| }; |
| export 'Plot.dart' ; | |||||
| export 'ResourceHelper.dart' ; |
| import 'package:farm_tpf/presentation/screens/actions/plant/sc_plant.dart'; | import 'package:farm_tpf/presentation/screens/actions/plant/sc_plant.dart'; | ||||
| import 'package:farm_tpf/presentation/screens/plot/sc_plot.dart'; | import 'package:farm_tpf/presentation/screens/plot/sc_plot.dart'; | ||||
| import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_detail.dart'; | import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_detail.dart'; | ||||
| import 'package:farm_tpf/presentation/screens/resources/sc_resource_helper.dart'; | |||||
| import 'package:flutter/material.dart'; | import 'package:flutter/material.dart'; | ||||
| class HomePage extends StatelessWidget { | class HomePage extends StatelessWidget { | ||||
| Navigator.of(context).push( | Navigator.of(context).push( | ||||
| MaterialPageRoute(builder: (_) => PlotListScreen())); | MaterialPageRoute(builder: (_) => PlotListScreen())); | ||||
| }), | }), | ||||
| MaterialButton( | |||||
| child: Text("ResourceHelperScreen"), | |||||
| onPressed: () { | |||||
| Navigator.of(context) | |||||
| .push(MaterialPageRoute( | |||||
| builder: (_) => ResourceHelperScreen( | |||||
| resourceName: "test", | |||||
| selectedPlotId: 1531, | |||||
| ), | |||||
| fullscreenDialog: false)) | |||||
| .then((value) { | |||||
| if (value != null) { | |||||
| print("Home: $value"); | |||||
| } | |||||
| }); | |||||
| }), | |||||
| ], | ], | ||||
| ), | ), | ||||
| ), | ), |
| import 'package:farm_tpf/data/repository/repository.dart'; | |||||
| import 'package:farm_tpf/models/index.dart'; | |||||
| import 'package:farm_tpf/presentation/custom_widgets/bottom_loader.dart'; | |||||
| import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart'; | |||||
| import 'package:farm_tpf/utils/bloc/infinity_scroll_bloc.dart'; | |||||
| import 'package:farm_tpf/utils/const_string.dart'; | |||||
| import 'package:flutter/material.dart'; | |||||
| import 'package:flutter_bloc/flutter_bloc.dart'; | |||||
| class ResourceHelperScreen extends StatefulWidget { | |||||
| final String resourceName; | |||||
| final int selectedPlotId; | |||||
| ResourceHelperScreen( | |||||
| {@required this.resourceName, @required this.selectedPlotId}); | |||||
| @override | |||||
| _ResourceHelperScreenState createState() => _ResourceHelperScreenState(); | |||||
| } | |||||
| class _ResourceHelperScreenState extends State<ResourceHelperScreen> { | |||||
| @override | |||||
| Widget build(BuildContext context) { | |||||
| return BlocProvider( | |||||
| create: (context) => | |||||
| InfinityScrollBloc(repository: Repository())..add(DataFetched()), | |||||
| child: HoldInfinityWidget( | |||||
| selectedPlotId: widget.selectedPlotId, | |||||
| ), | |||||
| ); | |||||
| } | |||||
| } | |||||
| class HoldInfinityWidget extends StatelessWidget { | |||||
| final int selectedPlotId; | |||||
| HoldInfinityWidget({@required this.selectedPlotId}); | |||||
| final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); | |||||
| @override | |||||
| Widget build(BuildContext context) { | |||||
| return Scaffold( | |||||
| key: _scaffoldKey, | |||||
| appBar: AppBar(title: Text("Chọn danh sách")), | |||||
| body: InfinityView( | |||||
| selectedPlotId: selectedPlotId, | |||||
| )); | |||||
| } | |||||
| } | |||||
| class InfinityView extends StatefulWidget { | |||||
| final int selectedPlotId; | |||||
| InfinityView({@required this.selectedPlotId}); | |||||
| @override | |||||
| _InfinityViewState createState() => _InfinityViewState(); | |||||
| } | |||||
| class _InfinityViewState extends State<InfinityView> { | |||||
| final _scrollController = ScrollController(); | |||||
| final _scrollThreshold = 250.0; | |||||
| InfinityScrollBloc _infinityScrollBloc; | |||||
| @override | |||||
| void initState() { | |||||
| _scrollController.addListener(() { | |||||
| final maxScroll = _scrollController.position.maxScrollExtent; | |||||
| final currentScroll = _scrollController.position.pixels; | |||||
| if (maxScroll - currentScroll < _scrollThreshold) { | |||||
| _infinityScrollBloc.add(DataFetched()); | |||||
| } | |||||
| }); | |||||
| _infinityScrollBloc = BlocProvider.of<InfinityScrollBloc>(context); | |||||
| super.initState(); | |||||
| } | |||||
| @override | |||||
| Widget build(BuildContext context) { | |||||
| return BlocBuilder<InfinityScrollBloc, InfinityScrollState>( | |||||
| builder: (context, state) { | |||||
| if (state is InfinityScrollFailure) { | |||||
| return Center(child: Text(label_error_get_data)); | |||||
| } | |||||
| if (state is InfinityScrollSuccess) { | |||||
| if (state.items.isEmpty) { | |||||
| return Center(child: Text(label_list_empty)); | |||||
| } | |||||
| Plot selectedPlot; | |||||
| List<Plot> plots = state.items.map((e) => e as Plot).toList(); | |||||
| plots.forEach((plot) { | |||||
| plot.id == widget.selectedPlotId ? selectedPlot = plot : Plot(); | |||||
| }); | |||||
| return RefreshIndicator( | |||||
| child: ListView.builder( | |||||
| itemBuilder: (BuildContext context, int index) { | |||||
| return index >= state.items.length | |||||
| ? BottomLoader() | |||||
| : ItemInfinityWidget( | |||||
| item: state.items[index], | |||||
| selectedPlot: selectedPlot, | |||||
| ); | |||||
| }, | |||||
| itemCount: state.hasReachedMax | |||||
| ? state.items.length | |||||
| : state.items.length + 1, | |||||
| controller: _scrollController, | |||||
| ), | |||||
| onRefresh: () async { | |||||
| _infinityScrollBloc.add(OnRefresh()); | |||||
| }); | |||||
| } | |||||
| return Center( | |||||
| child: LoadingListPage(), | |||||
| ); | |||||
| }, | |||||
| ); | |||||
| } | |||||
| @override | |||||
| void dispose() { | |||||
| _scrollController.dispose(); | |||||
| super.dispose(); | |||||
| } | |||||
| } | |||||
| class ItemInfinityWidget extends StatelessWidget { | |||||
| final Plot item; | |||||
| final Plot selectedPlot; | |||||
| const ItemInfinityWidget({Key key, @required this.item, this.selectedPlot}) | |||||
| : super(key: key); | |||||
| @override | |||||
| Widget build(BuildContext context) { | |||||
| return GestureDetector( | |||||
| child: Card( | |||||
| color: item.id % 3 == 0 ? Colors.white : Colors.greenAccent[100], | |||||
| child: Material( | |||||
| child: RadioListTile( | |||||
| title: Text(item.activityExecuteDate.toString()), | |||||
| subtitle: Text(item.id.toString()), | |||||
| value: item, | |||||
| groupValue: selectedPlot, | |||||
| onChanged: (Plot value) { | |||||
| print("selected value: ${value.id}"); | |||||
| Navigator.of(context).pop(value.id); | |||||
| }), | |||||
| )), | |||||
| onTap: () {}); | |||||
| } | |||||
| } |
| name: _fe_analyzer_shared | name: _fe_analyzer_shared | ||||
| url: "https://pub.dartlang.org" | url: "https://pub.dartlang.org" | ||||
| source: hosted | source: hosted | ||||
| version: "6.0.0" | |||||
| version: "7.0.0" | |||||
| analyzer: | analyzer: | ||||
| dependency: transitive | dependency: transitive | ||||
| description: | description: | ||||
| name: analyzer | name: analyzer | ||||
| url: "https://pub.dartlang.org" | url: "https://pub.dartlang.org" | ||||
| source: hosted | source: hosted | ||||
| version: "0.39.16" | |||||
| version: "0.39.17" | |||||
| archive: | archive: | ||||
| dependency: transitive | dependency: transitive | ||||
| description: | description: | ||||
| name: build_resolvers | name: build_resolvers | ||||
| url: "https://pub.dartlang.org" | url: "https://pub.dartlang.org" | ||||
| source: hosted | source: hosted | ||||
| version: "1.3.10" | |||||
| version: "1.3.11" | |||||
| build_runner: | build_runner: | ||||
| dependency: "direct dev" | dependency: "direct dev" | ||||
| description: | description: | ||||
| name: cli_util | name: cli_util | ||||
| url: "https://pub.dartlang.org" | url: "https://pub.dartlang.org" | ||||
| source: hosted | source: hosted | ||||
| version: "0.1.4" | |||||
| version: "0.2.0" | |||||
| code_builder: | code_builder: | ||||
| dependency: transitive | dependency: transitive | ||||
| description: | description: | ||||
| name: json_serializable | name: json_serializable | ||||
| url: "https://pub.dartlang.org" | url: "https://pub.dartlang.org" | ||||
| source: hosted | source: hosted | ||||
| version: "3.3.0" | |||||
| version: "3.4.0" | |||||
| keyboard_dismisser: | keyboard_dismisser: | ||||
| dependency: "direct main" | dependency: "direct main" | ||||
| description: | description: | ||||
| name: stream_transform | name: stream_transform | ||||
| url: "https://pub.dartlang.org" | url: "https://pub.dartlang.org" | ||||
| source: hosted | source: hosted | ||||
| version: "1.2.0" | |||||
| version: "0.0.20" | |||||
| string_scanner: | string_scanner: | ||||
| dependency: transitive | dependency: transitive | ||||
| description: | description: |