You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

256 lines
7.2 KiB

4 years ago
import 'dart:convert';
4 years ago
import 'dart:io';
4 years ago
import 'package:dio/dio.dart';
4 years ago
import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/home/huixiang_brand_page.dart';
import 'package:huixiang/home/main_home_page.dart';
4 years ago
import 'package:huixiang/main.dart';
4 years ago
import 'package:huixiang/mine/mine_page.dart';
4 years ago
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
4 years ago
import 'package:huixiang/union/union_page.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
4 years ago
import 'package:huixiang/utils/event_type.dart';
4 years ago
import 'package:permission_handler/permission_handler.dart';
4 years ago
import 'package:shared_preferences/shared_preferences.dart';
4 years ago
class MainPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _MainPage();
}
}
class _MainPage extends State<MainPage> {
List<Widget> _widgetOptions;
4 years ago
4 years ago
List<String> icons;
List<String> iconn;
@override
void initState() {
super.initState();
_widgetOptions = <Widget>[
BrandPage(),
MainHomePage(),
UnionPage(),
MinePage(),
];
icons = [
"assets/image/icon_brand_s.png",
"assets/image/icon_bi_s.png",
"assets/image/icon_meng_s.png",
"assets/image/icon_wo_s.png",
];
iconn = [
"assets/image/icon_brand_n.png",
"assets/image/icon_bi_n.png",
"assets/image/icon_meng_n.png",
"assets/image/icon_wo_n.png",
];
4 years ago
4 years ago
eventBus.on<EventType>().listen((event) {
setState(() {});
});
queryUserInfo();
}
queryUserInfo() async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
4 years ago
BaseData baseDate = await ApiService(Dio(),
context: context, token: sharedPreferences.getString('token'))
.queryInfo();
4 years ago
SharedPreferences.getInstance().then(
4 years ago
(value) => {
4 years ago
value.setString('user', jsonEncode(baseDate.data)),
},
);
4 years ago
}
requestPermission() async {
4 years ago
if (!await Permission.storage.isGranted) {
4 years ago
await Permission.storage.request();
}
4 years ago
}
4 years ago
PageController pageController = PageController();
4 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
4 years ago
resizeToAvoidBottomInset: false,
4 years ago
body: Container(
child: PageView(
controller: pageController,
children: _widgetOptions,
physics: NeverScrollableScrollPhysics(),
onPageChanged: (index) {
clickIndex = index;
setState(() {});
},
),
4 years ago
),
extendBody: true,
bottomNavigationBar: Container(
alignment: Platform.isAndroid ? Alignment.center : Alignment.topCenter,
decoration: BoxDecoration(
4 years ago
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 2),
blurRadius: 4,
spreadRadius: 0,
)
],
borderRadius: BorderRadius.only(
topRight: Radius.circular(4),
topLeft: Radius.circular(4),
),
),
4 years ago
height: 82.h,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
4 years ago
bottomNavigationBigItem(S.of(context).pinpai, 0),
bottomNavigationItem(S.of(context).main_menu1, 1),
bottomNavigationItem(S.of(context).main_menu2, 2),
bottomNavigationItem(S.of(context).main_menu3, 3),
4 years ago
],
),
),
);
}
var clickIndex = 0;
4 years ago
Widget bottomNavigationItem(text, index) {
4 years ago
var isSelected = index == clickIndex;
return Expanded(
child: InkWell(
onTap: () {
setState(() {
clickIndex = index;
4 years ago
pageController.jumpToPage(clickIndex);
4 years ago
});
},
child: Container(
width: 45.w,
child: Column(
4 years ago
mainAxisAlignment: Platform.isAndroid
? MainAxisAlignment.center
: MainAxisAlignment.start,
4 years ago
crossAxisAlignment: CrossAxisAlignment.center,
children: [
4 years ago
if (Platform.isIOS)
4 years ago
SizedBox(
height: 4.h,
),
4 years ago
AnimatedCrossFade(
firstChild: Image.asset(
icons[index],
width: 30,
height: 30,
fit: BoxFit.contain,
),
secondChild: Image.asset(
iconn[index],
width: 30,
height: 30,
fit: BoxFit.contain,
),
crossFadeState: isSelected
? CrossFadeState.showFirst
: CrossFadeState.showSecond,
duration: Duration(milliseconds: 200),
),
Text(
4 years ago
text,
4 years ago
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
color: Color(0xFF4C4C4C)),
),
],
),
),
),
flex: 1,
);
}
4 years ago
Widget bottomNavigationBigItem(text, index) {
4 years ago
var isSelected = index == clickIndex;
return Expanded(
child: InkWell(
onTap: () {
4 years ago
setState(() {
clickIndex = index;
pageController.jumpToPage(clickIndex);
});
4 years ago
},
child: Container(
width: 45.w,
alignment: Alignment.center,
child: AnimatedCrossFade(
firstCurve: Curves.easeIn,
secondCurve: Curves.ease,
sizeCurve: Curves.easeInOut,
4 years ago
firstChild: Container(
padding: EdgeInsets.all(4),
height: 82.h,
alignment:
Platform.isAndroid ? Alignment.center : Alignment.topCenter,
child: Image.asset(
icons[index],
width: 45,
height: 45,
fit: BoxFit.contain,
),
4 years ago
),
secondChild: Column(
4 years ago
mainAxisAlignment: Platform.isAndroid
? MainAxisAlignment.center
: MainAxisAlignment.start,
4 years ago
crossAxisAlignment: CrossAxisAlignment.center,
children: [
4 years ago
if (Platform.isIOS)
4 years ago
SizedBox(
height: 4.h,
),
4 years ago
Image.asset(
iconn[index],
width: 30,
height: 30,
fit: BoxFit.contain,
),
4 years ago
SizedBox(
height: 1.h,
),
4 years ago
Text(
4 years ago
text,
4 years ago
style: TextStyle(
4 years ago
fontSize: 10.sp,
fontWeight: FontWeight.bold,
color: Color(0xFF4C4C4C),
),
4 years ago
),
],
),
crossFadeState: isSelected
? CrossFadeState.showFirst
: CrossFadeState.showSecond,
duration: Duration(milliseconds: 200),
),
),
),
flex: 1,
);
}
}