feat: adding loading

fix: change ui
This commit is contained in:
wzp 2024-09-02 19:49:30 +08:00
parent 991f871a17
commit ed176aa297
4 changed files with 262 additions and 184 deletions

View File

@ -9,13 +9,6 @@ import 'package:environmental_protection/views/social.dart';
import 'package:flutter/material.dart';
main() async {
var global = GlobalInformation.getInstance();
var response = await global.requester.post(resolve("api/login"), body: jsonEncode({
'username': 'WUvFG3gY',
'password': 'ZogPgBF6'
}));
// print(response.body);
global.token = jsonDecode(response.body)['token'];
runApp(const DigitalLife());
}
class DigitalLife extends StatelessWidget {
@ -36,6 +29,7 @@ class RouterView extends StatefulWidget {
}
class _RouterViewState extends State<RouterView> {
bool _isLogin = false;
int _pageIndex = 0;
final List<Widget> _pages = [
const HomePage(),
@ -46,8 +40,28 @@ class _RouterViewState extends State<RouterView> {
];
final String _name = "红星海五期";
GlobalInformation? _globalInformation;
void _login() async {
var global = GlobalInformation.getInstance();
var response = await global.requester.post(resolve("api/login"), body: jsonEncode({
'username': 'WUvFG3gY',
'password': 'ZogPgBF6'
}));
// print(response.body);
global.token = jsonDecode(response.body)['token'];
setState(() {
_isLogin = true;
});
}
@override
void initState() {
super.initState();
_login();
}
@override
Widget build(BuildContext context) {
if (!_isLogin) {
return const Center(child: CircularProgressIndicator());
}
_globalInformation ??= GlobalInformation.getInstance(super.setState);
return Scaffold(
appBar: AppBar(

View File

@ -89,9 +89,7 @@ class _AdvantageState extends State<Advantage> {
child: PageView(
scrollDirection: Axis.horizontal,
children: urls
.map((e) => Image(
image: NetworkImage(
"http://124.93.196.45:10091/Neusoft/community$e")))
.map((e) => Image.network("http://124.93.196.45:10091/Neusoft/community$e"))
.toList(),
onPageChanged: (index) {
setState(() {
@ -122,6 +120,7 @@ class Notifications extends StatefulWidget {
class _NotificationsState extends State<Notifications> {
String _notification = "通知";
bool _isLoading = true;
@override
void initState() {
@ -137,12 +136,16 @@ class _NotificationsState extends State<Notifications> {
final data = jsonDecode(response.body);
setState(() {
_notification = data['rows'][0]['noticeTitle'];
_isLoading = false;
});
}
}
@override
Widget build(BuildContext context) {
if (_isLoading) {
return const Center(child: CircularProgressIndicator());
}
return Row(
children: [
const Icon(MaterialDesign.sms, color: Colors.blue),
@ -280,6 +283,7 @@ class Activities extends StatefulWidget {
class _ActivitiesState extends State<Activities> {
List<Map<String, dynamic>> _activities = [];
bool _isLoading = true;
@override
void initState() {
@ -302,6 +306,7 @@ class _ActivitiesState extends State<Activities> {
"http://124.93.196.45:10091/Neusoft/community${activity['cover']}",
})
.toList();
_isLoading = false;
});
}
}
@ -311,7 +316,7 @@ class _ActivitiesState extends State<Activities> {
return ShowMoreContainer(
title: "社区活动",
showMore: true,
child: SizedBox(
child: _isLoading ? const Center(child: CircularProgressIndicator()) : SizedBox(
height: 100,
child: ListView(
scrollDirection: Axis.horizontal,
@ -402,6 +407,7 @@ class Dynamics extends StatefulWidget {
class _DynamicsState extends State<Dynamics> {
List<Map<String, dynamic>> _dynamics = [];
bool _isLoading = true;
@override
void initState() {
@ -425,6 +431,7 @@ class _DynamicsState extends State<Dynamics> {
"http://124.93.196.45:10091/Neusoft/community${dynamic['cover']}",
})
.toList();
_isLoading = false;
});
}
}
@ -434,7 +441,7 @@ class _DynamicsState extends State<Dynamics> {
return ShowMoreContainer(
title: "社区动态",
showMore: true,
child: Column(
child: _isLoading ? const Center(child: CircularProgressIndicator()) : Column(
children: _dynamics.map((dynamic) {
return Dynamic(
title: dynamic['title'],
@ -444,7 +451,7 @@ class _DynamicsState extends State<Dynamics> {
imageUrl: dynamic['imageUrl'],
);
}).toList(),
),
)
);
}
}
@ -520,6 +527,7 @@ class Reminders extends StatefulWidget {
class _RemindersState extends State<Reminders> {
final List<Map<String, dynamic>> _reminders = [];
bool _isLoading = true;
@override
void initState() {
@ -535,6 +543,7 @@ class _RemindersState extends State<Reminders> {
final data = jsonDecode(response.body);
setState(() {
data['data'].forEach((e) => _reminders.add(e));
_isLoading = false;
});
}
}
@ -544,7 +553,7 @@ class _RemindersState extends State<Reminders> {
return ShowMoreContainer(
title: "认证提醒",
showMore: false,
child: SizedBox(
child: _isLoading ? const Center(child: CircularProgressIndicator()) : SizedBox(
height: 300,
child: ListView.builder(
itemCount: _reminders.length,

View File

@ -110,6 +110,7 @@ class _MePageState extends State<MePage> {
var personsCard = persons.map((e){return PersonCard(name: e['name'], phone: e['telephone'], endDate: e['endDate'] == null ? null : DateTime.parse(e['endDate']), id: e['id'], fetchFunction: _fetchFamilyData, type: e['memberType'] == "1" ? "家属" : "租户");}).toList();
List<Widget> items = [];
items.addAll(personsCard);
items.add(const SizedBox(height: 20));
items.add(Center(
child: ElevatedButton(
onPressed: (){
@ -133,10 +134,31 @@ class _MePageState extends State<MePage> {
));
return FullPageStruct(
title: '家庭成员管理',
color: Colors.lightBlue,
child: Stack(
children: [
Positioned.fill(
top: 0,
child: Flex(
direction: Axis.vertical,
children: [
Container(
decoration: const BoxDecoration(
borderRadius: BorderRadiusDirectional.only(bottomStart: Radius.circular(10), bottomEnd: Radius.circular(10)),
color: Colors.blue
),
height: 100,
)
],
)
),
Positioned.fill(
top: 50,
child: ListView(
children: items,
),
)
)
],
)
);
}
}
@ -224,6 +246,10 @@ class _AddFamilyPersonState extends State<AddFamilyPerson> {
title: "新增家庭成员",
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Stack(
children: [
Positioned.fill(
top: 0,
child: Form(
key: _formKey,
child: ListView(
@ -245,6 +271,7 @@ class _AddFamilyPersonState extends State<AddFamilyPerson> {
validator: (value) =>
value == null ? '请选择房屋' : null,
),
const Divider(),
TextFormField(
decoration: const InputDecoration(labelText: '姓名'),
onSaved: (value) => _name = value,
@ -296,13 +323,24 @@ class _AddFamilyPersonState extends State<AddFamilyPerson> {
validator: (value) =>
value == null ? '请选择住户类型' : null,
),
],
),
)
),
Positioned.fill(
bottom: 0,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ElevatedButton(
onPressed: _submit,
child: const Text('保存'),
),
)
],
),
),
)
],
)
),
);
}
@ -441,6 +479,10 @@ class _FamilyPersonInformationState extends State<FamilyPersonInformation> {
title: "家庭成员详情",
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Stack(
children: [
Positioned.fill(
top: 0,
child: Form(
key: _formKey,
child: ListView(
@ -462,6 +504,7 @@ class _FamilyPersonInformationState extends State<FamilyPersonInformation> {
validator: (value) =>
value == null ? '请选择房屋' : null,
),
const Divider(),
TextFormField(
initialValue: _name,
decoration: const InputDecoration(labelText: '姓名'),
@ -516,6 +559,15 @@ class _FamilyPersonInformationState extends State<FamilyPersonInformation> {
validator: (value) =>
value == null ? '请选择住户类型' : null,
),
],
),
)
),
Positioned.fill(
bottom: 0,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
@ -531,10 +583,12 @@ class _FamilyPersonInformationState extends State<FamilyPersonInformation> {
child: const Text('保存'),
),
],
),
)
],
),
),
)
)
],
)
),
);
}

View File

@ -76,6 +76,7 @@ class SocialPage extends StatefulWidget {
class _SocialPageState extends State<SocialPage> {
List<Map<String, dynamic>> posts = [];
bool _isLoading = true;
@override
void initState() {
@ -91,6 +92,7 @@ class _SocialPageState extends State<SocialPage> {
final data = json.decode(response.body);
setState(() {
posts = List<Map<String, dynamic>>.from(data['rows']);
_isLoading = false;
});
} else {
throw Exception('Failed to load posts');
@ -103,13 +105,12 @@ class _SocialPageState extends State<SocialPage> {
appBar: AppBar(
title: const Text("友邻社交"),
),
body: GridView.builder(
body: _isLoading ? const Center(child: CircularProgressIndicator()) : GridView.builder(
padding: const EdgeInsets.all(10.0),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 0.75,
crossAxisSpacing: 10.0,
mainAxisSpacing: 10.0,
),
itemCount: posts.length,
itemBuilder: (context, index) {