|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:provider/provider.dart';
- import 'package:zhiying_base_widget/pages/setting_page/models/setting_page_style_item_model.dart';
- import 'package:zhiying_base_widget/pages/setting_page/models/setting_page_style_model.dart';
- import 'package:zhiying_base_widget/pages/setting_page/setting_page_bloc.dart';
- import 'package:zhiying_comm/util/base_bloc.dart';
- import 'package:zhiying_comm/zhiying_comm.dart';
-
- class SettingPage extends StatefulWidget {
- final Map<String, dynamic> data;
-
- const SettingPage(this.data, {Key key}) : super(key: key);
-
- @override
- _SettingPageState createState() => _SettingPageState();
- }
-
- class _SettingPageState extends State<SettingPage> {
- @override
- Widget build(BuildContext context) {
- return BlocProvider<SettingPageBloc>(
- bloc: SettingPageBloc(),
- child: _SettingContainer(widget.data),
- );
- }
- }
-
- class _SettingContainer extends StatefulWidget {
- final Map<String, dynamic> data;
-
- const _SettingContainer(
- this.data, {
- Key key,
- }) : super(key: key);
-
- @override
- _SettingContainerState createState() => _SettingContainerState();
- }
-
- class _SettingContainerState extends State<_SettingContainer> {
- SettingPageBloc _bloc;
-
- @override
- void initState() {
- _bloc = BlocProvider.of<SettingPageBloc>(context);
- _bloc.loadData(widget.data['skip_identifier']);
-
- super.initState();
- }
-
- @override
- Widget build(BuildContext context) {
- return StreamBuilder<SettingPageStyleModel>(
- stream: _bloc.outData,
- builder: (BuildContext context, AsyncSnapshot snapshot) {
- SettingPageStyleModel style = snapshot.data;
-
- List<Widget> widgets = List();
- widgets.addAll(style?.settings?.map((list) {
- return _createSection(list);
- })?.toList() ??
- []);
- widgets.add(Provider.of<UserInfoNotifier>(context).userInfo == null
- ? Container()
- : _createLogout());
-
- return Scaffold(
- backgroundColor: Color(0xfff9f9f9),
- appBar: _createNav(style),
- body: SingleChildScrollView(
- child: Column(
- children: widgets,
- ),
- ));
- });
- }
-
- // 导航栏
- Widget _createNav(SettingPageStyleModel style) {
- return CupertinoNavigationBar(
- border: Border(
- bottom: BorderSide(
- width: 0.0, // One physical pixel.
- style: BorderStyle.none,
- ),
- ),
- backgroundColor: HexColor.fromHex(style?.appBarBgColor ?? '#ffffff'),
- leading: Navigator.canPop(context)
- ? GestureDetector(
- child: Container(
- padding: EdgeInsets.zero,
- child: Icon(
- Icons.arrow_back_ios,
- size: 20,
- ),
- ),
- onTap: () {
- if (Navigator.canPop(context)) {
- Navigator.pop(context);
- }
- },
- )
- : Container(),
- middle: Text(
- style?.appBarName ?? '设置',
- style: TextStyle(
- fontSize: 15,
- color: HexColor.fromHex(style?.appBarNameColor ?? '#333333'),
- ),
- ),
- );
- }
-
- Widget _createSection(List<SettingPageStyleItemModel> sections) {
- return Container(
- margin: EdgeInsets.only(top: 8),
- child: Column(
- children: sections.map((item) {
- return _createItem(item);
- }).toList(),
- ),
- );
- }
-
- Widget _createItem(SettingPageStyleItemModel item) {
- return GestureDetector(
- child: Container(
- padding: EdgeInsets.only(left: 12.5, right: 12.5),
- width: double.infinity,
- height: 50,
- color: Colors.white,
- child: Row(
- children: <Widget>[
- Expanded(
- child: Text(
- item.name,
- style: TextStyle(
- fontSize: 13,
- color: HexColor.fromHex(item?.nameColor ?? '#333333'),
- fontWeight: FontWeight.bold,
- ),
- ),
- ),
- Expanded(
- child: Text(
- item.desc,
- textAlign: TextAlign.right,
- style: TextStyle(
- fontSize: 13,
- color: HexColor.fromHex(item?.descColor ?? '#333333'),
- ),
- ),
- ),
- Icon(
- Icons.arrow_forward_ios,
- size: 14,
- color: Color(0xff999999),
- )
- ],
- ),
- ),
- onTap: () {
- RouterUtil.route(item, item.toJson(), context);
- },
- );
- }
-
- Widget _createLogout() {
- return GestureDetector(
- child: Container(
- color: Colors.white,
- width: double.infinity,
- height: 50,
- margin: EdgeInsets.only(top: 10),
- child: Center(
- child: Text(
- '退出登录',
- style: TextStyle(
- fontSize: 13,
- color: Color(0xffff4242),
- fontWeight: FontWeight.bold,
- ),
- ),
- ),
- ),
- onTap: () {
- Logger.debug('退出登录');
- Provider.of<UserInfoNotifier>(context, listen: false).unLogin();
- },
- );
- }
- }
|