美文网首页
flutter搜索框修改hint

flutter搜索框修改hint

作者: KeepAlone | 来源:发表于2019-08-14 11:56 被阅读0次
    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 => "搜索";
    }

    相关文章

      网友评论

          本文标题:flutter搜索框修改hint

          本文链接:https://www.haomeiwen.com/subject/crhgjctx.html