Browse Source

show badge icon in tabbar

master
daivph 5 years ago
parent
commit
b1a8e63e79
3 changed files with 60 additions and 15 deletions
  1. +4
    -0
      lib/presentation/screens/notification/sc_notification.dart
  2. +1
    -6
      lib/presentation/screens/splash/view/splash_page.dart
  3. +55
    -9
      lib/presentation/screens/tabbar/tabbar.dart

+ 4
- 0
lib/presentation/screens/notification/sc_notification.dart View File

import 'package:farm_tpf/presentation/custom_widgets/bottom_loader.dart'; import 'package:farm_tpf/presentation/custom_widgets/bottom_loader.dart';
import 'package:farm_tpf/presentation/custom_widgets/dash_line_widget.dart'; import 'package:farm_tpf/presentation/custom_widgets/dash_line_widget.dart';
import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart'; import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart';
import 'package:farm_tpf/presentation/screens/notification/update_count_noti_bloc.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/plot_detail/sc_plot_information.dart'; import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_information.dart';
import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_parameter.dart'; import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_parameter.dart';
print("onMessage: $message"); print("onMessage: $message");
try { try {
notiBloc.add(OnRefreshFromNotification()); notiBloc.add(OnRefreshFromNotification());
updateCountNotiBloc.getNotifications((data) {}, (err) {});
} catch (e) { } catch (e) {
print(e); print(e);
} }
if (state is NotiFailure) { if (state is NotiFailure) {
return Center(child: Text(state.errorString)); return Center(child: Text(state.errorString));
} else if (state is NotiSuccess) { } else if (state is NotiSuccess) {
updateCountNotiBloc.getNotifications((data) {}, (err) {});
if (state.items.isEmpty) { if (state.items.isEmpty) {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
Expanded( Expanded(
child: RefreshIndicator( child: RefreshIndicator(
child: ListView.builder( child: ListView.builder(
physics: AlwaysScrollableScrollPhysics(),
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return index >= state.items.length return index >= state.items.length
? BottomLoader() ? BottomLoader()

+ 1
- 6
lib/presentation/screens/splash/view/splash_page.dart View File



@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold(
body: Image.asset(
AppAssets.icActionCropStatus,
width: Get.width,
height: Get.height,
));
return Scaffold(body: Center(child: CircularProgressIndicator()));
} }
} }

+ 55
- 9
lib/presentation/screens/tabbar/tabbar.dart View File

import 'package:badges/badges.dart';
import 'package:farm_tpf/custom_model/NotificationObjectDTO.dart';
import 'package:farm_tpf/presentation/screens/account/sc_account.dart'; import 'package:farm_tpf/presentation/screens/account/sc_account.dart';
import 'package:farm_tpf/presentation/screens/control_device/sc_control_device.dart'; import 'package:farm_tpf/presentation/screens/control_device/sc_control_device.dart';
import 'package:farm_tpf/presentation/screens/notification/sc_notification.dart'; import 'package:farm_tpf/presentation/screens/notification/sc_notification.dart';
import 'package:farm_tpf/presentation/screens/notification/update_count_noti_bloc.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/utils/const_color.dart'; import 'package:farm_tpf/utils/const_color.dart';
import 'package:farm_tpf/utils/const_icons.dart'; import 'package:farm_tpf/utils/const_icons.dart';
void initState() { void initState() {
super.initState(); super.initState();
changeTabbar.initValue(); changeTabbar.initValue();
updateCountNotiBloc.getNotifications((data) {}, (err) {});
}

Widget textCountNoti() {
return StreamBuilder(
stream: updateCountNotiBloc.actions,
builder: (context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.hasData) {
var noti = snapshot.data as NotificationObjectDTO;
var unreadNoti =
noti.numberUnreadTotal > 99 ? '99+' : '${noti.numberUnreadTotal}';
return Text(
'$unreadNoti',
softWrap: true,
style: TextStyle(color: Colors.white, fontSize: 10),
);
} else {
return Text(
'O',
softWrap: true,
style: TextStyle(color: Colors.white, fontSize: 10),
);
}
},
);
} }


@override @override
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
SvgPicture.asset(
itemsTabbar[index].icon,
width: 24,
height: 24,
color: (tabbarSelected.index ==
itemsTabbar[index].index)
? AppColors.YELLOW
: AppColors.GRAY1,
),
index == 3
? Badge(
badgeContent: textCountNoti(),
shape: BadgeShape.circle,
badgeColor: Colors.red,
position: BadgePosition(
top: -15, start: 10),
child: SvgPicture.asset(
itemsTabbar[index].icon,
width: 24,
height: 24,
color: (tabbarSelected.index ==
itemsTabbar[index]
.index)
? AppColors.YELLOW
: AppColors.GRAY1,
),
)
: SvgPicture.asset(
itemsTabbar[index].icon,
width: 24,
height: 24,
color: (tabbarSelected.index ==
itemsTabbar[index].index)
? AppColors.YELLOW
: AppColors.GRAY1,
),
Flexible( Flexible(
child: Text( child: Text(
itemsTabbar[index].title, itemsTabbar[index].title,

Loading…
Cancel
Save