Flutter 时间选择器不接受阿拉伯数字

问题描述 投票:0回答:1
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
TimeOfDay _tim =  const TimeOfDay(hour:5, minute: 0);
void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: const <LocalizationsDelegate<Object>>[
        // ... app-specific localization delegate(s) here
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      supportedLocales: <Locale>[
        Locale('ar', 'EG'), // English
        // Locale('he', 'IL'), // Hebrew
        // ... other locales the app supports
      ],
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {




  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(

        backgroundColor: Theme.of(context).colorScheme.inversePrimary,

        title: Text(widget.title),
      ),
      body: Center(

        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            GestureDetector(
              onTap: () async {
                final TimeOfDay?timeOfDay = await showTimePicker(

                  context: context,
                  //initialEntryMode: TimePickerEntryMode.inputOnly,

                  initialTime:_tim,

                  builder: (BuildContext context, Widget? child) => MediaQuery(
                    data: MediaQuery.of(context).copyWith(alwaysUse24HourFormat: false),
                    child: Localizations.override(
                      context: context,
                      locale: const Locale('ar', 'EG'),
                      child: child!,
                    ),
                  ),

                );
                if (timeOfDay!= null) {
                  setState(() {
                    _tim=timeOfDay;

                  });
                  // ignore: use_build_context_synchronously

                }
              } ,
              child: Container(
                decoration:  BoxDecoration(
                  border: Border.all(color: Colors.black12),
                  color: Colors.white70,
                ),
                width: MediaQuery.of(context).size.width,
                child: Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Column(
                    children: [
                      Text("Press to set the time",style: TextStyle(

                          color:const Color.fromARGB(255, 126, 122, 122),
                          fontWeight: FontWeight.bold,
                         

                      ),
                      ),
                      Center(
                          child: Text(
                            _tim.format(context).toString()
                            ,style: TextStyle(
                            color: Colors.black38,

                          )
                            ,)
                      ),
                    ],
                  ),
                ),
              ),
            ),

          ],
        ),
      ),

    );
  }
}

我在手动设置时间时遇到问题。它不接受阿拉伯语,但在没有手动输入的情况下设置它时,它接受。我不知道问题出在哪里。手动设置时如何使其接受阿拉伯数字?我希望我已经解释了这个问题。

问题图片:

The problem is that the keyboard only accepts English. I want it to accept Arabic.

不,我不知道如何更改键盘并使其接受阿拉伯数字,

看这里:

从这里选择时没有问题就接受了

enter image description here

flutter flutter-animation timepicker
1个回答
0
投票

您可以尝试键盘类型:TextInputType.phone 或键盘类型:TextInputType.number。

据我所知,iOS 没有提供任何方法来控制数字键盘中的西方和东方阿拉伯数字? https://developer.apple.com/documentation/uikit/uikeyboardtype

© www.soinside.com 2019 - 2024. All rights reserved.