import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main(List<String> args) => runApp(App());
class App extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return AppState();
}
class AppState extends State<App> {
@override
Widget build(BuildContext context) {
return MaterialApp(
localizationsDelegates: [
CustomLocalizationDelegate(),
],
home: Scaffold(
body: 省略,
),
);
}
}
class CustomLocalizationDelegate extends LocalizationsDelegate<MaterialLocalizations> {
const CustomLocalizationDelegate();
@override
bool isSupported(Locale locale) => locale.languageCode == 'zh-cn';
@override
Future<MaterialLocalizations> load(Locale locale) => SynchronousFuture<MaterialLocalizations>(const CustomLocalization());
@override
bool shouldReload(CustomLocalizationDelegate old) => false;
@override
String toString() => 'CustomLocalization.delegate(zh-cn)';
}
class CustomLocalization extends DefaultMaterialLocalizations {
const CustomLocalization();
//在这里设置搜索框的hint
@override
String get searchFieldLabel => "搜索";
}
网友评论