flutter: やりたい事:ログイン機能付き、TODOアプリ

1.HTTPを使ったログイン、レスポンスはTOKEN

2.ログイン後は、自身がアサインされたタスクリストを表示

3.タスクリスト表示画面には抽出条件があり、アサイン、登録日の範囲や、状態が指定できる

ただこれだけを作りたいのに、良く解らんで1か月たった、俺はアホなんか?

1はこんな感じで出来たが、、2が良く解らん

class LoginPage extends HookConsumerWidget {
  LoginPage({Key? key, required this.title}) : super(key: key);

  final String title;

  final _userNameTextCtl = TextEditingController();
  final _pwdTextCtl = TextEditingController();
  final FocusNode _userNameFocusNode = FocusNode();
  final FocusNode _passwordNameFocusNode = FocusNode();

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final errorMessage = ref.watch(errorMessageProvider);
    final viewModel = ref.watch(loginStateNotifierProvider.notifier);
    debugPrint('LoginPage build');

    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(errorMessage, style: const TextStyle(color: Colors.red)),
            TextField(
              controller: _userNameTextCtl,
              decoration: const InputDecoration(
                filled: true,
                labelText: 'Username',
              ),
              focusNode: _userNameFocusNode,
            ),
            const SizedBox(height: 10.0),
            TextField(
              controller: _pwdTextCtl,
              decoration: const InputDecoration(
                filled: true,
                labelText: 'Password',
              ),
              focusNode: _passwordNameFocusNode,
              obscureText: true,
            ),
            ButtonBar(
              children: <Widget>[
                ElevatedButton(
                    child: const Text('ログイン'),
                      onPressed: () {
                        viewModel.readData(
                          _userNameTextCtl.text, _pwdTextCtl.text).then(
                              (loginStatus) {
                                // debugPrint('LOGIN:' + loginStatus.accessToken);
                        Navigator.push(context,
                            MaterialPageRoute(builder: (context) =>
                                ScheduleList(loginStatus: loginStatus)));
                            }
                        ).onError((error, stackTrace) {
                        // _userNameTextController.clear();
                        _pwdTextCtl.clear();
                      });
                    }),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

final errorMessageProvider = StateProvider((ref) => '');

// StateNotifierProviderとLoginNotifierを使ったもの
class LoginStateNotifier extends StateNotifier<LoginState> {
  LoginStateNotifier(this.ref) : super(const LoginState());
  final Ref ref;
  //データ読み込み処理
  Future<LoginState> readData(name, password) async {
    LoginState loginState = await Repository().login(name, password)
        .onError((error, stackTrace) async {
        ref.watch(errorMessageProvider.notifier).state = "ログインに失敗しました";
      throw Exception(error.toString());
    });

    state = state.copyWith( //stateを更新します
      isSaseki: loginState.isSaseki,
      syokuinCode: loginState.syokuinCode,
      accessToken: loginState.accessToken,
      refreshToken: loginState.refreshToken,
    );
    return loginState;
  }
}

final loginStateNotifierProvider = StateNotifierProvider((ref) => LoginStateNotifier(ref));
/* -----codeの行番号----- */