123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- import 'package:cached_network_image/cached_network_image.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_easyrefresh/easy_refresh.dart';
- import 'package:get_it/get_it.dart';
- import 'package:provider/provider.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- import 'package:sport/bean/forum.dart';
- import 'package:sport/constant/ui.dart' show ui_padding, ui_margin_list;
- import 'package:sport/pages/social/search_page.dart';
- import 'package:sport/pages/social/user_friend_page.dart';
- import 'package:sport/provider/lib/provider_widget.dart';
- import 'package:sport/provider/lib/view_state.dart';
- import 'package:sport/provider/lib/view_state_lifecycle.dart';
- import 'package:sport/provider/message_model.dart';
- import 'package:sport/provider/social_index_model.dart';
- import 'package:sport/router/navigator_util.dart';
- import 'package:sport/router/routes.dart';
- import 'package:sport/widgets/appbar.dart';
- import 'package:sport/widgets/decoration.dart';
- import 'package:sport/widgets/error.dart';
- import 'package:sport/widgets/image.dart';
- import 'package:sport/widgets/loading.dart';
- import 'package:sport/widgets/misc.dart';
- import 'package:sport/widgets/page_resume.dart';
- import 'package:sport/widgets/space.dart';
- import 'package:umeng_common_sdk/umeng_common_sdk.dart';
- class SocialIndexPage extends StatefulWidget {
- @override
- createState() => _PageState();
- }
- class _PageState extends ViewStateLifecycle<SocialIndexPage, SocialIndexModel> with AutomaticKeepAliveClientMixin, PageResume {
- @override
- void didChangeDependencies() {
- super.didChangeDependencies();
- }
- @override
- void onResume() {
- super.onResume();
- }
- @override
- Widget build(BuildContext context) {
- super.build(context);
- return Scaffold(
- body: ProviderWidget<SocialIndexModel>(
- model: model,
- onModelReady: (model) => model.initData(),
- builder: (_, model, __) {
- return EasyRefresh.builder(
- controller: model.refreshController,
- enableControlFinishRefresh: true,
- onRefresh: () => model.refresh(),
- header: buildClassicalHeader(),
- builder: (context, physics, header, footer) {
- return CustomScrollView(
- physics: physics,
- slivers: <Widget>[
- buildSliverAppBar(context, "社区",
- backgroundColor: Theme.of(context).scaffoldBackgroundColor,
- canBack: false,
- actions: <Widget>[
- IconButton(
- icon: Stack(
- alignment: Alignment.center,
- children: <Widget>[
- Image.asset("lib/assets/img/topbar_friendslist.png"),
- ValueListenableBuilder(
- valueListenable: GetIt.I<MessageModel>().notifierFriend,
- builder: (BuildContext context, int value, Widget? child) {
- if (value > 0) {
- return Align(
- alignment: Alignment.topRight,
- child: Container(
- margin: const EdgeInsets.only(top: 6.0),
- width: 10,
- height: 10,
- decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.red),
- child: Center(
- child: Text(""),
- ),
- ),
- );
- }
- return Container();
- }),
- ],
- ),
- onPressed: () async {
- UmengCommonSdk.onEvent("social_friend", {});
- NavigatorUtil.goPage(context, (context) => UserFriendPage());
- },
- ),
- Selector<SocialIndexModel, ViewState>(
- selector: (_, SocialIndexModel model) => model.viewState,
- shouldRebuild: (_, v) => v == ViewState.idle,
- builder: (BuildContext context, ViewState value, Widget? child) {
- return IconButton(
- icon: Stack(
- alignment: Alignment.center,
- children: <Widget>[
- Image.asset("lib/assets/img/bbs_icon_news.png"),
- FutureBuilder(
- future: SharedPreferences.getInstance(),
- builder: (BuildContext context, AsyncSnapshot<SharedPreferences> snapshot) {
- if (snapshot.connectionState == ConnectionState.done) {
- if (snapshot.data?.getBool("message_setting") ?? true == true) {
- return ValueListenableBuilder(
- valueListenable: GetIt.I<MessageModel>().notifierSocial,
- builder: (BuildContext context, int value, Widget? child) {
- if (value > 0) {
- return Align(
- alignment: Alignment.topRight,
- child: Container(
- margin: const EdgeInsets.only(top: 6.0),
- width: 10,
- height: 10,
- decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.red),
- child: Center(
- child: Text(""),
- ),
- ),
- );
- }
- return Container();
- });
- }
- }
- return Container();
- }),
- ],
- ),
- onPressed: () async {
- await NavigatorUtil.go(context, Routes.socialMessage);
- setState(() {});
- },
- );
- }),
- const SizedBox(width: 6.0,),
- ],
- paddingLeading: false),
- if (header != null) header,
- if (model.isBusy)
- SliverToBoxAdapter(
- child: RequestLoadingWidget(),
- ),
- if (model.isIdle && model.list.isNotEmpty == true)
- SliverList(
- delegate: SliverChildBuilderDelegate(
- (context, index) {
- return _buildItemWidget(model.list[index]);
- },
- childCount: model.list.length,
- ),
- ),
- if (model.isError)
- SliverToBoxAdapter(
- child: RequestErrorWidget(() {
- model.initData();
- }),
- ),
- ],
- );
- });
- }),
- );
- }
- Widget _buildSearchWidget() {
- return GestureDetector(
- onTap: () {
- Navigator.push(context, new MaterialPageRoute(builder: (context) => SearchPage()));
- },
- child: Container(
- margin: EdgeInsets.fromLTRB(12.0, 0, 12.0, 12.0),
- height: 35,
- padding: EdgeInsets.fromLTRB(12.0, 0, 12.0, 0),
- decoration: BoxDecoration(
- color: Color(0xffF1F1F1),
- shape: BoxShape.rectangle,
- borderRadius: BorderRadius.all(Radius.circular(50)),
- ),
- child: Row(
- children: <Widget>[
- Image.asset("lib/assets/img/searchbar_icon_search.png"),
- Space(
- width: 4,
- ),
- Text(
- "输入关键词",
- strutStyle: StrutStyle(forceStrutHeight: true),
- style: TextStyle(fontSize: 14, color: Color(0xff999999)),
- ),
- ],
- ),
- ),
- );
- }
- Widget _buildItemWidget(Forum item) {
- return Padding(
- padding: const EdgeInsets.fromLTRB(ui_padding, 6.0, ui_padding, 6.0),
- child: InkWell(
- onTap: () => NavigatorUtil.goSocialDetail(context, item),
- child: Container(
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.all(Radius.circular(10)),
- ),
- padding: const EdgeInsets.all(ui_padding),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Row(
- children: <Widget>[
- CachedNetworkImage(imageUrl: item.cover ?? "", width: 48.0, height: 48.0,),
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: Text(
- "${item.name}",
- maxLines: 1,
- style: Theme.of(context).textTheme.headline2!.copyWith(fontSize: 16.0),
- ),
- ),
- Expanded(
- child: Center(
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- Image.asset("lib/assets/img/tab_bbs_normal.png", height: 14.0,),
- Padding(
- padding: const EdgeInsets.only(left: 5.0),
- child: ConstrainedBox(
- constraints: BoxConstraints(minWidth: 44),
- child: Text(
- "${item.subjectCount}",
- style: Theme.of(context).textTheme.bodyText1!,
- ),
- ),
- ),
- ],),
- ),
- ),
- Container(
- width: 79.0,
- height: 30.0,
- decoration: BoxDecoration(color: Theme.of(context).colorScheme.secondary, borderRadius: BorderRadius.circular(100.0)),
- child: Center(
- child: Text(
- "进入",
- style: Theme.of(context).textTheme.subtitle1?.copyWith(color: Colors.white),
- ),
- ),
- ),
- ],
- ),
- Padding(
- padding: const EdgeInsets.only(top: 12.0),
- child: Text(
- "${item.digest}",
- style: Theme.of(context).textTheme.subtitle1?.copyWith( height: 1.5,),
- ),
- ),
- ],
- ),
- ),
- ),
- );
- }
- @override
- bool get wantKeepAlive => true;
- @override
- SocialIndexModel createModel() => SocialIndexModel();
- }
|