diff --git a/lib/main.dart b/lib/main.dart index b27ebe0..39747eb 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 { + bool _isLogin = false; int _pageIndex = 0; final List _pages = [ const HomePage(), @@ -46,8 +40,28 @@ class _RouterViewState extends State { ]; 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( diff --git a/lib/views/home.dart b/lib/views/home.dart index 90ea5e5..a826cc3 100644 --- a/lib/views/home.dart +++ b/lib/views/home.dart @@ -89,9 +89,7 @@ class _AdvantageState extends State { 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 { String _notification = "通知"; + bool _isLoading = true; @override void initState() { @@ -137,12 +136,16 @@ class _NotificationsState extends State { 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 { List> _activities = []; + bool _isLoading = true; @override void initState() { @@ -302,6 +306,7 @@ class _ActivitiesState extends State { "http://124.93.196.45:10091/Neusoft/community${activity['cover']}", }) .toList(); + _isLoading = false; }); } } @@ -311,7 +316,7 @@ class _ActivitiesState extends State { 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 { List> _dynamics = []; + bool _isLoading = true; @override void initState() { @@ -425,6 +431,7 @@ class _DynamicsState extends State { "http://124.93.196.45:10091/Neusoft/community${dynamic['cover']}", }) .toList(); + _isLoading = false; }); } } @@ -434,7 +441,7 @@ class _DynamicsState extends State { 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 { imageUrl: dynamic['imageUrl'], ); }).toList(), - ), + ) ); } } @@ -520,6 +527,7 @@ class Reminders extends StatefulWidget { class _RemindersState extends State { final List> _reminders = []; + bool _isLoading = true; @override void initState() { @@ -535,6 +543,7 @@ class _RemindersState extends State { final data = jsonDecode(response.body); setState(() { data['data'].forEach((e) => _reminders.add(e)); + _isLoading = false; }); } } @@ -544,7 +553,7 @@ class _RemindersState extends State { return ShowMoreContainer( title: "认证提醒", showMore: false, - child: SizedBox( + child: _isLoading ? const Center(child: CircularProgressIndicator()) : SizedBox( height: 300, child: ListView.builder( itemCount: _reminders.length, diff --git a/lib/views/me.dart b/lib/views/me.dart index 92f5125..598d9c6 100644 --- a/lib/views/me.dart +++ b/lib/views/me.dart @@ -110,6 +110,7 @@ class _MePageState extends State { 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 items = []; items.addAll(personsCard); + items.add(const SizedBox(height: 20)); items.add(Center( child: ElevatedButton( onPressed: (){ @@ -133,10 +134,31 @@ class _MePageState extends State { )); return FullPageStruct( title: '家庭成员管理', - color: Colors.lightBlue, - child: ListView( - children: items, - ), + 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,85 +246,101 @@ class _AddFamilyPersonState extends State { title: "新增家庭成员", child: Padding( padding: const EdgeInsets.all(16.0), - child: Form( - key: _formKey, - child: ListView( - children: [ - DropdownButtonFormField( - decoration: const InputDecoration(labelText: '选择房屋'), - value: _selectedHouseId, - onChanged: (value) { - setState(() { - _selectedHouseId = value; - }); - }, - items: _houseList.map((house) { - return DropdownMenuItem( - value: house['id'].toString(), - child: Text(house['address'] ?? '未知地址'), - ); - }).toList(), - validator: (value) => - value == null ? '请选择房屋' : null, - ), - TextFormField( - decoration: const InputDecoration(labelText: '姓名'), - onSaved: (value) => _name = value, - validator: (value) => value == null || value.isEmpty - ? '请输入姓名' - : null, - ), - DropdownButtonFormField( - decoration: const InputDecoration(labelText: '性别'), - value: _gender, - onChanged: (value) { - setState(() { - _gender = value; - }); - }, - items: const [ - DropdownMenuItem(value: "0", child: Text('男')), - DropdownMenuItem(value: "1", child: Text('女')), + child: Stack( + children: [ + Positioned.fill( + top: 0, + child: Form( + key: _formKey, + child: ListView( + children: [ + DropdownButtonFormField( + decoration: const InputDecoration(labelText: '选择房屋'), + value: _selectedHouseId, + onChanged: (value) { + setState(() { + _selectedHouseId = value; + }); + }, + items: _houseList.map((house) { + return DropdownMenuItem( + value: house['id'].toString(), + child: Text(house['address'] ?? '未知地址'), + ); + }).toList(), + validator: (value) => + value == null ? '请选择房屋' : null, + ), + const Divider(), + TextFormField( + decoration: const InputDecoration(labelText: '姓名'), + onSaved: (value) => _name = value, + validator: (value) => value == null || value.isEmpty + ? '请输入姓名' + : null, + ), + DropdownButtonFormField( + decoration: const InputDecoration(labelText: '性别'), + value: _gender, + onChanged: (value) { + setState(() { + _gender = value; + }); + }, + items: const [ + DropdownMenuItem(value: "0", child: Text('男')), + DropdownMenuItem(value: "1", child: Text('女')), + ], + validator: (value) => value == null ? '请选择性别' : null, + ), + TextFormField( + decoration: const InputDecoration(labelText: '手机号'), + keyboardType: TextInputType.phone, + onSaved: (value) => _phone = value, + validator: (value) => value == null || value.isEmpty + ? '请输入手机号' + : null, + ), + TextFormField( + decoration: const InputDecoration(labelText: '身份证号'), + onSaved: (value) => _idCard = value, + validator: (value) => value == null || value.isEmpty + ? '请输入身份证号' + : null, + ), + DropdownButtonFormField( + decoration: const InputDecoration(labelText: '住户类型'), + value: _memberType, + onChanged: (value) { + setState(() { + _memberType = value; + }); + }, + items: const [ + DropdownMenuItem(value: "1", child: Text('业主')), + DropdownMenuItem(value: "2", child: Text('租户')), + ], + validator: (value) => + value == null ? '请选择住户类型' : null, + ), ], - validator: (value) => value == null ? '请选择性别' : null, ), - TextFormField( - decoration: const InputDecoration(labelText: '手机号'), - keyboardType: TextInputType.phone, - onSaved: (value) => _phone = value, - validator: (value) => value == null || value.isEmpty - ? '请输入手机号' - : null, - ), - TextFormField( - decoration: const InputDecoration(labelText: '身份证号'), - onSaved: (value) => _idCard = value, - validator: (value) => value == null || value.isEmpty - ? '请输入身份证号' - : null, - ), - DropdownButtonFormField( - decoration: const InputDecoration(labelText: '住户类型'), - value: _memberType, - onChanged: (value) { - setState(() { - _memberType = value; - }); - }, - items: const [ - DropdownMenuItem(value: "1", child: Text('业主')), - DropdownMenuItem(value: "2", child: Text('租户')), + ) + ), + Positioned.fill( + bottom: 0, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + ElevatedButton( + onPressed: _submit, + child: const Text('保存'), + ) ], - validator: (value) => - value == null ? '请选择住户类型' : null, ), - ElevatedButton( - onPressed: _submit, - child: const Text('保存'), - ), - ], - ), - ), + ) + ], + ) ), ); } @@ -441,100 +479,116 @@ class _FamilyPersonInformationState extends State { title: "家庭成员详情", child: Padding( padding: const EdgeInsets.all(16.0), - child: Form( - key: _formKey, - child: ListView( - children: [ - DropdownButtonFormField( - decoration: const InputDecoration(labelText: '选择房屋'), - value: _selectedHouseId, - onChanged: (value) { - setState(() { - _selectedHouseId = value; - }); - }, - items: _houseList.map((house) { - return DropdownMenuItem( - value: house['id'].toString(), - child: Text(house['address'] ?? '未知地址'), - ); - }).toList(), - validator: (value) => - value == null ? '请选择房屋' : null, - ), - TextFormField( - initialValue: _name, - decoration: const InputDecoration(labelText: '姓名'), - onSaved: (value) => _name = value, - validator: (value) => value == null || value.isEmpty - ? '请输入姓名' - : null, - ), - DropdownButtonFormField( - decoration: const InputDecoration(labelText: '性别'), - value: _gender, - onChanged: (value) { - setState(() { - _gender = value; - }); - }, - items: const [ - DropdownMenuItem(value: "0", child: Text('男')), - DropdownMenuItem(value: "1", child: Text('女')), - ], - validator: (value) => value == null ? '请选择性别' : null, - ), - TextFormField( - initialValue: _phone, - decoration: const InputDecoration(labelText: '手机号'), - keyboardType: TextInputType.phone, - onSaved: (value) => _phone = value, - validator: (value) => value == null || value.isEmpty - ? '请输入手机号' - : null, - ), - TextFormField( - initialValue: _idCard, - decoration: const InputDecoration(labelText: '身份证号'), - onSaved: (value) => _idCard = value, - validator: (value) => value == null || value.isEmpty - ? '请输入身份证号' - : null, - ), - DropdownButtonFormField( - decoration: const InputDecoration(labelText: '住户类型'), - value: _memberType, - onChanged: (value) { - setState(() { - _memberType = value; - }); - }, - items: const [ - DropdownMenuItem(value: "1", child: Text('业主')), - DropdownMenuItem(value: "2", child: Text('租户')), - ], - validator: (value) => - value == null ? '请选择住户类型' : null, - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + child: Stack( + children: [ + Positioned.fill( + top: 0, + child: Form( + key: _formKey, + child: ListView( children: [ - OutlinedButton( - onPressed: _deleteMember, - style: OutlinedButton.styleFrom( - foregroundColor: Colors.red, - ), - child: const Text('删除家庭成员'), + DropdownButtonFormField( + decoration: const InputDecoration(labelText: '选择房屋'), + value: _selectedHouseId, + onChanged: (value) { + setState(() { + _selectedHouseId = value; + }); + }, + items: _houseList.map((house) { + return DropdownMenuItem( + value: house['id'].toString(), + child: Text(house['address'] ?? '未知地址'), + ); + }).toList(), + validator: (value) => + value == null ? '请选择房屋' : null, ), - ElevatedButton( - onPressed: _submit, - child: const Text('保存'), + const Divider(), + TextFormField( + initialValue: _name, + decoration: const InputDecoration(labelText: '姓名'), + onSaved: (value) => _name = value, + validator: (value) => value == null || value.isEmpty + ? '请输入姓名' + : null, + ), + DropdownButtonFormField( + decoration: const InputDecoration(labelText: '性别'), + value: _gender, + onChanged: (value) { + setState(() { + _gender = value; + }); + }, + items: const [ + DropdownMenuItem(value: "0", child: Text('男')), + DropdownMenuItem(value: "1", child: Text('女')), + ], + validator: (value) => value == null ? '请选择性别' : null, + ), + TextFormField( + initialValue: _phone, + decoration: const InputDecoration(labelText: '手机号'), + keyboardType: TextInputType.phone, + onSaved: (value) => _phone = value, + validator: (value) => value == null || value.isEmpty + ? '请输入手机号' + : null, + ), + TextFormField( + initialValue: _idCard, + decoration: const InputDecoration(labelText: '身份证号'), + onSaved: (value) => _idCard = value, + validator: (value) => value == null || value.isEmpty + ? '请输入身份证号' + : null, + ), + DropdownButtonFormField( + decoration: const InputDecoration(labelText: '住户类型'), + value: _memberType, + onChanged: (value) { + setState(() { + _memberType = value; + }); + }, + items: const [ + DropdownMenuItem(value: "1", child: Text('业主')), + DropdownMenuItem(value: "2", child: Text('租户')), + ], + validator: (value) => + value == null ? '请选择住户类型' : null, ), ], ), - ], - ), - ), + ) + ), + Positioned.fill( + bottom: 0, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + OutlinedButton( + onPressed: _deleteMember, + style: OutlinedButton.styleFrom( + foregroundColor: Colors.red, + ), + child: const Text('删除家庭成员'), + ), + ElevatedButton( + onPressed: _submit, + child: const Text('保存'), + ), + ], + ) + ], + ) + ) + ], + ) ), ); } diff --git a/lib/views/social.dart b/lib/views/social.dart index 822d423..b2de81f 100644 --- a/lib/views/social.dart +++ b/lib/views/social.dart @@ -76,6 +76,7 @@ class SocialPage extends StatefulWidget { class _SocialPageState extends State { List> posts = []; + bool _isLoading = true; @override void initState() { @@ -91,6 +92,7 @@ class _SocialPageState extends State { final data = json.decode(response.body); setState(() { posts = List>.from(data['rows']); + _isLoading = false; }); } else { throw Exception('Failed to load posts'); @@ -103,13 +105,12 @@ class _SocialPageState extends State { 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) {