Skip to content

Commit

Permalink
适配界面布局
Browse files Browse the repository at this point in the history
  • Loading branch information
toly1994328 committed Jun 9, 2022
1 parent fde6888 commit b7ba90b
Show file tree
Hide file tree
Showing 18 changed files with 818 additions and 85 deletions.
9 changes: 9 additions & 0 deletions lib/app/res/cons.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_unit/components/permanent/code/highlighter_style.dart';

import 'toly_icon.dart';

class Cons {

static const menuInfo = <String>["关于", "帮助", "问题反馈"]; //菜单栏
Expand All @@ -25,6 +27,13 @@ class Cons {
'Other'
]; //标题列表

static const iconMap = {
//底栏图标
"组件集录": TolyIcon.icon_layout, "收藏集录": TolyIcon.icon_star,
"绘制集录": Icons.palette, "布局集录": Icons.widgets,
"要点集录": TolyIcon.icon_bug,
};

static const fontFamilySupport = <String>[
'local',
'ComicNeue',
Expand Down
35 changes: 35 additions & 0 deletions lib/app/res/str_unit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,39 @@ class StrUnit {
static const String version = 'V1.5.1';
static const String appName = 'Flutter Unit';

static const String galleryInfo = """
[
{
"image":"assets/images/anim_draw.webp",
"name":"基础绘制",
"info":"收录一些基础图形绘制案例,这些案例对初涉绘制的编程者会非常友好。通过这些案例,可以学会点、线、矩形、圆、圆弧、文字、图片等基本图形的绘制方法,了解 Canvas、Paint、Path 等绘制中核心对象的使用。"
},
{
"image":"assets/images/draw_bg3.webp",
"name":"动画手势",
"info":"收录一些动画和手势的绘制案例,这些案例会让绘制更具有操作性。通过这些案例,可以学会动画和手势的使用,如滑动、旋转、缩放、移动等效果,让绘制不再只是静态展现。"
},
{
"image":"assets/images/base_draw.webp",
"name":"粒子绘制",
"info":"收录一些粒子相关的绘制案例,这些案例将是绘制的顶级操作。通过这些案例,可以学会如何使用粒子来绘制惊艳的视觉效果,如粒子时钟、粒子爆炸、粒子背景等效果,让绘制拥有无限可能。"
},
{
"image":"assets/images/draw_bg4.webp",
"name":"趣味绘制",
"info":"收录一些比较有趣的绘制案例,让我们一起在这里一起体验绘制的乐趣、编程的乐趣和智慧的乐趣吧。"
},
{
"image":"assets/images/caver.webp",
"name":"艺术画廊",
"info":"收录一些殿堂级的绘制案例,这些案例将是绘制的巅峰作品,它们的没有任何的实用性,也不为任何需求而生,它们仅是因为存在而存在,是人类智慧和表达的媒介,称谓艺术。"
}
]
""";


}
305 changes: 305 additions & 0 deletions lib/app/views/navigation/unit_desk_navigation.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,305 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_unit/app/blocs/color_change_bloc.dart';
import 'package:flutter_unit/app/res/cons.dart';

import 'package:flutter_unit/app/res/toly_icon.dart';
import 'package:flutter_unit/app/router/unit_router.dart';
import 'package:flutter_unit/app/views/unit_todo/layout_unit_page.dart';
import 'package:flutter_unit/app/views/unit_todo/paint_unit_page.dart';
import 'package:flutter_unit/app/views/unit_todo/point_unit_page.dart';
import 'package:flutter_unit/components/components.dart';
import 'package:flutter_unit/components/permanent/circle_image.dart';
import 'package:flutter_unit/components/permanent/feedback_widget.dart';
import 'package:flutter_unit/painter_system/gallery_unit.dart';
import 'package:flutter_unit/widget_system/views/widget_system_view.dart';

import 'package:url_launcher/url_launcher.dart';


class UnitDeskNavigation extends StatefulWidget {

const UnitDeskNavigation();

@override
_UnitDeskNavigationState createState() => _UnitDeskNavigationState();

}

class _UnitDeskNavigationState extends State<UnitDeskNavigation> {
late PageController _controller; //页面控制器,初始0

@override
void initState() {
super.initState();
_controller = PageController();

// ActionUnit.searchAction.onSearch = () {
// Navigator.of(context).pushNamed(UnitRouter.search);
// };
}

@override
void dispose() {
_controller.dispose(); //释放控制器
super.dispose();
}

// 构建悬浮按钮工具
Widget wrapOverlayTool({required Widget child}) => Builder(
builder: (ctx) => OverlayToolWrapper(
child: child,
));

@override
Widget build(BuildContext context) {
return BlocBuilder<ColorChangeCubit, SelectTab>(
builder: (_, state) => Scaffold(
drawer: HomeDrawer(),
//左滑页
endDrawer: HomeRightDrawer(
// color: state.homeColor,
),
//右滑页
floatingActionButton: _buildSearchButton(state.tabColor),
body: wrapOverlayTool(
child: Row(
children: [
_buildLeftNav(),
Expanded(
child: Container(
child: PageView(
physics: const NeverScrollableScrollPhysics(),
//使用PageView实现页面的切换
controller: _controller,
children: <Widget>[
HomePage(),
CollectPage(),
GalleryUnit(),
// GalleryPage(),
// PaintUnitPage(),
LayoutUnitPage(),
BugUnitPage(),
],
),
),
),
],
),
),
));
}

Widget _buildSearchButton(Color color) {
return FloatingActionButton(
elevation: 2,
backgroundColor: color,
child: const Icon(Icons.search),
onPressed: () => Navigator.of(context).pushNamed(UnitRouter.search),
);
}

_onTapNav(int index) {
_controller.jumpToPage(index);
if (index == 1) {
// BlocProvider.of<CollectBloc>(context).add(EventSetCollectData());
}
}

Widget _buildLeftNav() {
return Container(
padding: EdgeInsets.only(top: 20),
alignment: Alignment.topCenter,
margin: EdgeInsets.only(right: 1),
width: 120,
decoration: BoxDecoration(color: Color(0xff2C3036), boxShadow: [
BoxShadow(color: Colors.grey, offset: Offset(1, 0), blurRadius: 2)
]),
child: Column(
children: [
Wrap(
direction: Axis.vertical,
spacing: 10,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
CircleImage(
image: AssetImage('assets/images/icon_head.webp'),
size: 60,
),
Text(
'张风捷特烈',
style: TextStyle(color: Colors.white70),
)
],
),
buildIcons(),
Divider(
color: Colors.white,
height: 1,
endIndent: 20,
),
// SizedBox(height: 60,),
Expanded(
flex: 5,
child: Center(
child: RightNavBar(
itemData: Cons.iconMap,
onItemClick: _onTapNav,
color: Theme.of(context).primaryColor,
),
),
),

Expanded(
child: Container(),
flex: 1,
),
Divider(
indent: 20,
color: Colors.white,
height: 1,
),
Builder(
builder: (ctx) => FeedbackWidget(
onPressed: () => Scaffold.of(ctx).openDrawer(),
child: Padding(
padding: const EdgeInsets.only(bottom: 20, top: 20),
child: Icon(
Icons.settings,
color: Colors.white,
),
),
),
),
],
),
);
}

Widget buildIcons() {
return Padding(
padding: const EdgeInsets.only(bottom: 20, top: 20),
child: Wrap(
spacing: 5,
children: [
FeedbackWidget(
onPressed: () => _launchURL("http://blog.toly1994.com"),
child: Icon(
TolyIcon.icon_item,
color: Colors.white,
),
),
FeedbackWidget(
onPressed: () =>
_launchURL("https://github.com/toly1994328/FlutterUnit"),
child: Icon(
TolyIcon.icon_github,
color: Colors.white,
),
),
FeedbackWidget(
onPressed: () =>
_launchURL("https://juejin.im/user/5b42c0656fb9a04fe727eb37"),
child: Icon(
TolyIcon.icon_juejin,
color: Colors.white,
),
),
],
),
);
}

_launchURL(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
debugPrint('Could not launch $url');
}
}
}

