liuyuqi-dellpc 1 year ago
parent
commit
596ad98b29
2 changed files with 12 additions and 5 deletions
  1. 9 2
      lib/dao/user_dao.dart
  2. 3 3
      lib/index_page.dart

+ 9 - 2
lib/dao/user_dao.dart

@@ -1,7 +1,14 @@
+import 'package:dio/dio.dart';
+import 'package:flutter_provider_demo/model/api.dart';
 import 'package:flutter_provider_demo/model/user_model.dart';
 
 class UserDao {
-  Future<UserModel> login() async {
-    Dio().post();
+  Future<UserModel> login(String username, String pwd) async {
+    Map<String, dynamic> params = {"username": username, "pwd": pwd};
+    Response response = await Dio().post(
+      Api.login,
+      data: params,
+    );
+    return UserModel.fromJson(response.data);
   }
 }

+ 3 - 3
lib/index_page.dart

@@ -11,14 +11,14 @@ class IndexPage extends StatefulWidget {
 }
 
 class _IndexPageState extends State<IndexPage> {
-  List<String> _list = <String>[];
+  final List<String> _list = <String>[];
 
   @override
   Widget build(BuildContext context) {
     return Scaffold(
-        body: Placeholder(),
+        body: const Placeholder(),
         appBar: AppBar(
-          title: Text('Index Page'),
+          title: const Text('Index Page'),
         ),
         floatingActionButton: FloatingActionButton(
           onPressed: () {