我只是从Flutter和Provider开始,我试图根据用户登录状态来渲染两个不同的小部件。
我正在将YouBeautyApp()作为ChangeNotifierProvider的子级运行,但仍然出现以下错误:
错误:在此YouBeautyApp小部件上方找不到正确的提供程序
我哪里出错了?
很多坦克!
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'auth.dart';
import 'home_page.dart';
import 'login_page.dart';
void main() => runApp(
ChangeNotifierProvider<AuthService>(
create: (_) => new AuthService(),
child: YouBeautyApp(),
),
);
class YouBeautyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'You Beauty App',
theme: ThemeData(primarySwatch: Colors.red),
home: FutureBuilder(
future: Provider.of<AuthService>(context).getUser(),
builder: (context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return snapshot.hasData ? HomePage() : LoginPage();
} else {
return Container(color: Colors.white);
}
},
),
);
}
}