创建mixin
import 'package:flutter/material.dart';
mixin JobsMixin<T extends StatefulWidget> on State<T> {
@override
void initState() {
super.initState();
}
int page = 1;
bool isLoading = false;
List<JobData> jobs = [];
Future<List<JobData>> getJobs(String city, [String searchValue = '']) async {
// ...
}
loadMoreJobs(String city, [String searchValue = '']) async {
// ...
}
}
使用
class SearchView extends StatefulWidget {
@override
_SearchViewState createState() => _SearchViewState();
}
class _SearchViewState extends State<SearchView> with JobsMixin<SearchView> {
// ...
}
class JobsTab extends StatefulWidget {
@override
JobsTabState createState() => JobsTabState();
}
class JobsTabState extends State<JobsTab> with JobsMixin<JobsTab> {
// ...
}