简体   繁体   中英

Flutter Text Is Not Centered

I have a code like this:

return Scaffold(
  backgroundColor: const Color.fromARGB(255, 25, 25, 25),
  body: Padding(
    padding: EdgeInsets.all(5),
    child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        const Text("Güvenli ve Gizli", style: TextStyle(fontSize: 32, color: Colors.white, fontWeight: FontWeight.bold)),
        SizedBox(height: MediaQuery.of(context).size.height * 0.02),
        AnimatedBuilder(
          animation: ezAnimation,
          builder: (context, snapshot) {
            return Center(
              child: Image.asset("assets/SecureAndHiddenIcon.png", fit: BoxFit.cover, color: Colors.white, height: 200)
            );
          }
        ),
        SizedBox(height: MediaQuery.of(context).size.height * 0.02),
        Center(child: Text("Kullanıcıya değer vermek, güvenlik ve gizliliği sağlamaktan başlar. Malum tarayıcılar gibi bilgilerinizi satmayız!", style: TextStyle(fontSize: 18, color: Colors.white))), // !!!!!!!!!!!!! <<<<<<<<<<<<<<<
      ],
    ),
  ),
);

"Kullanıcıya değer vermek, güvenlik ve gizliliği sağlamaktan başlar. Malum tarayıcılar gibi bilgilerinizi satmayız!" written Text is not centered even though it is inside the Center widget. Why does this problem occur? How to I solve it?

Hey did you try textAlign property of Text widget like this - textAlign: TextAlign.center

return Scaffold(
  backgroundColor: const Color.fromARGB(255, 25, 25, 25),
  body: Padding(
    padding: EdgeInsets.all(5),
    child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        const Text("Güvenli ve Gizli", style: TextStyle(fontSize: 32, color: Colors.white, fontWeight: FontWeight.bold)),
        SizedBox(height: MediaQuery.of(context).size.height * 0.02),
        AnimatedBuilder(
          animation: ezAnimation,
          builder: (context, snapshot) {
            return Center(
              child: Image.asset("assets/SecureAndHiddenIcon.png", fit: BoxFit.cover, color: Colors.white, height: 200)
            );
          }
        ),
        SizedBox(height: MediaQuery.of(context).size.height * 0.02),
        Center(child: Text("Kullanıcıya değer vermek, güvenlik ve gizliliği sağlamaktan başlar. Malum tarayıcılar gibi bilgilerinizi satmayız!",textAlign: TextAlign.center, style: TextStyle(fontSize: 18, color: Colors.white))), // !!!!!!!!!!!!! <<<<<<<<<<<<<<<
      ],
    ),
  ),
);

请尝试使用对齐小部件

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM