1+ import 'package:android_tool/page/common/package_help_mixin.dart' ;
12import 'package:android_tool/widget/text_view.dart' ;
23import 'package:flutter/material.dart' ;
34import 'package:flutter/rendering.dart' ;
45import 'package:provider/provider.dart' ;
56import 'package:selector_plus/selector_plus.dart' ;
7+ import 'package:shared_preferences/shared_preferences.dart' ;
68
79class ListFilterDialog <T extends ListFilterItem > extends StatefulWidget {
810 final ListFilterController controller;
911
1012 final String ? title;
1113 final String ? tipText;
1214 final String ? notFoundText;
15+ final bool isSelectApp;
1316 final Function ()? refreshCallback;
1417
1518 const ListFilterDialog ({
@@ -18,6 +21,7 @@ class ListFilterDialog<T extends ListFilterItem> extends StatefulWidget {
1821 this .title,
1922 this .tipText,
2023 this .notFoundText,
24+ this .isSelectApp = false ,
2125 this .refreshCallback,
2226 }) : super (key: key);
2327
@@ -126,13 +130,38 @@ class _ListFilterDialogState<T extends ListFilterItem>
126130 },
127131 selector: widget.controller.selectorList,
128132 ),
133+ Offstage (
134+ offstage: ! widget.isSelectApp,
135+ child: _buildShowSelectSystemAppView (),
136+ ),
129137 ],
130138 ),
131139 ),
132140 ),
133141 );
134142 });
135143 }
144+
145+ Widget _buildShowSelectSystemAppView () {
146+ return Row (
147+ mainAxisAlignment: MainAxisAlignment .end,
148+ children: [
149+ const TextView ("显示系统应用" ),
150+ Selector <ListFilterController , bool >(
151+ selector: (context, controller) => controller._isShowSystemApp,
152+ builder: (context, isFilter, child) {
153+ return Checkbox (
154+ value: isFilter,
155+ onChanged: (value) async {
156+ await widget.controller._setShowSystemApp (value ?? false );
157+ widget.refreshCallback? .call ();
158+ },
159+ );
160+ },
161+ )
162+ ],
163+ );
164+ }
136165}
137166
138167class ListFilterItem {
@@ -150,6 +179,8 @@ class ListFilterController<T extends ListFilterItem> extends ChangeNotifier {
150179
151180 T ? current;
152181
182+ bool _isShowSystemApp = false ;
183+
153184 ListFilterController () {
154185 controller.addListener (() {
155186 if (controller.text.isEmpty) {
@@ -172,28 +203,51 @@ class ListFilterController<T extends ListFilterItem> extends ChangeNotifier {
172203 String ? title,
173204 String ? tipText,
174205 String ? notFoundText,
206+ bool isSelectApp = false ,
175207 Function ()? refreshCallback,
176208 }) async {
177209 dataList = data;
178210 selectorList.value = data;
179211 this .current = current;
212+ if (isSelectApp) {
213+ _getIsShowSystemApp ();
214+ }
180215 return await showDialog <T >(
181216 context: context,
182217 builder: (context) => ListFilterDialog (
183218 controller: this ,
184219 title: title,
185220 tipText: tipText,
186221 notFoundText: notFoundText,
222+ isSelectApp: isSelectApp,
187223 refreshCallback: refreshCallback,
188224 ),
189225 );
190226 }
191227
192- void setData (List <T > data) {
228+ void setData (List <T > data, {T ? current}) {
229+ if (current != null ) {
230+ this .current = current;
231+ }
193232 dataList = data;
194233 selectorList.value = dataList
195234 .where ((element) => element.itemTitle.contains (controller.text))
196235 .toList ();
197236 notifyListeners ();
198237 }
238+
239+ _setShowSystemApp (bool bool ) async {
240+ _isShowSystemApp = bool ;
241+ notifyListeners ();
242+ var prefs = await SharedPreferences .getInstance ();
243+ prefs.setBool (PackageHelpMixin .isShowSystemApp, bool );
244+ }
245+
246+ void _getIsShowSystemApp () {
247+ SharedPreferences .getInstance ().then ((value) {
248+ _isShowSystemApp =
249+ value.getBool (PackageHelpMixin .isShowSystemApp) ?? false ;
250+ notifyListeners ();
251+ });
252+ }
199253}
0 commit comments