class RightNavBar extends StatefulWidget {
final Color color;
final Map<String, IconData> itemData;
final Function(int) onItemClick;
final Size itemSize;

RightNavBar(
{this.color = Colors.blue,
required this.itemData,
required this.onItemClick,
this.itemSize = const Size(120, 35)});

@override
_RightNavBarState createState() => _RightNavBarState();
}

class _RightNavBarState extends State<RightNavBar> {
int _position = 0;

List<String> get info => widget.itemData.keys.toList();

@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: info
.map((e) => _buildChild(context, info.indexOf(e), widget.color))
.toList(),
);
}

Widget _buildChild(BuildContext context, int i, Color color) {
var active = i == _position;

return GestureDetector(
onTap: () => _tapTab(i),
child: Container(
alignment: Alignment.topLeft,
margin: EdgeInsets.only(top: 10),
width: widget.itemSize.width,
child: UnconstrainedBox(
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
color: active ? widget.color : Colors.white.withAlpha(33),
borderRadius: BorderRadius.only(
topRight: Radius.circular(20),
bottomRight: Radius.circular(20))),
width: active
? widget.itemSize.width * 0.95
: widget.itemSize.width * 0.85,
height: widget.itemSize.height,
child: Wrap(
spacing: 10,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Icon(
widget.itemData[info[i]],
size: active ? 24 : 20,
color: active ? Colors.white : Colors.white70,
),
Text(
info[i],
style: TextStyle(
color: active ? Colors.white : Colors.white70,
),
),
],
),
),
),
));
}

_tapTab(int i) {
setState(() {
_position = i;
if (widget.onItemClick != null) {
widget.onItemClick(_position);
}
});
}
}
Loading

0 comments on commit b7ba90b

Please sign in to comment.