مجهول
مجهول

Reputation: 47

Flutter time picker does not accept Arabic numbers

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,

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

          ],
        ),
      ),

    );
  }
}

I have a problem with setting the time manually. It does not accept the Arabic language, but when setting it without manual entry, it accepts. I do not know where the problem is. How can I make it accept Arabic numbers when setting it manually? I hope I have explained the problem.

Pictures of the problem:

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

NoI don't know how to change the keyboard and make it accept Arabic numbers,

look here:

Accepted without problems when selecting from here

enter image description here

Upvotes: 2

Views: 65

Answers (1)

Eric Seidel
Eric Seidel

Reputation: 1

You might try
keyboardType: TextInputType.phone or keyboardType: TextInputType.number

As far as I can tell, iOS doesn't give any way to control western vs. eastern Arabic numerals in a number keyboard?
https://developer.apple.com/documentation/uikit/uikeyboardtype

Upvotes: 0

Related Questions