示例状态:
abstract class ExampleState extends Equatable {
const ExampleState();
}
class LoadingState extends ExampleState {
//
}
class LoadedState extends ExampleState {
//
}
class FailedState extends ExampleState {
//
}
Run Code Online (Sandbox Code Playgroud)
示例_事件:
abstract class ExampleEvent extends Equatable {
//
}
class SubscribeEvent extends ExampleEvent {
//
}
class UnsubscribeEvent extends ExampleEvent {
//
}
class FetchEvent extends ExampleEvent {
//
}
Run Code Online (Sandbox Code Playgroud)
示例_块:
class ExampleBloc extends Bloc<ExampleEvent, ExampleState> {
@override
ExampleState get initialState => LoadingState();
@override
Stream<ExampleState> mapEventToState(
ExampleEvent event,
) …Run Code Online (Sandbox Code Playgroud) 我有一个页面,用户在初始登录后输入他的用户名和生日,然后我想返回并在上一个屏幕中使用这些数据。
在屏幕 2 中:
Navigator.pop(context, {'username':username, 'birthday':birthday});
Run Code Online (Sandbox Code Playgroud)
在屏幕 1 中:
final userData = await Navigator.pushNamed(context, '/setup_profile');
Run Code Online (Sandbox Code Playgroud)
Final/var 适用于单个变量(例如 String),但不适用于映射,因为它不知道返回对象实际上是映射。
当然,如果不指定它是一个 Map 就不能使用userData['username'],我不明白如何指定它。
我试过了
Map<String, dynamic> userData = await Navigator.pushNamed(context, '/register');
Run Code Online (Sandbox Code Playgroud)
它不起作用我收到此错误:
Unhandled Exception: type 'MaterialPageRoute<dynamic>' is not a subtype of type 'Route<Map<String, dynamic>>'
Run Code Online (Sandbox Code Playgroud)
然后我尝试了
Route route = await Navigator.pushNamed(context, '/register');
Map<String, dynamic> data = route.currentResult;
Run Code Online (Sandbox Code Playgroud)
这不太有效,我遇到了同样的错误
Unhandled Exception: type 'MaterialPageRoute<dynamic>' is not a subtype of type 'Route<Route<dynamic>>'
Run Code Online (Sandbox Code Playgroud)
简而言之,我想在 Screen1 中使用返回的 Map。
主要问题是我不知道如何指定返回数据,它是自定义类、地图、列表还是其他内容。如何指定 Navigator.pop 的返回类型?
我正在尝试实现所示图像中的形状。我不知道如何做到这一点。我尝试的最后一件事是:
Container(
height: 175,
decoration: BoxDecoration(
borderRadius: BorderRadius.vertical(
bottom: Radius.elliptical(175, 45),
),
),
)
Run Code Online (Sandbox Code Playgroud)
我怎样才能创建这个形状?